[Eager-future-devel] Interaction between pexec macro and loop macro?
Mark Brown
markb at parkcity.ne.jp
Sun Feb 24 13:03:52 UTC 2013
I'm having difficulty in understanding behaviour when futures are
created in loops defined by the loop macro. Here's a very simple example:
First, load eager-future2 using quicklisp.
CL-USER> (ql:quickload :eager-future2)
To load "eager-future2":
Load 1 ASDF system:
eager-future2
; Loading "eager-future2"
(:EAGER-FUTURE2)
Now create a bunch of futures in a loop with pexec, using a loop
variable in the future, then yield them. For the following code, I
expect a list of values from 0 to 9 but I get something strange:
CL-USER> (loop for k in (loop repeat 10 for i = 0 then (+ 1 i) collect
(eager-future2:pexec (list i))) collect (eager-future2:yield k))
((7) (7) (8) (9) (9) (9) (9) (9) (9) (9))
Instead of using pexec, let's use a separate function to create our thunk.
CL-USER> (defun make-thunk (i) (lambda () (list i)))
MAKE-THUNK
Now instead of using pexec we use pcall with our thunk-maker. And the
result is as expected.
CL-USER> (loop for k in (loop repeat 10 for i = 0 then (+ 1 i) collect
(eager-future2:pcall (make-thunk i))) collect (eager-future2:yield k))
((0) (1) (2) (3) (4) (5) (6) (7) (8) (9))
Note that using (pcall (lambda () (list i))) also does NOT work.
Am I misunderstanding something?
More information about the eager-future-devel
mailing list