Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defmacro case-eval
- "
- 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.
- "
- [case- & body]
- (if (first body)
- (if (second body)
- (list 'if (list '= case- (first body))
- (list 'do (second body))
- `(case-eval ~@(cons case- (next (next body)))))
- (list 'if (list '= case- (first body))
- (list 'do (first body))
- nil
- )
- )
- nil
- )
- )
- TEST
- (let [x 1]
- (case-eval (= 1 x)
- "true" "false"
- (= 2 x) (println "you'll never see this.")
- true (println "you'll only see this. 1 =" x)
- x))
- ;> you'll only see this. 1 = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement