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: Michael Heerdegen
Subject: Re: Why is FUNC in cl-callf not allowed to be an expression?
Date: Wed, 15 May 2019 01:32:53 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> > (defmacro gv-modify (binding call)

Here is another idea:

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

Example:

(let ((x '((a))))
  (gv-with-place (car x)
    (lambda (v set)
      (funcall set (append '(1 2) v '(3 4)))))
  x)

=> ((1 2 a 3 4))

The usage looks a bit longer than in all other proposals, but I find it
cleaner.  It's also more general, you can e.g. make setting conditional
as in your (commented) `gv-pushnew!'.  The second arg of `gv-with-place'
being a function also gives a chance for factoring.  More function calls
at run time involved, though.

I see that the suggestion comes near to just use `gv-letplace' in the
first place, but I think it's easier to understand for the end
programmer.


Michael.



reply via email to

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