opensubscriber
   Find in this group all groups
 
Unknown more information…

e : emacs-devel@gnu.org 9 June 2012 • 7:32PM -0400

Re: Replacement for `aput' from obsolete assoc.el?
by Vitalie Spinu

REPLY TO AUTHOR
 
REPLY TO GROUP




  >> "Stephen J. Turnbull" <stephen@xema...>
  >> on Sat, 09 Jun 2012 17:59:05 +0900 wrote:

  > Analogous to `put' and `get' for symbols, disembodied plists are
  > managed with `plist-put' and `plist-get'.  

There is no way to associate multiple values at once. What is the
canonical way to do that?

Assume FOO and BAR are plists. You want values of FOO set into BAR. The
best I can think of is:

  
   (setq
    FOO '(:a 1 :b 2)
    BAR '(:b 3 :c 4))
  
   (loop for X on FOO  by 'cddr
         do (setq BAR (plist-put BAR (car X) (cadr X))))
  
   BAR
   (:b 2 :c 4 :a 1)


And for a setq like macro:
  
  
   (defmacro plist-put* (plist &rest body)
     "Like `plist-put' but allows multiple pairs.
  
   \(fn PLIST [PROP VALUE] ...)"
     (declare (indent defun))
     `(let ((PL ,plist)
   (VALS ',body))
        (loop for X on VALS by 'cddr
      do (setq PL (plist-put PL (car X) (eval (cadr X)))))
        PL))
  
   (plist-put* FOO
     :d 5
     :e (+ 100 50))
  
   ==>
    (:a 1 :b 2 :d 5 :e 150)


I find reasonable that this sort of functionality be in the core for all
available containers. FWIW, for text properties there are `propertize'
and `set-text-properties' which don't have an uniform interface.

Vitalie.


Bookmark with:

Delicious   Digg   reddit   Facebook   StumbleUpon

Related Messages

opensubscriber is not affiliated with the authors of this message nor responsible for its content.