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: Fri, 10 May 2019 17:18:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> > Now that I look at it again, I guess an "anamorphic" version would be
> > probably more obvious:
> >
> >     (gv-modify (nth i l)
> >        (append head it (cdr x)))

I guess I would rather like it with explicit naming:

(defmacro gv-modify (binding call)
  (declare (indent 1))
  (pcase-let ((`(,var ,place) binding))
    (gv-letplace (getter setter) place
      (funcall setter `(let ((,var ,getter)) ,call)))))

Example:

(let ((l '(x ((2 3)))))
  (gv-modify (plc (car (cadr l)))
    (append '(0 1) plc '(4 5)))
  l)

=> (x ((0 1 2 3 4 5)))

> And I see it solves another downside of (gv-callf N EXP), which is that in
>
>     (gv-callf 2 (append HEAD (nth INDEX LIST) TAIL))
>
> the evaluation order will actually end up being
>
>     INDEX; LIST; HEAD; TAIL
>
> which is counter-intuitive.

The disadvantage is that the `append' call looks a bit pulled apart, but
I think it would be ok for me.


Michael.



reply via email to

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