From: Noam Postavsky <npostavs@users.sourceforge.net>
To: Eric Abrahamsen <eric@ericabrahamsen.net>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: make-thread with lambda form instead of function symbol
Date: Sun, 16 Apr 2017 14:44:25 -0400 [thread overview]
Message-ID: <CAM-tV-9C+Kkn-PkgP7ZcSccuY-vWswYnf4KbtdD3bmCDgW9HyA@mail.gmail.com> (raw)
In-Reply-To: <874lxo6x4e.fsf@ericabrahamsen.net>
On Sun, Apr 16, 2017 at 2:11 PM, Eric Abrahamsen
<eric@ericabrahamsen.net> 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)
next prev parent reply other threads:[~2017-04-16 18:44 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-16 16:05 make-thread with lambda form instead of function symbol Eric Abrahamsen
2017-04-16 16:21 ` Noam Postavsky
2017-04-16 18:11 ` Eric Abrahamsen
2017-04-16 18:44 ` Noam Postavsky [this message]
2017-04-16 20:02 ` Eric Abrahamsen
2017-04-17 1:12 ` Eric Abrahamsen
2017-04-17 1:46 ` Noam Postavsky
2017-04-17 3:45 ` Eric Abrahamsen
2017-04-17 7:02 ` Eli Zaretskii
2017-04-17 16:54 ` Eric Abrahamsen
2017-04-17 17:18 ` Eric Abrahamsen
2017-04-17 6:51 ` Eli Zaretskii
2017-04-17 6:59 ` Andrew Cohen
2017-04-17 17:32 ` Eric Abrahamsen
2017-04-18 1:00 ` Andrew Cohen
2017-04-18 1:38 ` Eric Abrahamsen
2017-04-20 1:22 ` Eric Abrahamsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAM-tV-9C+Kkn-PkgP7ZcSccuY-vWswYnf4KbtdD3bmCDgW9HyA@mail.gmail.com \
--to=npostavs@users.sourceforge.net \
--cc=emacs-devel@gnu.org \
--cc=eric@ericabrahamsen.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).