unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
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 12:21:38 -0400	[thread overview]
Message-ID: <CAM-tV-8Yf9zvpNaERm3X_-7hvb0fQ8Qy+=BNYF8C2p5b0pgpng@mail.gmail.com> (raw)
In-Reply-To: <87efws9w3c.fsf@ericabrahamsen.net>

On Sun, Apr 16, 2017 at 12:05 PM, Eric Abrahamsen
<eric@ericabrahamsen.net> wrote:
> I'm trying to do something that seems like it would be a normal use
> case: spawn a series of threads which call the same function using
> different external processes. Practically what this means is that I want
> to pass a function-plus-argument form to make-thread, not a function
> symbol. Something like:
>
> (let* ((results)
>        (sources '(source1 source2))
>        (threads
>         (mapcar
>          (lambda (s)
>            (make-thread
>             (funcall
>              (lambda ()
>                (push (get-stuff-from-source s) results)))))
>          sources)))
>   (mapc #'thread-join threads)
>   results)
>
> The (funcall (lambda () thing was the only way I could get anything but
> nil out of the thread functions. I think I'm fooling myself, though: so
> far as I can tell, `get-stuff-from-source' is fully evaluated before the
> thread is made, and nothing at all happens during the #'thread-join
> loop.

Just drop the funcall: (make-thread (lambda () ...)) should do what
you want, assuming you have lexical-binding set (if not, you can
construct a lambda-list with backquote or similar).



  reply	other threads:[~2017-04-16 16:21 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 [this message]
2017-04-16 18:11   ` Eric Abrahamsen
2017-04-16 18:44     ` Noam Postavsky
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-8Yf9zvpNaERm3X_-7hvb0fQ8Qy+=BNYF8C2p5b0pgpng@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).