emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: make-thread with lambda form instead of function symbol


From: Noam Postavsky
Subject: Re: make-thread with lambda form instead of function symbol
Date: Sun, 16 Apr 2017 14:44:25 -0400

On Sun, Apr 16, 2017 at 2:11 PM, Eric Abrahamsen
<address@hidden> wrote:
>
> (setq lexical-binding t)
>
> (let ((threads
>        (mapcar
>         (lambda (el)
>           (make-thread
>            (lambda ()
>              (push (cl-incf el) results))))
>         '(1 2 3)))
>       results)
>   (mapc #'thread-join threads)
>   results)
>
> This gives me nil.
>
> (Incidentally, if I put this in a function and edebug it, it tells me
> edebug will stop at the next break point, and then enters a level of
> recursive editing I can't escape from: C-M-c gives me "No catch for tag:
> exit, nil".)
>
> Should the above example work?

No, check the compile warnings:

a.el:7:33:Warning: reference to free variable ‘results’
a.el:9:7:Warning: assignment to free variable ‘results’

Not sure about the edebug thing, probably it doesn't handle
cross-thread stepping.

The below returns (2 3 4) or sometimes (3 4 2).

(let* ((results nil)
       (threads
        (mapcar
         (lambda (el)
           (make-thread
            (lambda ()
              (push (cl-incf el) results))))
         '(1 2 3))))
  (mapc #'thread-join threads)
  results)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]