Created
July 30, 2010 14:51
-
-
Save suryagaddipati/500650 to your computer and use it in GitHub Desktop.
on lisp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;1; | |
(sort #(> %2 %1) '( 1 4 2 )) | |
;2; | |
(def x 5 ) | |
(let [x 2] (print x)) ; x 5 local scope | |
(binding [ x 2] ( print x )) ; x=> global scope | |
;3; | |
(defn makeaddr [n] #(+ % n)) | |
(def addr2 (makeaddr 2)) | |
(addr2 5 ) ; => 7 | |
;4; | |
(defn list+ [ lst a ] (map #(+ % a) lst) ) | |
(list+ [10 20] 5 ) ; (15 25) | |
;5; | |
(defn nicknames [name] ` ( (str name 1) (str name 2)) ) ; arbitrary implementation | |
(defn allnicknames [lstnames ] (mapcat nicknames lstnames)) | |
(allnicknames `("jetpaks" " promise")) ; (jetpaks1 jetpaks2 promise1 promise2) | |
;6; | |
(def add10AndPrint (comp #(print %) #(+ % 10) )) | |
(add10AndPrint 5) ; 15 | |
;7; | |
(defn printall [ x y ] ( str x " and " y )) | |
( def printsome (partial printall "surya")) | |
(printsome "g") ; "surya and g" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
;7;
(defn printall [ x y ](str x " and " y))
( def printsome (partial printall "surya"))
(printsome "g") ; "surya and g"