[Eager-future-devel] Interaction between pexec macro and loop macro?

Mark Brown markb at parkcity.ne.jp
Mon Feb 25 10:31:03 UTC 2013


Okay, I think I sorted this out myself.

The problem appears to be with trying to create a closure over a loop 
variable. I think the closure is using the binding rather than the 
value; so pexec is starting threads with the value that the loop 
variable is bound to at the time of the thread being kicked off. A 
Common Lisp gotcha!


On 2013/02/24 22:03, Mark Brown wrote:
>
> 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?
>
>
>
> _______________________________________________
> Eager-future-devel mailing list
> Eager-future-devel at common-lisp.net
> http://lists.common-lisp.net/cgi-bin/mailman/listinfo/eager-future-devel
>

-- 
--
Mark Brown
Email: markb at parkcity.ne.jp
Tel/fax: 0422-42-3151




More information about the eager-future-devel mailing list