Advertisement
Guest User

Untitled

a guest
Dec 29th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (defmacro case-eval
  2.   "
  3. This implementation of (case) accepts any type and posibly repeated clauses, returns the clause pair as the only pair evaluated of the clause equal to case-. If there is a clause without pair it is considered as the default and is returned only if is equal to case-. Othewhise returns nil.
  4. "
  5.   [case- & body]
  6.   (if (first body)
  7.     (if (second body)
  8.       (list 'if (list '= case- (first body))
  9.             (list 'do (second body))
  10.             `(case-eval ~@(cons case- (next (next body)))))
  11.       (list 'if (list '= case- (first body))
  12.             (list 'do (first body))
  13.             nil
  14.             )
  15.       )
  16.     nil
  17.     )
  18.   )
  19.  
  20. TEST
  21. (let [x 1]
  22.     (case-eval (= 1 x)
  23.                "true" "false"
  24.                (= 2 x) (println "you'll never see this.")
  25.                true (println "you'll only see this. 1 =" x)
  26.                x))
  27. ;> you'll only see this. 1 = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement