Advertisement
Guest User

Untitled

a guest
Nov 25th, 2013
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 0.57 KB | None | 0 0
  1. (defun xons (x y)
  2.   (labels ((fwd (x y)
  3.              (setf (fdefinition 'xons) #'bwd)
  4.              (cons x y))
  5.            (bwd (x y)
  6.              (setf (fdefinition 'xons) #'fwd)
  7.              (cons y x)))
  8.     (fwd x y)))
  9.  
  10. (mapcar 'xons '(1 2 3 4 5 6) '(a b c d e f))
  11. ;=> ((A . 1) (B . 2) (C . 3) (D . 4) (E . 5) (F . 6)) ; first time
  12. ;=> ((1 . A) (2 . B) (3 . C) (4 . D) (5 . E) (6 . F)) ; second time
  13.  
  14. (reduce 'xons '(1 2 3 4 5 6) :initial-value '())
  15. ;=> (1 2 3 4 5 6)                            ; first time
  16. ;=> ((((((NIL . 1) . 2) . 3) . 4) . 5) . 6)  ; second time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement