Re: Parsec parser library...

"Tim Bradshaw (as tfb at tfeb dot org)" <[email protected]> Mon, 27 Jul 2026 15:24:41 +0100
Newsgroups gmane.lisp.lispworks.general
Message-ID <[email protected]>
On 27 Jul 2026, at 06:45, David McClain (as dbm at refined-audiometrics dot com) <[email protected]> wrote:
> 
> So we need some kind of thread-local version of Let-Over-Lambda.

For things like this I tend to use some variant of

(defun make-tval (&optional (default nil))
  (let ((table (make-hash-table :weak-kind :key)))
    (lambda (thread &optional (nv nil nvp))
      (if nvp
          (setf (gethash thread table) nv)
        (gethash thread table default)))))

(declaim (inline tval-value (setf tval-value)))

(defun tval-value (tval &optional (thread *current-process*))
  (funcall tval thread))

(defun (setf tval-value) (new tval &optional (thread *current-process*))
  (funcall tval thread new))

Assuming hash-table access is thread-safe this is OK I think.  And then you do something like.

(let ((something (make-tval <default>)))
  (lambda (...)
    ... (tval-value something) ... (setf (tval-value something) ...) ...))

I like it that the solution is itself let over lambda.


_______________________________________________
Lisp Hug - the mailing list for LispWorks users
[email protected]
http://www.lispworks.com/support/lisp-hug.html