Lipsy
(alert "Hello World")
Run
Function declaration
(def factorial (fn [x] (if (zero? x) 1 (* x (factorial (dec x)))))) (alert (factorial 5))
Run
List evens
;; Printing in console (print (filter even? (range 50)))
Run
Short-hand lambda
;; Printing in console (map #(* % %) (range 10))
Run
Rest Args
(def allExceptFirst (fn [x & more] more)) (allExceptFirst 1 2 3 4)
Run
Closure
(def add (fn [x] (fn [y] (+ x y)))) (def add5 (add 5)) (print (add5 2))
Run
JS Interop
(alert (Math.pow 2 3))
Run
Lazy Evaluation
(def echo (fn [x] (alert x) x)) (def returnFirst (fn [x] x)) ;; Because the function 'returnFirst' only uses first parameter, only '1' will ;; be printed. The arguments while invoking a function are not immediately ;; evaluated. Arguments are evaluated on demand. (returnFirst (echo 1) (echo 2) (echo 3))
Run