[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [RFC] Adding threads to Eshell

From: Stefan Monnier
Subject: Re: [RFC] Adding threads to Eshell
Date: Fri, 16 Dec 2022 09:05:11 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> lisp/eshell/esh-cmd.el).  This requires a lot of code to handle various Lisp
> special forms, and the allowed forms are fairly limited.  It also has a few
> bugs, likely due in part to being written before lexical binding.

I remember discussing this with John the one time we got to meet face to
face and him telling me that he didn't know the concept of
CPS-conversion back then :-)

> 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.

> 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).

> Is it possible to tell a thread that I want to inherit the bindings
> from wherever I called 'make-thread'?

For statically scoped vars, this should already be the case because the
(lambda ....) you pass to `make-thread` will close over the surrounding
static scopes.

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

I've had some fun writing an `lml.el` compatibility package which
includes support for that.  The corresponding part of the code is:

    (oclosure-define (lml-closure
                      (:predicate lml-closurep))
      bindings function)

    (defun lml--closure (bindings function)
      (oclosure-lambda (lml-closure (bindings bindings)
                                    (function function))
          (&rest args)
        (cl-progv (mapcar #'car bindings) (mapcar #'cdr bindings)
          (apply function args))))

    (defun lml-closure (varlist function)
      "Create a closure over the dynamic variables in VARLIST."
      (lml--closure (mapcar (lambda (v) (cons v (symbol-value v))) varlist)

-- Stefan

reply via email to

[Prev in Thread] Current Thread [Next in Thread]