emacs-devel
[Top][All Lists]
Advanced

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

Re: Why is FUNC in cl-callf not allowed to be an expression?


From: Stefan Monnier
Subject: Re: Why is FUNC in cl-callf not allowed to be an expression?
Date: Tue, 14 May 2019 22:02:06 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> (defmacro gv-with-place (place f)
>   (declare (indent 1))
>   (gv-letplace (getter setter) place
>     (let ((v (make-symbol "v")))
>       `(funcall ,f ,getter (lambda (,v) ,(funcall setter v))))))

We could at least avoid the overall `funcall`:

    (defmacro gv-with-place (val setfun place &rest body)
      (declare (indent 3))
      (gv-letplace (getter setter) place
        `(let ((,val ,getter)
               (,setfun (lambda (v) ,(funcall setter 'v))))
           ,@body)))

Along the same lines maybe we could provide a (gv-ref VAL SETFUN) 
pcase-macro, so you could do

    (pcase-let (((gv-ref val setter) (gv-ref PLACE)))
      (unless (member X val) (funcall setter (cons X val))))

Even better would be if we could do

    (pcase-let (((gv-ref p) (gv-ref PLACE)))
      (unless (member X p) (setf p (cons X p))))

but it seems this would require non-trivial changes to pcase (since
basically `p` should not be bound there with a `let` but with
a `cl-symbol-macrolet`).

Still, I think the `gv-modify` discussed earlier hits a sweeter spot.


        Stefan



reply via email to

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