emacs-devel
[Top][All Lists]
Advanced

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

Re: `setplist' on local var escaping let binding


From: Davis Herring
Subject: Re: `setplist' on local var escaping let binding
Date: Thu, 21 Oct 2010 05:46:06 -0700 (PDT)
User-agent: SquirrelMail/1.4.8-5.el5_4.10.lanl3

> (progn
>   (unintern "ms" obarray)
>   (let (ms)
>     (setplist 'ms '(can-has a-plist))
>     `(,(get 'ms 'can-has)
>       ,(intern-soft "ms" obarray))))
> (a-plist nil)

Symbols are created (or retrieved) when a form is read, so the rest of
this form is still using the old ms.  Your life will be much simpler if
you forget that `unintern' exists at all.  If you want to have a dynamic
mapping where it's important to remove elements, just use a hash table.

> (let ((ms (make-symbol "bubba")))
>   (apply #'setplist
>          (list (eval (list 'quote (identity ms)))
>                '(not a symbol really?)))
>   `(:non-thing-bubba ,(not (intern-soft "bubba" obarray))
>     :but-with-a-plist ,(apply #'get
>                               (list (eval (list 'quote (identity ms)))
>                                     'symbol))
>     :is-thing-like-ms ,(eq (intern-soft "ms" obarray)
>                            (intern-soft "ms" obarray))))

You continue to use `identity' for no reason, and seem to have discovered
an even more verbose synonym for nothing: (eval (list 'quote foo)) is
exactly equivalent to foo.  (apply #'foo (list bar baz)) is also just the
same as (foo bar baz), and `obarray' is the default argument to the
interning functions.  All :symbols evaluate to themselves, so you can
finally write (with about half the characters)

(let ((ms (make-symbol "bubba")))
  (setplist ms '(not a symbol really?))
  (list :non-thing-bubba (not (intern-soft "bubba"))
        :but-with-a-plist (get ms 'symbol)
        :is-thing-like-ms (eq (intern-soft "ms") (intern-soft "ms"))))

at which point the only remaining quarrels are your use of "thing" and
"non-thing" (but surely that's just the result of the confusion, not the
cause) and your apparent suspicion that `intern-soft''s value will change
between two adjacent calls.

It's really not that confusing if you don't make it so!

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.



reply via email to

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