From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: design ponderings: plist to alist Date: Wed, 16 Apr 2014 12:04:06 +0200 Organization: Informatimago Message-ID: <871twx3815.fsf@kuiper.lan.informatimago.com> References: <87a9bl7rkd.fsf@zigzag.favinet> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1397642904 31712 80.91.229.3 (16 Apr 2014 10:08:24 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 16 Apr 2014 10:08:24 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Apr 16 12:08:19 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WaMlO-0007Wr-Lu for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Apr 2014 12:08:18 +0200 Original-Received: from localhost ([::1]:53751 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaMlO-0003GU-67 for geh-help-gnu-emacs@m.gmane.org; Wed, 16 Apr 2014 06:08:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaMl5-00036s-6v for help-gnu-emacs@gnu.org; Wed, 16 Apr 2014 06:08:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WaMky-0008RK-08 for help-gnu-emacs@gnu.org; Wed, 16 Apr 2014 06:07:59 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:48904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WaMkx-0008RA-Pi for help-gnu-emacs@gnu.org; Wed, 16 Apr 2014 06:07:51 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WaMkv-0006Rm-NW for help-gnu-emacs@gnu.org; Wed, 16 Apr 2014 12:07:49 +0200 Original-Received: from amontsouris-654-1-20-159.w90-2.abo.wanadoo.fr ([90.2.155.159]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 16 Apr 2014 12:07:49 +0200 Original-Received: from pjb by amontsouris-654-1-20-159.w90-2.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 16 Apr 2014 12:07:49 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 77 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-654-1-20-159.w90-2.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:ODE0YTQ0YmY1YTNhMTliN2MzNGZkODg5YTliNDMyM2JhNWFjNWY4Yw== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:97151 Archived-At: Thien-Thi Nguyen writes: > This fragment (from gnugo.el): > (let ((root (gnugo--root-node))) > (cl-flet > ((r! (&rest plist) > (gnugo--decorate > root (loop ; hmm, available elsewhere? > while plist > collect (let* ((k (pop plist)) > (v (pop plist))) > (cons k v)))))) > (r! :SZ board-size > :DT (format-time-string "%Y-%m-%d") > :RU (if (string-match "--chinese-rules" args) > "Chinese" > "Japanese") > :AP (cons "gnugo.el" gnugo-version) > :KM komi) > (let ((gb (gnugo--blackp (gnugo-other user-color)))) > (r! (if gb :PW :PB) (user-full-name) > (if gb :PB :PW) (concat "GNU Go " (gnugo-query "version")))) > (unless (zerop handicap) > (r! :HA handicap > :AB (mapcar (gnugo--as-cc-func) > (gnugo-lsquery "fixed_handicap %d" > handicap)))))) > includes a function to convert plist (succinct to humans) to alist > (succinct to computers). Actually, an a-list contains the same number of cons cells and requires the same number of accesses as a p-list. I wouldn't say it's more succinct to computer than p-list. There are only two places where lisp marks a preference to p-list rather than a-list: - symbol-plist, get, (setf get) - &key parameter. The only advantage of A-list, is that you can process entries independently. So if you have to move entries from place to place or if you need to share them amongst several collections, it's preferable to p-list where you would have to copy all the cons cells: (let* ((a1 (list (cons :a 1) (cons :b 2) (cons :c 3))) (a2 (list (first a1) (cons :b 3) (third a1)))) (setf (cdr (assoc :a a1)) 42) a2) --> ((:a . 42) (:b . 3) (:c . 3)) This wouldn't be possible with p-list, since the cons cell containing 1 couldn't have two cdr cells, to (cdr a1) and to (cdr a2). But if you don't need to extract, insert or mutate entries _independently_, then p-list may be prefered since they can be used with &key. > 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? This is not a popularity contest. -- __Pascal Bourguignon__ http://www.informatimago.com/ "Le mercure monte ? C'est le moment d'acheter !"