Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

more new functions

  • Loading branch information...
commit b4c0549913c8ca643a90eb9b879d185cadd0b379 1 parent 4210b1f
Nic Ferrier authored

Showing 1 changed file with 44 additions and 1 deletion. Show diff stats Hide diff stats

  1. +44 1 kv.el
45 kv.el
@@ -4,7 +4,7 @@
4 4
5 5 ;; Author: Nic Ferrier <nferrier@ferrier.me.uk>
6 6 ;; Keywords: lisp
7   -;; Version: 0.0.4
  7 +;; Version: 0.0.5
8 8 ;; Maintainer: Nic Ferrier <nferrier@ferrier.me.uk>
9 9 ;; Created: 7th September 2012
10 10
@@ -71,6 +71,34 @@ HASH-TABLE-ARGS are passed to the hash-table creation."
71 71 (car pair)))))
72 72 (cdr pair))))
73 73
  74 +(defun kvplist->alist (plist)
  75 + "Convert PLIST to an alist.
  76 +
  77 +The keys are expected to be :prefixed and the colons are removed.
  78 +The keys in the resulting alist are symbols."
  79 + (labels
  80 + ((plist->alist-cons (a b lst)
  81 + (let ((key (intern (substring (symbol-name a) 1))))
  82 + (if (car-safe lst)
  83 + (cons
  84 + (cons key b)
  85 + (plist->alist-cons
  86 + (car lst)
  87 + (cadr lst)
  88 + (cddr lst)))
  89 + ;; Else
  90 + (cons (cons key b) nil)))))
  91 + (plist->alist-cons
  92 + (car plist)
  93 + (cadr plist)
  94 + (cddr plist))))
  95 +
  96 +(defun kvalist2->plist (alist2)
  97 + "Convert a list of alists too a list of plists."
  98 + (loop for alist in alist2
  99 + append
  100 + (list (kvalist->plist alist))))
  101 +
74 102 (defun kvalist->keys (alist)
75 103 "Get just the keys from the alist."
76 104 (mapcar (lambda (pair) (car pair)) alist))
@@ -95,6 +123,21 @@ Only pairs where the car is a `member' of KEYS will be returned."
95 123 if (member (car a) keys)
96 124 collect a))
97 125
  126 +(defun kvplist->filter-keys (plist &rest keys)
  127 + "Return the PLIST filtered to the KEYS list.
  128 +
  129 +Only plist parts where the car is a `member' of KEYS will be
  130 +returned."
  131 + (kvalist->plist
  132 + (loop for a in (kvplist-> plist)
  133 + if (member (car a) keys)
  134 + collect a)))
  135 +
  136 +(defun kvcmp (a b)
  137 + "Do a comparison of the two values using printable syntax."
  138 + (string-lessp (format "%S" a)
  139 + (format "%S" b)))
  140 +
98 141 (defun kvdotassoc-fn (expr table func)
99 142 "Use the dotted EXPR to access deeply nested data in TABLE.
100 143

0 comments on commit b4c0549

Please sign in to comment.
Something went wrong with that request. Please try again.