alist2plist
Created by: reiniervandijk
gdl:alist2plist function gives error when official alist is provided. "official" according to the definition: an a-list is a list of pairs (conses):
http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node153.html
Looking at the source, gdl:alist2plist can only deal with list pairs, and not dotted pairs, although these are perfectly valid building stones of a alist.
Replicate
(gdl:alist2plist '(("foo" . 3) ("bar" . 4)))
Imported comments:
By genworks on 2015-01-30 00:38:43 UTC
Open for submission: $50
By reiniervandijk on 2015-01-30 11:08:59 UTC
(in-package :gdl-user)
(defun alist2plist (alist)
"Plist. Converts an assoc-list to a plist.
:arguments (alist \"Assoc-List\"). Supports both alists
with list syntax or dotted style notation. Examples:
gdl-user> (alist2plist '((:foo . 1) (:bar . 2)))
(:foo 1 :bar 2)
gdl-user> (alist2plist '((:foo 1) (:bar 2)))
(:foo 1 :bar 2)
"
(when alist
(cons (first (first alist))
(cons
;; test cdr list syntax (1 2)
;; or dotted pair notation (1 . 2)
(let ((token (rest (first alist))))
(if (consp token)
;; list syntax
(first token)
;; dotted pair
token))
;; recurse
(alist2plist (rest alist))))))