PAIRLIS
authorOwen Rodley <Strigoides@gmail.com>
Sat, 4 May 2013 00:25:42 +0000 (12:25 +1200)
committerOwen Rodley <Strigoides@gmail.com>
Sat, 4 May 2013 00:25:42 +0000 (12:25 +1200)
src/list.lisp
src/toplevel.lisp
tests/list.lisp

index 09092ad..b353700 100644 (file)
 (defun acons (key datum alist)
   (cons (cons key datum) alist))
 
+(defun pairlis (keys data &optional (alist ()))
+  (while keys
+    (setq alist (acons (car keys) (car data) alist))
+    (setq keys (cdr keys))
+    (setq data (cdr data)))
+  alist)
+
 
 (define-setf-expander car (x)
   (let ((cons (gensym))
index c03f370..b238135 100644 (file)
@@ -67,8 +67,8 @@
           make-symbol mapcar member minusp mod multiple-value-bind
           multiple-value-call multiple-value-list multiple-value-prog1
           nconc nil ninth not nreconc nth nthcdr null numberp or otherwise
-          package-name package-use-list packagep parse-integer plusp pop
-          prin1-to-string print proclaim prog1 prog2 progn psetq push
+          package-name package-use-list packagep pairlis parse-integer plusp
+          pop prin1-to-string print proclaim prog1 prog2 progn psetq push
           quote read-from-string remove remove-if remove-if-not return
           return-from revappend reverse rplaca rplacd second set setf seventh
           setq sixth some string string-upcase string= stringp subseq subst
index 7969b0b..78cec44 100644 (file)
              (acons 1 2 (list (cons 3 4)))))
 (test (equal (list (cons 1 2)) (acons 1 2 ())))
 
+; PAIRLIS
+(test (equal (list (cons 1 3) (cons 0 2))
+             (pairlis '(0 1) '(2 3))))
+(test (equal (list (cons 1 2) (cons 'a 'b))
+             (pairlis '(1) '(2) (list (cons 'a 'b)))))
+
 ; SUBST
 ; Can't really test this until EQUAL works properly on lists