Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;testing for nothing
  2. (defn null-v1? [lat]
  3.   (or (empty? lat) (and (= (first lat) nil) (= (count lat) 1))))
  4. (defn null-v2? [lat]
  5.   (comp nil? lat))
  6.  
  7. ;some sample lists
  8. (def foods (list "owl curry" "rack of owl" "chicken-fried owl" "owl a la mode"))
  9. (def reactions (list "delightful" "succulent" "paradoxical" "decadent"))
  10.  
  11. ;a simple recursive function using a tail-recursive style
  12. (defn eat [lat ladj null-pred?]
  13.   (cond (null-pred? lat) "*burp*" (null-pred? ladj) "I'm afraid I must be leaving now. I'm barfing."
  14.         :else (str "Mmm, " (first lat) ". How " (first ladj) ". " (eat (rest lat) (rest ladj) null-pred?))))
  15.  
  16. (time (eat foods reactions null-v1?))
  17. ;"Elapsed time: 0.08 msecs"
  18. ;=> "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*"
  19. (time (eat foods reactions null-v2?))
  20. ;"Elapsed time: 0.043 msecs"
  21. ;=> "*burp*"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement