Getting errors and results back from spawned process

Q&A's, tips, howto's
Locked
cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Getting errors and results back from spawned process

Post by cormullion »

Playing with this area of newLISP. It seems to be not possible to communicate errors using catch.

Code: Select all

> (catch (eval-string {(+ 2 2)}) 'result)
true
> 
> result
4
> (catch (eval-string {(+ 2 2}) 'result)
nil
> result
"ERR: missing parenthesis in function eval-string : \"...(+ 2 2                              \""
>
> ; so the basic idea works. Try it with spawn...
>
> (spawn 'p1 (catch (eval-string {(+ 2 2)}) 'result))
15789
> (sync 10)
true
> p1
true
> result
"ERR: missing parenthesis in function eval-string : \"...(+ 2 2                              \""
> 
Is there a way to get results and errors from a spawned process using catch? Or is it a job for send/receive?

(newLISP v.10.2.8 on OSX IPv4 UTF-8)

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: Getting errors and results back from spawned process

Post by Lutz »

the 'result' you ask for is not the 'result' from the spawned process but from the main process, where it had been set before.

Return 'result' from the spawned process to make it visible in 'p1':

Code: Select all

> (spawn 'p1 (begin (catch (eval-string {(+ 2 3}) 'result) result))
39123
> (sync 1000)
true
> p1
"ERR: missing parenthesis in function eval-string : \"...(+ 2 3
The only thing you get back from the spawned process is in 'p1'.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Getting errors and results back from spawned process

Post by cormullion »

Ah, yes! That works great.

As ever - thanks Lutz!

Locked