DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Pairlis

10.14.2006
| 3288 views |
  • submit to reddit
        // common LISP compatible pairlis for newLISP

;; 
;;(pairlis '(1 2 3) '("one" "two" "three") '((4 "four"))) 
;;

 
(define (pairlis keys data alist) 
  (setq data2 data) 
  (setq newlist '()) 
  (dolist (x keys) 
          (push (list x (pop data2)) newlist -1)) 
  (append newlist alist)) 

;; newLISPy way

(define (pairlis keys data alist) 
  (append (map (lambda (x y) (list x y)) keys data) alist))