emacs-devel
[Top][All Lists]
Advanced

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

Re: gv-exander for 'list'


From: Michael Heerdegen
Subject: Re: gv-exander for 'list'
Date: Tue, 19 Mar 2019 23:34:21 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

> > +(put 'list 'gv-expander
> > +     (lambda (do &rest elt-places)
> > +       ;; FIXME: when using this with letf people would expect this to
> > +       ;; create local bindings
>
> Not sure what you mean by this FIXME.

I mean that something like

(cl-letf (((list a) (list 1)))
  a)

errors unless variable a is already bound.

> > +       (let ((getters+setters
> > +              (mapcar (lambda (place)
> > +                        (gv-get place (lambda (g s) (cons g s))))
> > +                      elt-places)))
> > +         (funcall do `(list ,@(mapcar #'car getters+setters))
> > +                  (lambda (v)
> > +                    (macroexp-let2 macroexp-copyable-p v v
> > +                      (macroexp-progn
> > + (mapcar (lambda (x) (funcall (cdr x) `(pop ,v)))
> > +                               getters+setters))))))))
>
> This expands to incorrect code: (macroexpand '(setf (list a b) x))
> You should probably replace `macroexp-copyable-p` with `ignore`.

Indeed, thanks.

> > It could be an alternative to `progv', where the variable list isn't
> > computed dynamically (the values list still is), but OTOH allows
> > generalized variables.  Would that make sense?
>
> I don't see why it wouldn't do what you say, but I'm not sure how often
> that would be usable (and preferable to an alternative).
>
> Also, as a replacement for cl-progv it will suffer from the fact that
> instead of using the built-in C code for dynamic scoping, it will mimic
> it via unwind-protect, which means that it will misbehave in the
> presence of buffer-local values:
>
>     (let ((buf (current-buffer)))
>       (with-temp-buffer
>         (setq default-directory "/bar/")
>         (cl-letf (((list default-directory) '("/foo/")))
>           (set-buffer buf))))
>
> There are a few other similar cases that we slowly
> patched over the years ;-)
>
> [ Note that it's one of the reasons (beside efficiency) why `cl-letf` is
>   careful to treat simple variables specially, thus taking advantage of
>   the built-in handling of dynamically-scoped vars.  ]

I think I just would want simple variables in `list' treated the same
way.


Michael.



reply via email to

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