[Top][All Lists]

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

Re: design ponderings: plist to alist

From: Stefan Monnier
Subject: Re: design ponderings: plist to alist
Date: Wed, 16 Apr 2014 13:29:56 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4.50 (gnu/linux)

> includes a function to convert plist (succinct to humans) to alist
> (succinct to computers).  I spent 20 minutes poking around the Emacs
> source searching for something builtin, to no avail.  I saw a few cases
> of the opposite direction (alist to plist) and many cases where plists
> are walked at time of use (e.g., the C code for text-properties), so
> maybe this is a hint that plist to alist (pre-use) is a net lose.  :-/

> What do people think?

I dislike plists, so the only thing that would make some sense would be
some kind of macro.

(defmacro plist (&rest args)
  (let ((l '()))
    (while args
      (push '(cons ,(pop l) ,(pop l)) args))
    `(list ,@(nreverse l))))

Then you'd write

 (let ((root (gnugo--root-node)))
   (cl-flet ((r! (alist) (gnugo--decorate root alist)))
     (r! (plist :SZ board-size
                :DT (format-time-string "%Y-%m-%d")
                :RU (if (string-match "--chinese-rules" args)
                :AP (cons "gnugo.el" gnugo-version)
                :KM komi))
     (let ((gb (gnugo--blackp (gnugo-other user-color))))
       (r! (plist (if gb :PW :PB) (user-full-name)
                  (if gb :PB :PW) (concat "GNU Go " (gnugo-query "version")))))
     (unless (zerop handicap)
       (r! (plist :HA handicap
                  :AB (mapcar (gnugo--as-cc-func)
                              (gnugo-lsquery "fixed_handicap %d"

which would also be more efficient by avoiding the &rest processing.


PS: Not sure why I chose "plist" for that macro's name: a bad choice.

reply via email to

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