Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;testing for nothing
- (defn null-v1? [lat]
- (or (empty? lat) (and (= (first lat) nil) (= (count lat) 1))))
- (defn null-v2? [lat]
- (comp nil? lat))
- ;some sample lists
- (def foods (list "owl curry" "rack of owl" "chicken-fried owl" "owl a la mode"))
- (def reactions (list "delightful" "succulent" "paradoxical" "decadent"))
- ;a simple recursive function using a tail-recursive style
- (defn eat [lat ladj null-pred?]
- (cond (null-pred? lat) "*burp*" (null-pred? ladj) "I'm afraid I must be leaving now. I'm barfing."
- :else (str "Mmm, " (first lat) ". How " (first ladj) ". " (eat (rest lat) (rest ladj) null-pred?))))
- (time (eat foods reactions null-v1?))
- ;"Elapsed time: 0.08 msecs"
- ;=> "Mmm, owl curry. How delightful. Mmm, rack of owl. How succulent. Mmm, owl wellington. How extravagant. Mmm, chicken-fried owl. How velvety. Mmm, owl a la mode. How decadent. *burp*"
- (time (eat foods reactions null-v2?))
- ;"Elapsed time: 0.043 msecs"
- ;=> "*burp*"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement