From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.devel Subject: Re: [RFC] Adding threads to Eshell Date: Fri, 16 Dec 2022 12:11:05 -0800 Message-ID: References: <7f4e3357-2c6a-a0d2-cab5-fb641b52877a@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28135"; mail-complaints-to="usenet@ciao.gmane.io" Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Fri Dec 16 21:11:41 2022 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p6H3T-00076j-WA for ged-emacs-devel@m.gmane-mx.org; Fri, 16 Dec 2022 21:11:40 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p6H35-0008Si-EY; Fri, 16 Dec 2022 15:11:15 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p6H33-0008ST-Fo for emacs-devel@gnu.org; Fri, 16 Dec 2022 15:11:13 -0500 Original-Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p6H31-0003hd-Ab for emacs-devel@gnu.org; Fri, 16 Dec 2022 15:11:12 -0500 Original-Received: by mail-pj1-x102c.google.com with SMTP id fa4-20020a17090af0c400b002198d1328a0so9415222pjb.0 for ; Fri, 16 Dec 2022 12:11:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=NAgYuGdx7eMu3hgTWCipO59Xq0HIRg4EsNQtpvYMtb8=; b=ggsMXne8Kl/IYhTIYsYVx94Fl6lN3TwsY3vyrogeed5xIdB3su1MjEa25NCygvb9VC 48SaTKt0xsppctV3e6vjx4QYzPrl9CufWOvubEiLsIKFmNMzawBe/oNcDEvJEyOb/CZr 73u+Z6W6A/j96nNygR8pBOmEvC8EVd0Khglg7Di9QJfeRjTvtOP35JzLc24wb9lrg4Lp SctwqFZIJcQdSyx5RxjOXrtqOT9Og6dHLS8ONzO7PKBhbYgtOomt2ekmGTgB6aniKnSv yV0RAxGsthCFNqRHnAzxFBRbYiuvHD04GYM5xTyr8GXlpKPFJzaeNgcnDyOfC5G71PZn 37Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NAgYuGdx7eMu3hgTWCipO59Xq0HIRg4EsNQtpvYMtb8=; b=8KWSFPQ7XLNpAAVmXW7TMQfpyzYXSYob7/UecGgFoy+pcNVYzDnZ2Bx2lqWwdP5DRK EsjpRO1PIRL1bAZwEvR+qRUfpgg86Wj2mh100nwbgcLgCF/gS65bWlvC81lPkfVfNjNn wIdpKs8eGBHfv+azwpmlt1OH6GlnvbudEb081J5gbs3oemSsx75Bqlpq41yN1fNq2LUT UI+KWPZWMh25VQuoERRyHRFtHhax8wGGqmyQ76pdFg7D9kHcy8vQ5lFCHLxcT8O+QtrN vwFaNCUHAwlFnC82TmX1iumwJjvZTJje0boHv41E6E5aZd1+KqswUoa5bkxrTizegyMI VQGw== X-Gm-Message-State: ANoB5pmRNEZBugIgXxuMmsXS/lYaOBhAex7Zo6tsXJZniRMEI0Tt/9kU eBsqHiEsGuCVkeaOVAjkDqAHdd0ftzs= X-Google-Smtp-Source: AA0mqf7XEpFOhGTz3RSoSo+k6cCUcjIlIaXaRPdDPJIx2lPFeFHXmdIEE8ccDKeTmJaJcog0iHW8jQ== X-Received: by 2002:a17:90b:4b05:b0:221:684a:d05d with SMTP id lx5-20020a17090b4b0500b00221684ad05dmr24714487pjb.45.1671221466813; Fri, 16 Dec 2022 12:11:06 -0800 (PST) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id f28-20020a63101c000000b00478f87eaa44sm1873030pgl.35.2022.12.16.12.11.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 16 Dec 2022 12:11:06 -0800 (PST) Content-Language: en-US In-Reply-To: Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=jporterbugs@gmail.com; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.devel:301524 Archived-At: On 12/16/2022 6:05 AM, Stefan Monnier wrote: >> However, before I go too far, I wanted to check with other, more >> knowledgeable people: are Emacs threads available on all platforms? > > I'll let others answer this part. IIUC the answer is not "yes", but > like you I hope the cases where they're not supported can be simply > swept under the rug. I'm not sure it's worth the added complexity (yet?), but maybe it would be useful to have some generic way of executing code asynchronously (probably using CPS-transformations). Then you could pass this code to a thread if those are available, or if not, just run in the main thread when Emacs is idle. >> A second issue I noticed is that Emacs threads have their own, >> completely separate set of lexical bindings. > > Do you really mean *lexical* bindings? > If yes, then I don't understand what you mean (I don't understand how > they could be non-completely separate). I suppose I mean *local* bindings, really. The manual says, "The new thread is created with no local variable bindings in effect." That's something that I think would be nice to change in this case, so that a user could do something like: (let ((some-defvar t)) (eshell-command "echo $some-defvar")) Internally, 'eshell-command' would convert "echo $some-defvar" to some Lisp form, then call 'make-thread' and eval that form in the thread. > For dynamically scoped vars, you'd have to do it more explicitly. > Lisp Machine Lisp had an operation they called `closure` for that > purpose (they didn't have static scoping at all). > See https://hanshuebner.github.io/lmman/fd-clo.xml That sounds like what I want. Thanks for the code snippet. The only bit I'm still unsure about is if there's a good (and performant) way to ask, "What are all the local bindings of dynamic variables?" Then, I could use that to feed those bindings to the thread and this would work. (I'm still not sure whether this is the right thing to do in the first place, but I want to see what it's like. It would also make more of the regression tests pass, which would make it easier to keep developing this.)