From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.devel Subject: Re: make-thread with lambda form instead of function symbol Date: Sun, 16 Apr 2017 11:11:29 -0700 Message-ID: <874lxo6x4e.fsf@ericabrahamsen.net> References: <87efws9w3c.fsf@ericabrahamsen.net> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1492366360 10282 195.159.176.226 (16 Apr 2017 18:12:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 16 Apr 2017 18:12:40 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 16 20:12:35 2017 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1czof4-0002WL-9X for ged-emacs-devel@m.gmane.org; Sun, 16 Apr 2017 20:12:34 +0200 Original-Received: from localhost ([::1]:33218 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1czof9-0007WO-RD for ged-emacs-devel@m.gmane.org; Sun, 16 Apr 2017 14:12:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49160) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1czoeZ-0007WI-6l for emacs-devel@gnu.org; Sun, 16 Apr 2017 14:12:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1czoeV-0002ue-4N for emacs-devel@gnu.org; Sun, 16 Apr 2017 14:12:03 -0400 Original-Received: from [195.159.176.226] (port=32993 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1czoeU-0002t6-Ti for emacs-devel@gnu.org; Sun, 16 Apr 2017 14:11:59 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1czoeL-0001WW-4S for emacs-devel@gnu.org; Sun, 16 Apr 2017 20:11:49 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 63 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:JX+jLaYbTczV7WdovhFJnq9WHBQ= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214018 Archived-At: Noam Postavsky writes: > On Sun, Apr 16, 2017 at 12:05 PM, Eric Abrahamsen > 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). Thanks for the response. The first thing I learned here was that lexical-binding was nil in *scratch*, but t in the source file I'm writing -- not a great testing setup. I'm still not seeing the results I expect, though. Here's a dumb test: (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? Thanks again, Eric