Hy | Python |
(setv foobar (+ 2 2))
(setv [tim eric] ["jim" "derrick"])
(setv alpha "a" beta "b")
| foobar = 2 + 2
tim, eric = 'jim', 'derrick'
alpha = 'a'; beta = 'b'
|
(sorted "abcBC"
:key (fn [x] (.lower x)))
| sorted("abcBC",
key = lambda x: x.lower())
|
(defn test [a b [c "x"] #* d]
[a b c d])
| def test(a, b, c="x", *d):
return [a, b, c, d]
|
(with [o (open "file.txt" "rt")]
(setv buffer [])
(while (< (len buffer) 10)
(.append buffer (next o))))
| with open('file.txt', 'rt') as o:
buffer = []
while len(buffer) < 10:
buffer.append(next(o))
|
(lfor
x (range 3)
y (range 3)
:if (= (+ x y) 3)
(* x y))
| [x * y
for x in range(3)
for y in range(3)
if x + y == 3]
|
(defmacro do-while [test #* body]
`(do
~@body
(while ~test
~@body)))
(setv x 0)
(do-while x
(print "Printed once."))
| x = 0
print("Printed once.")
while x:
print("Printed once.")
|