From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: emacs-devel@gnu.org
Subject: make-thread with lambda form instead of function symbol
Date: Sun, 16 Apr 2017 09:05:27 -0700 [thread overview]
Message-ID: <87efws9w3c.fsf@ericabrahamsen.net> (raw)
Okay, one more thread question...
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.
Is it possible to give make-thread anything but a function symbol? The
only other thing I could think of was looping over the sources and
making ad-hoc symbols:
(fset (make-symbol (format "%s-dummy-function" (source-name source)))
(lambda () (push (get-stuff-from-source source) results)))
That seems ugly, but perhaps not that bad.
Thanks in advance,
Eric
next reply other threads:[~2017-04-16 16:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-16 16:05 Eric Abrahamsen [this message]
2017-04-16 16:21 ` make-thread with lambda form instead of function symbol Noam Postavsky
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=87efws9w3c.fsf@ericabrahamsen.net \
--to=eric@ericabrahamsen.net \
--cc=emacs-devel@gnu.org \
/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).