(print "hello world") (+ 1 3) (+ 1 3 55) (let result (- (/ (+ 1 3 88) 2) 8)) (setv result (- (/ (+ 1 3 88) 2) 8)) ; simplified to... (setv result (- (/ 92 2) 8)) ; simplified to... (setv result (- 46 8)) ; simplified to... (setv result 38) (defn simple-conversation [] (print "Hello! I'd like to get to know you. Tell me about yourself!") (setv name (raw_input "What is your name? ")) (setv age (raw_input "What is your age? ")) (print (+ "Hello " name "! I see you are " age " years old."))) (simple-conversation) [1 2 3] {"dog" "bark" "cat" "meow"} (, 1 2 3) '(1 2 3) (.strip " fooooo ") (setv this-string " fooooo ") (this-string.strip) (if (try-some-thing) (print "this is if true") (print "this is if false")) (setv somevar 33) (cond [(> somevar 50) (print "That variable is too big!")] [(< somevar 10) (print "That variable is too small!")] [true (print "That variable is jussssst right!")]) (if some-condition (body-if-true) (body-if-false)) (if (try-some-thing) (do (print "this is if true") (print "and why not, let's keep talking about how true it is!")) (print "this one's still simply just false")) (print "this will run") ; (print "but this will not") (+ 1 2 3) ; we'll execute the addition, but not this comment! (for [i (range 10)] (print (+ "'i' is now at " (str i)))) (import os) (if (os.path.isdir "/tmp/somedir") (os.mkdir "/tmp/somedir/anotherdir") (print "Hey, that path isn't there!")) (with [[f (open "/tmp/data.in")]] (print (.read f))) (setv odds-squared (list-comp (pow num 2) (num (range 100)) (= (% num 2) 1))) ; And, an example stolen shamelessly from a Clojure page: ; Let's list all the blocks of a Chessboard: (list-comp (, x y) (x (range 8) y "ABCDEFGH")) (defn optional_arg [pos1 pos2 &optional keyword1 [keyword2 42]] [pos1 pos2 keyword1 keyword2]) (optional_arg 1 2) (optional_arg 1 2 3 4) (apply optional_arg [] {"keyword1" 1 "pos2" 2 "pos1" 3 "keyword2" 4}) (defn another_style [&key {"key1" "val1" "key2" "val2"}] [key1 key2]) (defn some_func [foo bar &rest args &kwargs kwargs] (import pprint) (pprint.pprint (, foo bar args kwargs))) (defclass FooBar [object] "Yet Another Example Class" [[--init-- (fn [self x] (setv self.x x) ; Currently needed for --init-- because __init__ needs None ; Hopefully this will go away :) None)] [get-x (fn [self] "Return our copy of x" self.x)]]) (defclass Customer [models.Model] [[name (apply models.CharField [] {"max_length" 255})] [address (models.TextField)] [notes (models.TextField)]]) (loop (print (eval (read)))) (-> (read) (eval) (print) (loop)) (import [sh [cat grep wc]]) (-> (cat "/usr/share/dict/words") (grep "-E" "^hy") (wc "-l")) (wc (grep (cat "/usr/share/dict/words") "-E" "^hy") "-l")