Re-indent Hy code using hy-mode
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
9776b7133e
commit
27e74d43b1
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env hy
|
#!/usr/bin/env hy
|
||||||
; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
|
;; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
|
||||||
; of the Expat license, a copy of which you have should have recieved with
|
;; of the Expat license, a copy of which you have should have received with
|
||||||
; the source.
|
;; the source.
|
||||||
|
|
||||||
|
|
||||||
(import sys)
|
(import sys)
|
||||||
@ -10,7 +10,7 @@
|
|||||||
(defn parse-rfc822-file [path]
|
(defn parse-rfc822-file [path]
|
||||||
"Parse an RFC822 file"
|
"Parse an RFC822 file"
|
||||||
(with-as (open path "r") fd
|
(with-as (open path "r") fd
|
||||||
(parse-rfc822-stream fd)))
|
(parse-rfc822-stream fd)))
|
||||||
|
|
||||||
|
|
||||||
(defn parse-rfc822-stream [fd]
|
(defn parse-rfc822-stream [fd]
|
||||||
@ -19,14 +19,14 @@
|
|||||||
(setv key null)
|
(setv key null)
|
||||||
(for [line fd]
|
(for [line fd]
|
||||||
(if (in ":" line)
|
(if (in ":" line)
|
||||||
(do (setv line (.split line ":" 1))
|
(do (setv line (.split line ":" 1))
|
||||||
(setv key (.strip (get line 0)))
|
(setv key (.strip (get line 0)))
|
||||||
(setv val (.strip (get line 1)))
|
(setv val (.strip (get line 1)))
|
||||||
(assoc bits key val))
|
(assoc bits key val))
|
||||||
(do
|
(do
|
||||||
(if (= (.strip line) ".")
|
(if (= (.strip line) ".")
|
||||||
(assoc bits key (+ (get bits key) "\n"))
|
(assoc bits key (+ (get bits key) "\n"))
|
||||||
(assoc bits key (+ (get bits key) "\n" (.strip line)))))))
|
(assoc bits key (+ (get bits key) "\n" (.strip line)))))))
|
||||||
bits)
|
bits)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/env hy
|
#!/usr/bin/env hy
|
||||||
|
|
||||||
; Very much a knockoff (straight port) of Dan Gulotta's 2013 MIT Mystery Hunt
|
;; Very much a knockoff (straight port) of Dan Gulotta's 2013 MIT Mystery Hunt
|
||||||
; puzzle "The Halting Problem". His Copyright terms are unclear, so presume
|
;; puzzle "The Halting Problem". His Copyright terms are unclear, so presume
|
||||||
; that this is distributable, but not free.
|
;; that this is distributable, but not free.
|
||||||
|
|
||||||
|
|
||||||
(defn evaluate [f] ((f (lambda [x] (+ x 1))) 0))
|
(defn evaluate [f] ((f (lambda [x] (+ x 1))) 0))
|
||||||
@ -14,7 +14,7 @@
|
|||||||
(defn one [f] (lambda [x] (f x)))
|
(defn one [f] (lambda [x] (f x)))
|
||||||
|
|
||||||
(defn predecessor [n] (lambda [f] (lambda [x]
|
(defn predecessor [n] (lambda [f] (lambda [x]
|
||||||
(((n (lambda [g] (lambda [h] (h (g f))))) (lambda [y] x)) (lambda [z] z)))))
|
(((n (lambda [g] (lambda [h] (h (g f))))) (lambda [y] x)) (lambda [z] z)))))
|
||||||
|
|
||||||
(defn subtract [m n] ((m predecessor) n))
|
(defn subtract [m n] ((m predecessor) n))
|
||||||
|
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
|
|
||||||
|
|
||||||
(with-as (ThreadPoolExecutor 10) executor
|
(with-as (ThreadPoolExecutor 10) executor
|
||||||
(setf jobs (list-comp (.submit executor task-to-do) (x (range 0 10))))
|
(setf jobs (list-comp (.submit executor task-to-do) (x (range 0 10))))
|
||||||
(for (future (as-completed jobs))
|
(for (future (as-completed jobs))
|
||||||
(.result future)))
|
(.result future)))
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
; hello, rHy!
|
;; hello, rHy!
|
||||||
|
|
||||||
|
|
||||||
(defn fib [n]
|
(defn fib [n]
|
||||||
(if (<= n 2) n
|
(if (<= n 2) n
|
||||||
(+ (fib (- n 1)) (fib (- n 2)))))
|
(+ (fib (- n 1)) (fib (- n 2)))))
|
||||||
|
|
||||||
|
|
||||||
(defn main [argv]
|
(defn main [argv]
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env hy
|
#!/usr/bin/env hy
|
||||||
; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
|
;; Copyright (c) Paul R. Tagliamonte <paultag@debian.org>, 2013 under the terms
|
||||||
; of the Expat license, a copy of which you have should have recieved with
|
;; of the Expat license, a copy of which you have should have recieved with
|
||||||
; the source.
|
;; the source.
|
||||||
|
|
||||||
(import sys)
|
(import sys)
|
||||||
(import [sunlight [openstates]]
|
(import [sunlight [openstates]]
|
||||||
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
(defn get-party-breakdown [state]
|
(defn get-party-breakdown [state]
|
||||||
(Counter (map
|
(Counter (map
|
||||||
(lambda [x] (get x "party"))
|
(lambda [x] (get x "party"))
|
||||||
(get-legislators state))))
|
(get-legislators state))))
|
||||||
|
|
||||||
|
|
||||||
(print *state* "-" (get-party-breakdown *state*))
|
(print *state* "-" (get-party-breakdown *state*))
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
;
|
|
||||||
|
|
||||||
(import [tests.resources [kwtest function-with-a-dash]]
|
(import [tests.resources [kwtest function-with-a-dash]]
|
||||||
[os.path [exists isdir isfile]]
|
[os.path [exists isdir isfile]]
|
||||||
[sys :as systest])
|
[sys :as systest])
|
||||||
@ -8,9 +6,7 @@
|
|||||||
|
|
||||||
(defn test-sys-argv []
|
(defn test-sys-argv []
|
||||||
"NATIVE: test sys.argv"
|
"NATIVE: test sys.argv"
|
||||||
;
|
;; BTW, this also tests inline comments. Which suck to implement.
|
||||||
; BTW, this also tests inline comments. Which suck to implement.
|
|
||||||
;
|
|
||||||
(assert (isinstance sys.argv list)))
|
(assert (isinstance sys.argv list)))
|
||||||
|
|
||||||
|
|
||||||
@ -85,36 +81,36 @@
|
|||||||
(defn test-branching []
|
(defn test-branching []
|
||||||
"NATIVE: test if branching"
|
"NATIVE: test if branching"
|
||||||
(if true
|
(if true
|
||||||
(assert (= 1 1))
|
(assert (= 1 1))
|
||||||
(assert (= 2 1))))
|
(assert (= 2 1))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-branching-with-do []
|
(defn test-branching-with-do []
|
||||||
"NATIVE: test if branching (multiline)"
|
"NATIVE: test if branching (multiline)"
|
||||||
(if false
|
(if false
|
||||||
(assert (= 2 1))
|
(assert (= 2 1))
|
||||||
(do
|
(do
|
||||||
(assert (= 1 1))
|
(assert (= 1 1))
|
||||||
(assert (= 1 1))
|
(assert (= 1 1))
|
||||||
(assert (= 1 1)))))
|
(assert (= 1 1)))))
|
||||||
|
|
||||||
(defn test-branching-expr-count-with-do []
|
(defn test-branching-expr-count-with-do []
|
||||||
"NATIVE: make sure we execute the right number of expressions in the branch"
|
"NATIVE: make sure we execute the right number of expressions in the branch"
|
||||||
(setv counter 0)
|
(setv counter 0)
|
||||||
(if false
|
(if false
|
||||||
(assert (= 2 1))
|
(assert (= 2 1))
|
||||||
(do
|
(do
|
||||||
(setv counter (+ counter 1))
|
(setv counter (+ counter 1))
|
||||||
(setv counter (+ counter 1))
|
(setv counter (+ counter 1))
|
||||||
(setv counter (+ counter 1))))
|
(setv counter (+ counter 1))))
|
||||||
(assert (= counter 3)))
|
(assert (= counter 3)))
|
||||||
|
|
||||||
|
|
||||||
(defn test-cond []
|
(defn test-cond []
|
||||||
"NATIVE: test if cond sorta works."
|
"NATIVE: test if cond sorta works."
|
||||||
(cond
|
(cond
|
||||||
((= 1 2) (assert (is true false)))
|
((= 1 2) (assert (is true false)))
|
||||||
((is null null) (assert (is true true)))))
|
((is null null) (assert (is true true)))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-index []
|
(defn test-index []
|
||||||
@ -181,37 +177,37 @@
|
|||||||
;; Test correct (raise)
|
;; Test correct (raise)
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(try
|
(try
|
||||||
(raise IndexError)
|
(raise IndexError)
|
||||||
(except [IndexError] (raise)))
|
(except [IndexError] (raise)))
|
||||||
(except [IndexError]
|
(except [IndexError]
|
||||||
(setv passed true)))
|
(setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
;; Test incorrect (raise)
|
;; Test incorrect (raise)
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(raise)
|
(raise)
|
||||||
;; Python 2 raises TypeError
|
;; Python 2 raises TypeError
|
||||||
;; Python 3 raises RuntimeError
|
;; Python 3 raises RuntimeError
|
||||||
(except [[TypeError RuntimeError]]
|
(except [[TypeError RuntimeError]]
|
||||||
(setv passed true)))
|
(setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
|
|
||||||
;; Test (finally)
|
;; Test (finally)
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(do)
|
(do)
|
||||||
(finally (setv passed true)))
|
(finally (setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
;; Test (finally) + (raise)
|
;; Test (finally) + (raise)
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(raise Exception)
|
(raise Exception)
|
||||||
(except)
|
(except)
|
||||||
(finally (setv passed true)))
|
(finally (setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
|
|
||||||
@ -219,101 +215,101 @@
|
|||||||
(let [[passed false]
|
(let [[passed false]
|
||||||
[not-elsed true]]
|
[not-elsed true]]
|
||||||
(try
|
(try
|
||||||
(raise Exception)
|
(raise Exception)
|
||||||
(except)
|
(except)
|
||||||
(else (setv not-elsed false))
|
(else (setv not-elsed false))
|
||||||
(finally (setv passed true)))
|
(finally (setv passed true)))
|
||||||
(assert passed)
|
(assert passed)
|
||||||
(assert not-elsed))
|
(assert not-elsed))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(raise (KeyError))
|
(raise (KeyError))
|
||||||
(catch [[IOError]] (assert false))
|
(catch [[IOError]] (assert false))
|
||||||
(catch [e [KeyError]] (assert e)))
|
(catch [e [KeyError]] (assert e)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(throw (KeyError))
|
(throw (KeyError))
|
||||||
(except [[IOError]] (assert false))
|
(except [[IOError]] (assert false))
|
||||||
(catch [e [KeyError]] (assert e)))
|
(catch [e [KeyError]] (assert e)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(catch [IndexError] (assert true))
|
(catch [IndexError] (assert true))
|
||||||
(except [IndexError] (do)))
|
(except [IndexError] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(catch [IndexError] (assert false))
|
(catch [IndexError] (assert false))
|
||||||
(except [NameError] (do)))
|
(except [NameError] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(except [e IndexError] (assert (isinstance e IndexError))))
|
(except [e IndexError] (assert (isinstance e IndexError))))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(catch [e [IndexError NameError]] (assert (isinstance e IndexError))))
|
(catch [e [IndexError NameError]] (assert (isinstance e IndexError))))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(except [e [IndexError NameError]] (assert (isinstance e NameError))))
|
(except [e [IndexError NameError]] (assert (isinstance e NameError))))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42)
|
(print foobar42)
|
||||||
(catch [[IndexError NameError]] (do)))
|
(catch [[IndexError NameError]] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(get [1] 3)
|
(get [1] 3)
|
||||||
(catch [[IndexError NameError]] (do)))
|
(catch [[IndexError NameError]] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(catch))
|
(catch))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(except []))
|
(except []))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(except [] (do)))
|
(except [] (do)))
|
||||||
|
|
||||||
(try
|
(try
|
||||||
(print foobar42ofthebaz)
|
(print foobar42ofthebaz)
|
||||||
(catch []
|
(catch []
|
||||||
(setv foobar42ofthebaz 42)
|
(setv foobar42ofthebaz 42)
|
||||||
(assert (= foobar42ofthebaz 42))))
|
(assert (= foobar42ofthebaz 42))))
|
||||||
|
|
||||||
(let [[passed false]]
|
(let [[passed false]]
|
||||||
(try
|
(try
|
||||||
(try (do) (except) (else (bla)))
|
(try (do) (except) (else (bla)))
|
||||||
(except [NameError] (setv passed true)))
|
(except [NameError] (setv passed true)))
|
||||||
(assert passed))
|
(assert passed))
|
||||||
|
|
||||||
(let [[x 0]]
|
(let [[x 0]]
|
||||||
(try
|
(try
|
||||||
(raise IOError)
|
(raise IOError)
|
||||||
(except [IOError]
|
(except [IOError]
|
||||||
(setv x 45))
|
(setv x 45))
|
||||||
(else (setv x 44)))
|
(else (setv x 44)))
|
||||||
(assert (= x 45)))
|
(assert (= x 45)))
|
||||||
|
|
||||||
(let [[x 0]]
|
(let [[x 0]]
|
||||||
(try
|
(try
|
||||||
|
(raise KeyError)
|
||||||
|
(except []
|
||||||
|
(setv x 45))
|
||||||
|
(else (setv x 44)))
|
||||||
|
(assert (= x 45)))
|
||||||
|
|
||||||
|
(let [[x 0]]
|
||||||
|
(try
|
||||||
|
(try
|
||||||
(raise KeyError)
|
(raise KeyError)
|
||||||
(except []
|
(except [IOError]
|
||||||
(setv x 45))
|
(setv x 45))
|
||||||
(else (setv x 44)))
|
(else (setv x 44)))
|
||||||
(assert (= x 45)))
|
(except))
|
||||||
|
|
||||||
(let [[x 0]]
|
|
||||||
(try
|
|
||||||
(try
|
|
||||||
(raise KeyError)
|
|
||||||
(except [IOError]
|
|
||||||
(setv x 45))
|
|
||||||
(else (setv x 44)))
|
|
||||||
(except))
|
|
||||||
(assert (= x 0))))
|
(assert (= x 0))))
|
||||||
|
|
||||||
(defn test-earmuffs []
|
(defn test-earmuffs []
|
||||||
@ -410,9 +406,9 @@
|
|||||||
"NATIVE: test for-do"
|
"NATIVE: test for-do"
|
||||||
(do (do (do (do (do (do (do (do (do (setf (, x y) (, 0 0)))))))))))
|
(do (do (do (do (do (do (do (do (do (setf (, x y) (, 0 0)))))))))))
|
||||||
(foreach [- [1 2]]
|
(foreach [- [1 2]]
|
||||||
(do
|
(do
|
||||||
(setf x (+ x 1))
|
(setf x (+ x 1))
|
||||||
(setf y (+ y 1))))
|
(setf y (+ y 1))))
|
||||||
(assert (= y x 2)))
|
(assert (= y x 2)))
|
||||||
|
|
||||||
|
|
||||||
@ -420,14 +416,14 @@
|
|||||||
"NATIVE: test foreach else"
|
"NATIVE: test foreach else"
|
||||||
(let [[x 0]]
|
(let [[x 0]]
|
||||||
(foreach [a [1 2]]
|
(foreach [a [1 2]]
|
||||||
(setv x (+ x a))
|
(setv x (+ x a))
|
||||||
(else (setv x (+ x 50))))
|
(else (setv x (+ x 50))))
|
||||||
(assert (= x 53)))
|
(assert (= x 53)))
|
||||||
|
|
||||||
(let [[x 0]]
|
(let [[x 0]]
|
||||||
(foreach [a [1 2]]
|
(foreach [a [1 2]]
|
||||||
(setv x (+ x a))
|
(setv x (+ x a))
|
||||||
(else))
|
(else))
|
||||||
(assert (= x 3))))
|
(assert (= x 3))))
|
||||||
|
|
||||||
|
|
||||||
@ -464,9 +460,9 @@
|
|||||||
(setv acc [])
|
(setv acc [])
|
||||||
(defn my-fun []
|
(defn my-fun []
|
||||||
(do
|
(do
|
||||||
(.append acc "Foo")
|
(.append acc "Foo")
|
||||||
(.append acc "Bar")
|
(.append acc "Bar")
|
||||||
(.append acc "Baz")))
|
(.append acc "Baz")))
|
||||||
(my-fun)
|
(my-fun)
|
||||||
(assert (= acc ["Foo" "Bar" "Baz"])))
|
(assert (= acc ["Foo" "Bar" "Baz"])))
|
||||||
|
|
||||||
@ -475,8 +471,8 @@
|
|||||||
"NATIVE: test defn return with do"
|
"NATIVE: test defn return with do"
|
||||||
(defn my-fun [x]
|
(defn my-fun [x]
|
||||||
(do
|
(do
|
||||||
(+ x 42) ; noop
|
(+ x 42) ; noop
|
||||||
(+ x 1)))
|
(+ x 1)))
|
||||||
(assert (= 43 (my-fun 42))))
|
(assert (= 43 (my-fun 42))))
|
||||||
|
|
||||||
|
|
||||||
@ -518,8 +514,8 @@
|
|||||||
(+ x y z))
|
(+ x y z))
|
||||||
6))
|
6))
|
||||||
(try
|
(try
|
||||||
(assert (= x 42)) ; This ain't true
|
(assert (= x 42)) ; This ain't true
|
||||||
(catch [e [NameError]] (assert e)))
|
(catch [e [NameError]] (assert e)))
|
||||||
(assert (= y 123)))
|
(assert (= y 123)))
|
||||||
|
|
||||||
|
|
||||||
@ -527,23 +523,23 @@
|
|||||||
"NATIVE: test symbol encoded"
|
"NATIVE: test symbol encoded"
|
||||||
(let [[♥ "love"]
|
(let [[♥ "love"]
|
||||||
[⚘ "flower"]]
|
[⚘ "flower"]]
|
||||||
(assert (= (+ ⚘ ♥) "flowerlove"))))
|
(assert (= (+ ⚘ ♥) "flowerlove"))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-symbol-dash []
|
(defn test-symbol-dash []
|
||||||
"NATIVE: test symbol encoded"
|
"NATIVE: test symbol encoded"
|
||||||
(let [[♥-♥ "doublelove"]
|
(let [[♥-♥ "doublelove"]
|
||||||
[-_- "what?"]]
|
[-_- "what?"]]
|
||||||
(assert (= ♥-♥ "doublelove"))
|
(assert (= ♥-♥ "doublelove"))
|
||||||
(assert (= -_- "what?"))))
|
(assert (= -_- "what?"))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-and []
|
(defn test-and []
|
||||||
"NATIVE: test the and function"
|
"NATIVE: test the and function"
|
||||||
(let [[and123 (and 1 2 3)]
|
(let [[and123 (and 1 2 3)]
|
||||||
[and-false (and 1 False 3)]]
|
[and-false (and 1 False 3)]]
|
||||||
(assert (= and123 3))
|
(assert (= and123 3))
|
||||||
(assert (= and-false False))))
|
(assert (= and-false False))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-or []
|
(defn test-or []
|
||||||
@ -551,18 +547,18 @@
|
|||||||
(let [[or-all-true (or 1 2 3 True "string")]
|
(let [[or-all-true (or 1 2 3 True "string")]
|
||||||
[or-some-true (or False "hello")]
|
[or-some-true (or False "hello")]
|
||||||
[or-none-true (or False False)]]
|
[or-none-true (or False False)]]
|
||||||
(assert (= or-all-true 1))
|
(assert (= or-all-true 1))
|
||||||
(assert (= or-some-true "hello"))
|
(assert (= or-some-true "hello"))
|
||||||
(assert (= or-none-true False))))
|
(assert (= or-none-true False))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-if-return-branching []
|
(defn test-if-return-branching []
|
||||||
"NATIVE: test the if return branching"
|
"NATIVE: test the if return branching"
|
||||||
; thanks, algernon
|
; thanks, algernon
|
||||||
(assert (= 1 (let [[x 1]
|
(assert (= 1 (let [[x 1]
|
||||||
[y 2]]
|
[y 2]]
|
||||||
(if true
|
(if true
|
||||||
2)
|
2)
|
||||||
1)))
|
1)))
|
||||||
(assert (= 1 (let [[x 1] [y 2]]
|
(assert (= 1 (let [[x 1] [y 2]]
|
||||||
(do)
|
(do)
|
||||||
@ -587,10 +583,10 @@
|
|||||||
"NATIVE: test nested if"
|
"NATIVE: test nested if"
|
||||||
(for [x (range 10)]
|
(for [x (range 10)]
|
||||||
(if (in "foo" "foobar")
|
(if (in "foo" "foobar")
|
||||||
(do
|
(do
|
||||||
(if true true true))
|
(if true true true))
|
||||||
(do
|
(do
|
||||||
(if false false false)))))
|
(if false false false)))))
|
||||||
|
|
||||||
|
|
||||||
(defn test-eval []
|
(defn test-eval []
|
||||||
@ -601,9 +597,9 @@
|
|||||||
(setf test-payload (quote (+ x 2)))
|
(setf test-payload (quote (+ x 2)))
|
||||||
(setf x 4)
|
(setf x 4)
|
||||||
(assert (= 6 (eval test-payload)))
|
(assert (= 6 (eval test-payload)))
|
||||||
; (assert (= 6 (eval (quote ((fn [] (+ 3 3)))))))
|
;; (assert (= 6 (eval (quote ((fn [] (+ 3 3)))))))
|
||||||
; XXX: This must be commented out while we resolve stmts being run through
|
;; XXX: This must be commented out while we resolve stmts being run through
|
||||||
; eval. Please fix me. -- PRT
|
;; eval. Please fix me. -- PRT
|
||||||
(assert (= 1 (eval (quote 1))))
|
(assert (= 1 (eval (quote 1))))
|
||||||
(assert (= "foobar" (eval (quote "foobar"))))
|
(assert (= "foobar" (eval (quote "foobar"))))
|
||||||
(setv x (quote 42))
|
(setv x (quote 42))
|
||||||
@ -613,18 +609,18 @@
|
|||||||
(defn test-import-syntax []
|
(defn test-import-syntax []
|
||||||
"NATIVE: test the import syntax."
|
"NATIVE: test the import syntax."
|
||||||
|
|
||||||
; Simple import
|
;; Simple import
|
||||||
(import sys os)
|
(import sys os)
|
||||||
|
|
||||||
; from os.path import basename
|
;; from os.path import basename
|
||||||
(import [os.path [basename]])
|
(import [os.path [basename]])
|
||||||
(assert (= (basename "/some/path") "path"))
|
(assert (= (basename "/some/path") "path"))
|
||||||
|
|
||||||
; import os.path as p
|
;; import os.path as p
|
||||||
(import [os.path :as p])
|
(import [os.path :as p])
|
||||||
(assert (= p.basename basename))
|
(assert (= p.basename basename))
|
||||||
|
|
||||||
; from os.path import basename as bn
|
;; from os.path import basename as bn
|
||||||
(import [os.path [basename :as bn]])
|
(import [os.path [basename :as bn]])
|
||||||
(assert (= bn basename))
|
(assert (= bn basename))
|
||||||
|
|
||||||
|
@ -1,41 +1,37 @@
|
|||||||
; copyright ..
|
|
||||||
|
|
||||||
|
|
||||||
(setv square (fn [x]
|
(setv square (fn [x]
|
||||||
(* x x)))
|
(* x x)))
|
||||||
|
|
||||||
|
|
||||||
(setv test_basic_math (fn []
|
(setv test_basic_math (fn []
|
||||||
"NATIVE: Test basic math."
|
"NATIVE: Test basic math."
|
||||||
(assert (= (+ 2 2) 4))))
|
(assert (= (+ 2 2) 4))))
|
||||||
|
|
||||||
|
|
||||||
(setv test_mult (fn []
|
(setv test_mult (fn []
|
||||||
"NATIVE: Test multiplication."
|
"NATIVE: Test multiplication."
|
||||||
(assert (= 4 (square 2)))))
|
(assert (= 4 (square 2)))))
|
||||||
|
|
||||||
|
|
||||||
(setv test_sub (fn []
|
(setv test_sub (fn []
|
||||||
"NATIVE: Test subtraction"
|
"NATIVE: Test subtraction"
|
||||||
(assert (= 4 (- 8 4)))
|
(assert (= 4 (- 8 4)))
|
||||||
(assert (= -8 (- 8)))))
|
(assert (= -8 (- 8)))))
|
||||||
|
|
||||||
|
|
||||||
(setv test_add (fn []
|
(setv test_add (fn []
|
||||||
"NATIVE: Test addition"
|
"NATIVE: Test addition"
|
||||||
(assert (= 4 (+ 1 1 1 1)))))
|
(assert (= 4 (+ 1 1 1 1)))))
|
||||||
|
|
||||||
|
|
||||||
(setv test_div (fn []
|
(setv test_div (fn []
|
||||||
"NATIVE: Test division"
|
"NATIVE: Test division"
|
||||||
(assert (= 25 (/ 100 2 2)))
|
(assert (= 25 (/ 100 2 2)))
|
||||||
; Commented out until float constants get implemented
|
; Commented out until float constants get implemented
|
||||||
; (assert (= 0.5 (/ 1 2)))
|
; (assert (= 0.5 (/ 1 2)))
|
||||||
(assert (= 1 (* 2 (/ 1 2))))))
|
(assert (= 1 (* 2 (/ 1 2))))))
|
||||||
|
|
||||||
(setv test_int_div (fn []
|
(setv test_int_div (fn []
|
||||||
"NATIVE: Test integer division"
|
"NATIVE: Test integer division"
|
||||||
(assert (= 25 (// 101 2 2)))))
|
(assert (= 25 (// 101 2 2)))))
|
||||||
|
|
||||||
(defn test-modulo []
|
(defn test-modulo []
|
||||||
"NATIVE: test mod"
|
"NATIVE: test mod"
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
; This is a comment. It shall be ignored by the parser.
|
;; This is a comment. It shall be ignored by the parser.
|
||||||
|
|
||||||
|
|
||||||
(setv square (fn [x]
|
(setv square (fn [x]
|
||||||
(* x x)))
|
(* x x)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user