Processing after a function returns
Processing after a function returns
Hello,
Is there a way in Common Lisp to continue processing data, after the REPL has returned a value - without starting a subprocess.
(defun foo (x y)
(prog1 (+ x y)
(do more processing after (+ x y) has been returned...))
Thank you.
Is there a way in Common Lisp to continue processing data, after the REPL has returned a value - without starting a subprocess.
(defun foo (x y)
(prog1 (+ x y)
(do more processing after (+ x y) has been returned...))
Thank you.
Re: Processing after a function returns
You can create a thread on implementations supporting threads. For example, SBCL manual on threading. I suppose it would be possible to somehow use multiplexing to interleave some computation directly with the REPL, if you implemented your own REPL (I think Slime has multiplexing mode on some implementations), but what would be the point?
Re: Processing after a function returns
Could your program simply print a value to the REPL and continue processing? The return value can't be used until the current function completes...
Re: Processing after a function returns
That might work. May I ask how you would "print a value to the REPL" ?
-
- Posts: 406
- Joined: Sat Mar 07, 2009 6:17 pm
- Location: Brazil
- Contact:
Re: Processing after a function returns
If you evaluate some form in the REPL like (+ 1 2), the result is already printed to the REPL and stored in the variable *:bl108 wrote:That might work. May I ask how you would "print a value to the REPL" ?
Code: Select all
cl-user> (+ 1 2)
3
cl-user> *
3
cl-user> (+ * 5)
8
Re: Processing after a function returns
How would you do that the processing occured after foo has returned it's value ? If the print statement were in the function, then that would run before foo ended.
(defun foo (x y)
(prog1 (+ x y)
(do more processing after (+ x y) has been returned...))
(defun foo (x y)
(prog1 (+ x y)
(do more processing after (+ x y) has been returned...))
Re: Processing after a function returns
Code: Select all
(defun double-square (x)
(print (+ x x))
(* x x))
Until a function returns, nobody else can access its return value. The only ways to pass values without returning are to call another function, to write to memory for another thread, or use IPC to communicate with another process.