Skip to content

Instantly share code, notes, and snippets.

@suryagaddipati
Created July 30, 2010 14:51
Show Gist options
  • Save suryagaddipati/500650 to your computer and use it in GitHub Desktop.
Save suryagaddipati/500650 to your computer and use it in GitHub Desktop.
on lisp
;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"
@suryagaddipati
Copy link
Author

;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