emacs-devel
[Top][All Lists]
Advanced

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

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


From: Vitalie Spinu
Subject: Re: Replacement for `aput' from obsolete assoc.el?
Date: Sat, 09 Jun 2012 13:32:49 +0200
User-agent: Gnus/5.130004 (Ma Gnus v0.4) Emacs/23.3 (gnu/linux)

  >> "Stephen J. Turnbull" <address@hidden>
  >> 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.



reply via email to

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