From 03ea705f5e6162d6d9dc7417e0db14d96c5715bb Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Sun, 25 Apr 2021 22:34:06 +0530 Subject: Add plist->alist. * ccwl/utils.scm (pairify, plist->alist): New public functions. --- ccwl/utils.scm | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ccwl/utils.scm b/ccwl/utils.scm index 4f041a7..c20aae1 100644 --- a/ccwl/utils.scm +++ b/ccwl/utils.scm @@ -27,7 +27,25 @@ #:use-module (srfi srfi-26) #:use-module (srfi srfi-71) #:use-module (ice-9 match) - #:export (lambda**)) + #:export (pairify + plist->alist + lambda**)) + +(define (pairify lst) + "Return a list of pairs of successive elements of LST." + (match lst + (() '()) + ((first second tail ...) + (cons (cons first second) + (pairify tail))))) + +(define (plist->alist plist) + "Convert the property list PLIST to an association list. A property +list is a list of the form (#:key1 value1 #:key2 value2 ...)." + (map (match-lambda + ((key . value) + (cons (keyword->symbol key) value))) + (pairify plist))) (define* (group-keyword-arguments args #:optional (unary-keywords (list))) "Group ARGS, a list of keyword arguments of arbitrary arity. Return -- cgit v1.2.3