Skip to content

Commit

Permalink
exported alist->plist and plist->alist from folio.collections.maps
Browse files Browse the repository at this point in the history
  • Loading branch information
mikelevins committed Sep 4, 2011
1 parent ed59ddd commit 0f827ef
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions collections/maps.lisp
Expand Up @@ -16,8 +16,8 @@
(:import-from :seq "EMPTY?")
(:nicknames "MAP")
(:shadow "GET" "MERGE")
(:export "ALIST" "ASSOCIATE" "CONTAINS-KEY?" "DISSOCIATE" "GET" "KEYS"
"MAKE" "MAKE-AS" "MERGE" "ORDERED-MAP" "PLIST" "VALS" "ZIPMAP"))
(:export "ALIST" "ALIST->PLIST" "ASSOCIATE" "CONTAINS-KEY?" "DISSOCIATE" "GET" "KEYS"
"MAKE" "MAKE-AS" "MERGE" "ORDERED-MAP" "PLIST" "PLIST->ALIST" "VALS" "ZIPMAP"))

(in-package :map)

Expand All @@ -32,15 +32,15 @@
;;; private utils
;;; =====================================================================

(defun %plist->alist (plist)
(defun plist->alist (plist)
(if (null plist)
nil
(if (null (cdr plist))
(error "Malformed key/value list in ~S" plist)
(acons (car plist) (cadr plist)
(%plist->alist (cddr plist))))))
(plist->alist (cddr plist))))))

(defun %alist->plist (alist)
(defun alist->plist (alist)
(seq:interleave (seq:image 'car alist)
(seq:image 'cdr alist)))

Expand Down Expand Up @@ -82,13 +82,13 @@
(fset:convert 'list thing))

(defmethod as ((class (eql 'plist)) (thing fset:map) &key &allow-other-keys)
(%alist->plist (fset:convert 'list thing)))
(alist->plist (fset:convert 'list thing)))

(defmethod as ((class (eql 'alist)) (thing ordered-map) &key &allow-other-keys)
(%map-entries thing))

(defmethod as ((class (eql 'plist)) (thing ordered-map) &key &allow-other-keys)
(%alist->plist (%map-entries thing)))
(alist->plist (%map-entries thing)))

(defmethod as ((class (eql 'alist)) (thing list) &key &allow-other-keys)
(make-instance 'alist-map-instance :data thing))
Expand All @@ -113,13 +113,13 @@
(reverse result)))

(defmethod as ((class (eql 'fset:map)) (thing plist-map-instance) &key &allow-other-keys)
(fset:convert 'fset:map (%plist->alist (data thing))))
(fset:convert 'fset:map (plist->alist (data thing))))

(defmethod as ((class (eql 'ordered-map)) (thing alist-map-instance) &key &allow-other-keys)
(make-instance 'ordered-map :entries (data thing)))

(defmethod as ((class (eql 'ordered-map)) (thing plist-map-instance) &key &allow-other-keys)
(make-instance 'ordered-map :entries (%plist->alist (data thing))))
(make-instance 'ordered-map :entries (plist->alist (data thing))))

;;; maps as sequences

Expand All @@ -133,7 +133,7 @@
(data thing))

(defmethod as ((class (eql 'sequence)) (thing plist-map-instance) &key &allow-other-keys)
(%alist->plist (data thing)))
(alist->plist (data thing)))

;;; other conversions

Expand All @@ -158,7 +158,7 @@
;;; ---------------------------------------------------------------------

(defun alist (&rest plist)
(%plist->alist plist))
(plist->alist plist))

;;; ---------------------------------------------------------------------
;;; associate
Expand Down

0 comments on commit 0f827ef

Please sign in to comment.