Burninate the synonyms true, false, and nil

Per the straw poll in #908, as an alternative to #1147.

Now you must use `True`, `False`, and `None`, as in Python. Or just assign `true` to `True`, etc.; the old synonyms aren't reserved words anymore.
This commit is contained in:
Kodi Arfer 2016-11-23 18:35:17 -08:00
parent f644dda0dd
commit ed8e37da62
23 changed files with 186 additions and 255 deletions

View File

@ -392,7 +392,7 @@ Some example usage:
.. code-block:: clj .. code-block:: clj
=> (if true => (if True
... (do (print "Side effects rock!") ... (do (print "Side effects rock!")
... (print "Yeah, really!"))) ... (print "Yeah, really!")))
Side effects rock! Side effects rock!
@ -589,7 +589,7 @@ Parameters may have the following keywords in front of them:
=> (apply compare ["lisp" "python"] => (apply compare ["lisp" "python"]
... {"keyfn" (fn [x y] ... {"keyfn" (fn [x y]
... (reduce - (map (fn [s] (ord (first s))) [x y]))) ... (reduce - (map (fn [s] (ord (first s))) [x y])))
... "reverse" true}) ... "reverse" True})
4 4
.. code-block:: python .. code-block:: python
@ -922,8 +922,8 @@ if / if* / if-not
if-not if-not
``if / if* / if-not`` respect Python *truthiness*, that is, a *test* fails if it ``if / if* / if-not`` respect Python *truthiness*, that is, a *test* fails if it
evaluates to a "zero" (including values of ``len`` zero, ``nil``, and evaluates to a "zero" (including values of ``len`` zero, ``None``, and
``false``), and passes otherwise, but values with a ``__bool__`` method ``False``), and passes otherwise, but values with a ``__bool__`` method
(``__nonzero__`` in Python 2) can overrides this. (``__nonzero__`` in Python 2) can overrides this.
The ``if`` macro is for conditionally selecting an expression for evaluation. The ``if`` macro is for conditionally selecting an expression for evaluation.
@ -931,7 +931,7 @@ The result of the selected expression becomes the result of the entire ``if``
form. ``if`` can select a group of expressions with the help of a ``do`` block. form. ``if`` can select a group of expressions with the help of a ``do`` block.
``if`` takes any number of alternating *test* and *then* expressions, plus an ``if`` takes any number of alternating *test* and *then* expressions, plus an
optional *else* expression at the end, which defaults to ``nil``. ``if`` checks optional *else* expression at the end, which defaults to ``None``. ``if`` checks
each *test* in turn, and selects the *then* corresponding to the first passed each *test* in turn, and selects the *then* corresponding to the first passed
test. ``if`` does not evaluate any expressions following its selection, similar test. ``if`` does not evaluate any expressions following its selection, similar
to the ``if/elif/else`` control structure from Python. If no tests pass, ``if`` to the ``if/elif/else`` control structure from Python. If no tests pass, ``if``
@ -944,7 +944,7 @@ generally no reason to use it directly.
``if-not`` is similar to ``if*`` but the second expression will be executed ``if-not`` is similar to ``if*`` but the second expression will be executed
when the condition fails while the third and final expression is executed when when the condition fails while the third and final expression is executed when
the test succeeds -- the opposite order of ``if*``. The final expression is the test succeeds -- the opposite order of ``if*``. The final expression is
again optional and defaults to ``nil``. again optional and defaults to ``None``.
Example usage: Example usage:
@ -974,7 +974,7 @@ lif and lif-not
lif-not lif-not
For those that prefer a more Lispy ``if`` clause, we have For those that prefer a more Lispy ``if`` clause, we have
``lif``. This *only* considers ``None`` / ``nil`` to be false! All other ``lif``. This *only* considers ``None`` to be false! All other
"false-ish" Python values are considered true. Conversely, we have "false-ish" Python values are considered true. Conversely, we have
``lif-not`` in parallel to ``if`` and ``if-not`` which ``lif-not`` in parallel to ``if`` and ``if-not`` which
reverses the comparison. reverses the comparison.
@ -988,12 +988,8 @@ reverses the comparison.
"true" "true"
=> (lif 0 "true" "false") => (lif 0 "true" "false")
"true" "true"
=> (lif nil "true" "false")
"false"
=> (lif None "true" "false") => (lif None "true" "false")
"false" "false"
=> (lif-not nil "true" "false")
"true"
=> (lif-not None "true" "false") => (lif-not None "true" "false")
"true" "true"
=> (lif-not False "true" "false") => (lif-not False "true" "false")

View File

@ -90,7 +90,7 @@ Checks whether *foo* is a :ref:`cons cell <hycons>`.
=> (cons? a) => (cons? a)
True True
=> (cons? nil) => (cons? None)
False False
=> (cons? [1 2 3]) => (cons? [1 2 3])
@ -137,7 +137,7 @@ is ``True``, the function prints Python code instead.
body=[ body=[
Expr(value=Call(func=Name(id='print'), args=[Str(s='Hello World!')], keywords=[], starargs=None, kwargs=None))]) Expr(value=Call(func=Name(id='print'), args=[Str(s='Hello World!')], keywords=[], starargs=None, kwargs=None))])
=> (disassemble '(print "Hello World!") true) => (disassemble '(print "Hello World!") True)
print('Hello World!') print('Hello World!')
@ -595,36 +595,6 @@ Returns ``True`` if *x* is less than zero. Raises ``TypeError`` if
=> (neg? 0) => (neg? 0)
False False
.. _nil?-fn:
nil?
----
Usage: ``(nil? x)``
Returns ``True`` if *x* is ``nil`` / ``None``.
.. code-block:: hy
=> (nil? nil)
True
=> (nil? None)
True
=> (nil? 0)
False
=> (setf x nil)
=> (nil? x)
True
=> ;; list.append always returns None
=> (nil? (.append [1 2 3] 4))
True
.. _none?-fn: .. _none?-fn:
none? none?
@ -656,10 +626,10 @@ Returns ``True`` if *x* is ``None``.
nth nth
--- ---
Usage: ``(nth coll n &optional [default nil])`` Usage: ``(nth coll n &optional [default None])``
Returns the *n*-th item in a collection, counting from 0. Return the Returns the *n*-th item in a collection, counting from 0. Return the
default value, ``nil``, if out of bounds (unless specified otherwise). default value, ``None``, if out of bounds (unless specified otherwise).
Raises ``ValueError`` if *n* is negative. Raises ``ValueError`` if *n* is negative.
.. code-block:: hy .. code-block:: hy
@ -670,7 +640,7 @@ Raises ``ValueError`` if *n* is negative.
=> (nth [1 2 4 7] 3) => (nth [1 2 4 7] 3)
7 7
=> (nil? (nth [1 2 4 7] 5)) => (none? (nth [1 2 4 7] 5))
True True
=> (nth [1 2 4 7] 5 "default") => (nth [1 2 4 7] 5 "default")
@ -807,23 +777,23 @@ some
Usage: ``(some pred coll)`` Usage: ``(some pred coll)``
Returns the first logically-true value of ``(pred x)`` for any ``x`` in Returns the first logically-true value of ``(pred x)`` for any ``x`` in
*coll*, otherwise ``nil``. Return ``nil`` if *coll* is empty. *coll*, otherwise ``None``. Return ``None`` if *coll* is empty.
.. code-block:: hy .. code-block:: hy
=> (some even? [2 4 6]) => (some even? [2 4 6])
True True
=> (nil? (some even? [1 3 5])) => (none? (some even? [1 3 5]))
True True
=> (nil? (some identity [0 "" []])) => (none? (some identity [0 "" []]))
True True
=> (some identity [0 "non-empty-string" []]) => (some identity [0 "non-empty-string" []])
'non-empty-string' 'non-empty-string'
=> (nil? (some even? [])) => (none? (some even? []))
True True
@ -898,12 +868,12 @@ as an example of how to use some of these functions.
(defn fib [] (defn fib []
(setv a 0) (setv a 0)
(setv b 1) (setv b 1)
(while true (while True
(yield a) (yield a)
(setv (, a b) (, b (+ a b))))) (setv (, a b) (, b (+ a b)))))
Note the ``(while true ...)`` loop. If we run this in the REPL, Note the ``(while True ...)`` loop. If we run this in the REPL,
.. code-block:: hy .. code-block:: hy
@ -1140,7 +1110,7 @@ if *from-file* ends before a complete expression can be parsed.
=> ; (print "hyfriends!") => ; (print "hyfriends!")
=> (with [f (open "example.hy")] => (with [f (open "example.hy")]
... (try ... (try
... (while true ... (while True
... (let [exp (read f)] ... (let [exp (read f)]
... (do ... (do
... (print "OHY" exp) ... (print "OHY" exp)

View File

@ -180,7 +180,7 @@ expressions are made of Python lists wrapped in a
``HyExpression``. However, the ``HyCons`` mimics the behavior of ``HyExpression``. However, the ``HyCons`` mimics the behavior of
"usual" Lisp variants thusly: "usual" Lisp variants thusly:
- ``(cons something nil)`` is ``(HyExpression [something])`` - ``(cons something None)`` is ``(HyExpression [something])``
- ``(cons something some-list)`` is ``((type some-list) (+ [something] - ``(cons something some-list)`` is ``((type some-list) (+ [something]
some-list))`` (if ``some-list`` inherits from ``list``). some-list))`` (if ``some-list`` inherits from ``list``).
- ``(get (cons a b) 0)`` is ``a`` - ``(get (cons a b) 0)`` is ``a``
@ -288,7 +288,7 @@ Second Stage Expression-Dispatch
The only special case is the ``HyExpression``, since we need to create different The only special case is the ``HyExpression``, since we need to create different
AST depending on the special form in question. For instance, when we hit an AST depending on the special form in question. For instance, when we hit an
``(if true true false)``, we need to generate a ``ast.If``, and properly ``(if True True False)``, we need to generate a ``ast.If``, and properly
compile the sub-nodes. This is where the ``@builds()`` with a String as an compile the sub-nodes. This is where the ``@builds()`` with a String as an
argument comes in. argument comes in.
@ -321,7 +321,7 @@ In Python, doing something like:
features, such as ``if``, ``for``, or ``while`` are statements. features, such as ``if``, ``for``, or ``while`` are statements.
Since they have no "value" to Python, this makes working in Hy hard, since Since they have no "value" to Python, this makes working in Hy hard, since
doing something like ``(print (if true true false))`` is not just common, it's doing something like ``(print (if True True False))`` is not just common, it's
expected. expected.
As a result, we auto-mangle things using a ``Result`` object, where we offer As a result, we auto-mangle things using a ``Result`` object, where we offer
@ -331,7 +331,7 @@ assignment to things while running.
As example, the Hy:: As example, the Hy::
(print (if true true false)) (print (if True True False))
Will turn into:: Will turn into::

View File

@ -138,13 +138,13 @@ Coding Style
(def *limit* 400000) (def *limit* 400000)
(defn fibs [a b] (defn fibs [a b]
(while true (while True
(yield a) (yield a)
(setv (, a b) (, b (+ a b))))) (setv (, a b) (, b (+ a b)))))
;; Bad (and not preferred) ;; Bad (and not preferred)
(defn fibs [a b] (defn fibs [a b]
(while true (while True
(yield a) (yield a)
(def (, a b) (, b (+ a b))))) (def (, a b) (, b (+ a b)))))

View File

@ -264,14 +264,14 @@ In Hy, you would do:
(print "That variable is too big!")] (print "That variable is too big!")]
[(< somevar 10) [(< somevar 10)
(print "That variable is too small!")] (print "That variable is too small!")]
[true [True
(print "That variable is jussssst right!")]) (print "That variable is jussssst right!")])
What you'll notice is that ``cond`` switches off between a statement What you'll notice is that ``cond`` switches off between a statement
that is executed and checked conditionally for true or falseness, and that is executed and checked conditionally for true or falseness, and
then a bit of code to execute if it turns out to be true. You'll also then a bit of code to execute if it turns out to be true. You'll also
notice that the ``else`` is implemented at the end simply by checking notice that the ``else`` is implemented at the end simply by checking
for ``true`` -- that's because ``true`` will always be true, so if we get for ``True`` -- that's because ``True`` will always be true, so if we get
this far, we'll always run that one! this far, we'll always run that one!
You might notice above that if you have code like: You might notice above that if you have code like:

View File

@ -82,8 +82,7 @@ def load_stdlib():
# are assignable in Python 2.* but become # are assignable in Python 2.* but become
# keywords in Python 3.* # keywords in Python 3.*
def _is_hy_builtin(name, module_name): def _is_hy_builtin(name, module_name):
extras = ['True', 'False', 'None', extras = ['True', 'False', 'None']
'true', 'false', 'nil']
if name in extras or keyword.iskeyword(name): if name in extras or keyword.iskeyword(name):
return True return True
# for non-Hy modules, check for pre-existing name in # for non-Hy modules, check for pre-existing name in

View File

@ -39,7 +39,7 @@
((type form) (outer (HyExpression (map inner form))))] ((type form) (outer (HyExpression (map inner form))))]
[(coll? form) [(coll? form)
(walk inner outer (list form))] (walk inner outer (list form))]
[true (outer form)])) [True (outer form)]))
(defn postwalk [f form] (defn postwalk [f form]
"Performs depth-first, post-order traversal of form. Calls f on each "Performs depth-first, post-order traversal of form. Calls f on each

View File

@ -64,7 +64,7 @@
"Decrement n by 1" "Decrement n by 1"
(- n 1)) (- n 1))
(defn disassemble [tree &optional [codegen false]] (defn disassemble [tree &optional [codegen False]]
"Return the python AST for a quoted Hy tree as a string. "Return the python AST for a quoted Hy tree as a string.
If the second argument is true, generate python code instead." If the second argument is true, generate python code instead."
(import astor) (import astor)
@ -151,7 +151,7 @@
(defn drop [count coll] (defn drop [count coll]
"Drop `count` elements from `coll` and yield back the rest" "Drop `count` elements from `coll` and yield back the rest"
(islice coll count nil)) (islice coll count None))
(defn drop-last [n coll] (defn drop-last [n coll]
"Return a sequence of all but the last n elements in coll." "Return a sequence of all but the last n elements in coll."
@ -225,7 +225,7 @@
(defn first [coll] (defn first [coll]
"Return first item from `coll`" "Return first item from `coll`"
(next (iter coll) nil)) (next (iter coll) None))
(defn identity [x] (defn identity [x]
"Returns the argument unchanged" "Returns the argument unchanged"
@ -250,8 +250,8 @@
"Return True if char `x` parses as an integer" "Return True if char `x` parses as an integer"
(try (try
(integer? (int x)) (integer? (int x))
(except [e ValueError] False) (except [ValueError] False)
(except [e TypeError] False))) (except [TypeError] False)))
(defn interleave [&rest seqs] (defn interleave [&rest seqs]
"Return an iterable of the first item in each of seqs, then the second etc." "Return an iterable of the first item in each of seqs, then the second etc."
@ -267,7 +267,7 @@
(defn iterate [f x] (defn iterate [f x]
(setv val x) (setv val x)
(while true (while True
(yield val) (yield val)
(setv val (f val)))) (setv val (f val))))
@ -324,17 +324,13 @@
"Return true if x is None" "Return true if x is None"
(is x None)) (is x None))
(defn nil? [x]
"Return true if x is nil (None)"
(is x None))
(defn numeric? [x] (defn numeric? [x]
(import numbers) (import numbers)
(instance? numbers.Number x)) (instance? numbers.Number x))
(defn nth [coll n &optional [default nil]] (defn nth [coll n &optional [default None]]
"Return nth item in collection or sequence, counting from 0. "Return nth item in collection or sequence, counting from 0.
Return nil if out of bounds unless specified otherwise." Return None if out of bounds unless specified otherwise."
(next (drop n coll) default)) (next (drop n coll) default))
(defn odd? [n] (defn odd? [n]
@ -348,7 +344,7 @@
more to skip elements, or less for a sliding window with overlap." more to skip elements, or less for a sliding window with overlap."
(setv (setv
step (or step n) step (or step n)
slices (genexpr (itertools.islice coll start nil step) [start (range n)])) slices (genexpr (itertools.islice coll start None step) [start (range n)]))
(if (is fillvalue -sentinel) (if (is fillvalue -sentinel)
(apply zip slices) (apply zip slices)
(apply zip-longest slices {"fillvalue" fillvalue}))) (apply zip-longest slices {"fillvalue" fillvalue})))
@ -363,7 +359,7 @@
(defn repeatedly [func] (defn repeatedly [func]
"Yield result of running func repeatedly" "Yield result of running func repeatedly"
(while true (while True
(yield (func)))) (yield (func))))
(defn second [coll] (defn second [coll]
@ -371,8 +367,8 @@
(nth coll 1)) (nth coll 1))
(defn some [pred coll] (defn some [pred coll]
"Return the first logical true value of (pred x) for any x in coll, else nil" "Return the first logical true value of (pred x) for any x in coll, else None"
(first (filter nil (map pred coll)))) (first (filter None (map pred coll))))
(defn string [x] (defn string [x]
"Cast x as current string implementation" "Cast x as current string implementation"
@ -389,7 +385,7 @@
(defn take [count coll] (defn take [count coll]
"Take `count` elements from `coll`, or the whole set if the total "Take `count` elements from `coll`, or the whole set if the total
number of entries in `coll` is less than `count`." number of entries in `coll` is less than `count`."
(islice coll nil count)) (islice coll None count))
(defn take-nth [n coll] (defn take-nth [n coll]
"Return every nth member of coll "Return every nth member of coll
@ -412,7 +408,7 @@
"Read from input and returns a tokenized string. "Read from input and returns a tokenized string.
Can take a given input buffer to read from" Can take a given input buffer to read from"
(def buff "") (def buff "")
(while true (while True
(def inn (str (.readline from-file))) (def inn (str (.readline from-file)))
(if (= inn eof) (if (= inn eof)
(raise (EOFError "Reached end of file" ))) (raise (EOFError "Reached end of file" )))
@ -465,6 +461,6 @@
group-by identity inc input instance? integer integer? integer-char? group-by identity inc input instance? integer integer? integer-char?
interleave interpose islice iterable? iterate iterator? keyword keyword? interleave interpose islice iterable? iterate iterator? keyword keyword?
last list* macroexpand macroexpand-1 map merge-with multicombinations name last list* macroexpand macroexpand-1 map merge-with multicombinations name
neg? nil? none? nth numeric? odd? partition permutations pos? product range neg? none? nth numeric? odd? partition permutations pos? product range
read read-str remove repeat repeatedly rest reduce second some string read read-str remove repeat repeatedly rest reduce second some string
string? symbol? take take-nth take-while xor tee zero? zip zip-longest]) string? symbol? take take-nth take-while xor tee zero? zip zip-longest])

View File

@ -78,7 +78,7 @@
(if baz (if baz
quux))" quux))"
(if (empty? branches) (if (empty? branches)
nil None
(do (do
(setv branches (iter branches)) (setv branches (iter branches))
(setv branch (next branches)) (setv branch (next branches))
@ -124,8 +124,8 @@
(macro-error None "`for' requires a body to evaluate")] (macro-error None "`for' requires a body to evaluate")]
[(empty? args) `(do ~@body ~@belse)] [(empty? args) `(do ~@body ~@belse)]
[(= (len args) 2) `(for* [~@args] (do ~@body) ~@belse)] [(= (len args) 2) `(for* [~@args] (do ~@body) ~@belse)]
[true [True
(let [alist (cut args 0 nil 2)] (let [alist (cut args 0 None 2)]
`(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] (do ~@body) ~@belse))])) `(for* [(, ~@alist) (genexpr (, ~@alist) [~@args])] (do ~@body) ~@belse))]))
@ -175,19 +175,19 @@
(defmacro lif [&rest args] (defmacro lif [&rest args]
"Like `if`, but anything that is not None/nil is considered true." "Like `if`, but anything that is not None is considered true."
(setv n (len args)) (setv n (len args))
(if* n (if* n
(if* (= n 1) (if* (= n 1)
(get args 0) (get args 0)
`(if* (is-not ~(get args 0) nil) `(if* (is-not ~(get args 0) None)
~(get args 1) ~(get args 1)
(lif ~@(cut args 2)))))) (lif ~@(cut args 2))))))
(defmacro lif-not [test not-branch &optional yes-branch] (defmacro lif-not [test not-branch &optional yes-branch]
"Like `if-not`, but anything that is not None/nil is considered true." "Like `if-not`, but anything that is not None is considered true."
`(if* (is ~test nil) ~not-branch ~yes-branch)) `(if* (is ~test None) ~not-branch ~yes-branch))
(defmacro when [test &rest body] (defmacro when [test &rest body]
@ -226,19 +226,19 @@
(defmacro/g! yield-from [expr] (defmacro/g! yield-from [expr]
`(do (import types) `(do (import types)
(setv ~g!iter (iter ~expr)) (setv ~g!iter (iter ~expr))
(setv ~g!return nil) (setv ~g!return None)
(setv ~g!message nil) (setv ~g!message None)
(while true (while True
(try (if (isinstance ~g!iter types.GeneratorType) (try (if (isinstance ~g!iter types.GeneratorType)
(setv ~g!message (yield (.send ~g!iter ~g!message))) (setv ~g!message (yield (.send ~g!iter ~g!message)))
(setv ~g!message (yield (next ~g!iter)))) (setv ~g!message (yield (next ~g!iter))))
(except [~g!e StopIteration] (except [~g!e StopIteration]
(do (setv ~g!return (if (hasattr ~g!e "value") (do (setv ~g!return (if (hasattr ~g!e "value")
(. ~g!e value) (. ~g!e value)
nil)) None))
(break))))) (break)))))
~g!return)) ~g!return))
nil) None)
(defmacro defmain [args &rest body] (defmacro defmain [args &rest body]
@ -254,6 +254,6 @@
(defreader @ [expr] (defreader @ [expr]
(let [decorators (cut expr nil -1) (let [decorators (cut expr None -1)
fndef (get expr -1)] fndef (get expr -1)]
`(with-decorator ~@decorators ~fndef))) `(with-decorator ~@decorators ~fndef)))

View File

@ -301,15 +301,6 @@ def t_identifier(p):
except ValueError: except ValueError:
pass pass
table = {
"true": "True",
"false": "False",
"nil": "None",
}
if obj in table:
return HySymbol(table[obj])
if obj.startswith(":"): if obj.startswith(":"):
return HyKeyword(obj) return HyKeyword(obj)

View File

@ -102,7 +102,7 @@ def test_ast_invalid_unary_op():
def test_ast_bad_while(): def test_ast_bad_while():
"Make sure AST can't compile invalid while" "Make sure AST can't compile invalid while"
cant_compile("(while)") cant_compile("(while)")
cant_compile("(while (true))") cant_compile("(while (True))")
def test_ast_good_do(): def test_ast_good_do():
@ -175,7 +175,7 @@ def test_ast_good_assert():
can_compile("(assert 1 \"Assert label\")") can_compile("(assert 1 \"Assert label\")")
can_compile("(assert 1 (+ \"spam \" \"eggs\"))") can_compile("(assert 1 (+ \"spam \" \"eggs\"))")
can_compile("(assert 1 12345)") can_compile("(assert 1 12345)")
can_compile("(assert 1 nil)") can_compile("(assert 1 None)")
can_compile("(assert 1 (+ 2 \"incoming eggsception\"))") can_compile("(assert 1 (+ 2 \"incoming eggsception\"))")
@ -337,7 +337,7 @@ def test_ast_valid_let():
"Make sure AST can compile valid let" "Make sure AST can compile valid let"
can_compile("(let [a b])") can_compile("(let [a b])")
can_compile("(let [a 1])") can_compile("(let [a 1])")
can_compile("(let [a 1 b nil])") can_compile("(let [a 1 b None])")
def test_ast_invalid_let(): def test_ast_invalid_let():
@ -571,7 +571,7 @@ def test_defn():
def test_setv_builtins(): def test_setv_builtins():
"""Ensure that assigning to a builtin fails, unless in a class""" """Ensure that assigning to a builtin fails, unless in a class"""
cant_compile("(setv nil 42)") cant_compile("(setv None 42)")
cant_compile("(defn get [&rest args] 42)") cant_compile("(defn get [&rest args] 42)")
can_compile("(defclass A [] (defn get [self] 42))") can_compile("(defclass A [] (defn get [self] 42))")
can_compile(""" can_compile("""

View File

@ -19,8 +19,8 @@
(defn t= [a b] (defn t= [a b]
(and (= a b) (= (type a) (type b)))) (and (= a b) (= (type a) (type b))))
(assert (t= (cons 1 2) '(1 . 2))) (assert (t= (cons 1 2) '(1 . 2)))
(assert (t= (cons 1 nil) '(1))) (assert (t= (cons 1 None) '(1)))
(assert (t= (cons nil 2) '(nil . 2))) (assert (t= (cons None 2) '(None . 2)))
(assert (t= (cons 1 []) [1])) (assert (t= (cons 1 []) [1]))
(setv tree (cons (cons 1 2) (cons 2 3))) (setv tree (cons (cons 1 2) (cons 2 3)))
(assert (t= (car tree) (cons 1 2))) (assert (t= (car tree) (cons 1 2)))
@ -52,7 +52,7 @@
(assert (cons? '(1 2 3 . 4))) (assert (cons? '(1 2 3 . 4)))
(assert (cons? (list* 1 2 3))) (assert (cons? (list* 1 2 3)))
(assert (not (cons? (cons 1 [2])))) (assert (not (cons? (cons 1 [2]))))
(assert (not (cons? (list* 1 nil))))) (assert (not (cons? (list* 1 None)))))
(defn test-list* [] (defn test-list* []

View File

@ -35,11 +35,11 @@
(defn test-ap-if [] (defn test-ap-if []
"NATIVE: testing anaphoric if" "NATIVE: testing anaphoric if"
(ap-if true (assert-true it)) (ap-if True (assert-true it))
(ap-if false true (assert-false it)) (ap-if False True (assert-false it))
(try (macroexpand '(ap-if true)) (try (macroexpand '(ap-if True))
(except [HyMacroExpansionError] true) (except [HyMacroExpansionError] True)
(else (assert false)))) (else (assert False))))
(defn test-ap-each [] (defn test-ap-each []
"NATIVE: testing anaphoric each" "NATIVE: testing anaphoric each"

View File

@ -19,15 +19,15 @@
(try (try
(setv n (non-tco-sum 100 10000)) (setv n (non-tco-sum 100 10000))
(except [e RuntimeError] (except [e RuntimeError]
(assert true)) (assert True))
(else (else
(assert false))) (assert False)))
;; tco-sum should not fail ;; tco-sum should not fail
(try (try
(setv n (tco-sum 100 10000)) (setv n (tco-sum 100 10000))
(except [e RuntimeError] (except [e RuntimeError]
(assert false)) (assert False))
(else (else
(assert (= n 10100))))) (assert (= n 10100)))))
@ -41,6 +41,6 @@
(try (try
(bad-recur 3) (bad-recur 3)
(except [e TypeError] (except [e TypeError]
(assert true)) (assert True))
(else (else
(assert false)))) (assert False))))

View File

@ -8,7 +8,7 @@
(defn collector [acc x] (defn collector [acc x]
(.append acc x) (.append acc x)
nil) None)
(defn test-walk-identity [] (defn test-walk-identity []
(assert (= (walk identity identity walk-form) (assert (= (walk identity identity walk-form)
@ -17,11 +17,11 @@
(defn test-walk [] (defn test-walk []
(let [acc '()] (let [acc '()]
(assert (= (walk (partial collector acc) identity walk-form) (assert (= (walk (partial collector acc) identity walk-form)
[nil nil])) [None None]))
(assert (= acc walk-form))) (assert (= acc walk-form)))
(let [acc []] (let [acc []]
(assert (= (walk identity (partial collector acc) walk-form) (assert (= (walk identity (partial collector acc) walk-form)
nil)) None))
(assert (= acc [walk-form])))) (assert (= acc [walk-form]))))
(defn test-walk-iterators [] (defn test-walk-iterators []

View File

@ -32,8 +32,8 @@
(defn assert-equal [x y] (defn assert-equal [x y]
(assert (= x y))) (assert (= x y)))
(defn assert-nil [x] (defn assert-none [x]
(assert (is x nil))) (assert (is x None)))
(defn assert-requires-num [f] (defn assert-requires-num [f]
(for [x ["foo" [] None]] (for [x ["foo" [] None]]
@ -130,7 +130,7 @@
(setv res (list (drop 0 [1 2 3 4 5]))) (setv res (list (drop 0 [1 2 3 4 5])))
(assert-equal res [1 2 3 4 5]) (assert-equal res [1 2 3 4 5])
(try (do (list (drop -1 [1 2 3 4 5])) (assert False)) (try (do (list (drop -1 [1 2 3 4 5])) (assert False))
(except [e [ValueError]] nil)) (except [e [ValueError]] None))
(setv res (list (drop 6 (iter [1 2 3 4 5])))) (setv res (list (drop 6 (iter [1 2 3 4 5]))))
(assert-equal res []) (assert-equal res [])
(setv res (list (take 5 (drop 2 (iterate inc 0))))) (setv res (list (take 5 (drop 2 (iterate inc 0)))))
@ -408,32 +408,23 @@
(assert-false (none? 0)) (assert-false (none? 0))
(assert-false (none? ""))) (assert-false (none? "")))
(defn test-nil? []
"NATIVE: testing for `is nil`"
(assert-true (nil? nil))
(assert-true (nil? None))
(setv f nil)
(assert-true (nil? f))
(assert-false (nil? 0))
(assert-false (nil? "")))
(defn test-nth [] (defn test-nth []
"NATIVE: testing the nth function" "NATIVE: testing the nth function"
(assert-equal 2 (nth [1 2 4 7] 1)) (assert-equal 2 (nth [1 2 4 7] 1))
(assert-equal 7 (nth [1 2 4 7] 3)) (assert-equal 7 (nth [1 2 4 7] 3))
(assert-nil (nth [1 2 4 7] 5)) (assert-none (nth [1 2 4 7] 5))
(assert-equal (nth [1 2 4 7] 5 "some default value") (assert-equal (nth [1 2 4 7] 5 "some default value")
"some default value") ; with default specified "some default value") ; with default specified
(try (do (nth [1 2 4 7] -1) (assert False)) (try (do (nth [1 2 4 7] -1) (assert False))
(except [e [ValueError]] nil)) (except [e [ValueError]] None))
;; now for iterators ;; now for iterators
(assert-equal 2 (nth (iter [1 2 4 7]) 1)) (assert-equal 2 (nth (iter [1 2 4 7]) 1))
(assert-equal 7 (nth (iter [1 2 4 7]) 3)) (assert-equal 7 (nth (iter [1 2 4 7]) 3))
(assert-nil (nth (iter [1 2 4 7]) 5)) (assert-none (nth (iter [1 2 4 7]) 5))
(assert-equal (nth (iter [1 2 4 7]) 5 "some default value") (assert-equal (nth (iter [1 2 4 7]) 5 "some default value")
"some default value") ; with default specified "some default value") ; with default specified
(try (do (nth (iter [1 2 4 7]) -1) (assert False)) (try (do (nth (iter [1 2 4 7]) -1) (assert False))
(except [e [ValueError]] nil)) (except [e [ValueError]] None))
(assert-equal 5 (nth (take 3 (drop 2 [1 2 3 4 5 6])) 2))) (assert-equal 5 (nth (take 3 (drop 2 [1 2 3 4 5 6])) 2)))
(defn test-numeric? [] (defn test-numeric? []
@ -518,16 +509,16 @@
(defn test-some [] (defn test-some []
"NATIVE: testing the some function" "NATIVE: testing the some function"
(assert-true (some even? [2 4 6])) (assert-true (some even? [2 4 6]))
(assert-nil (some even? [1 3 5])) (assert-none (some even? [1 3 5]))
(assert-true (some even? [1 2 3])) (assert-true (some even? [1 2 3]))
(assert-nil (some even? [])) (assert-none (some even? []))
; 0, "" (empty string) and [] (empty list) are all logical false ; 0, "" (empty string) and [] (empty list) are all logical false
(assert-nil (some identity [0 "" []])) (assert-none (some identity [0 "" []]))
; non-empty string is logical true ; non-empty string is logical true
(assert-equal (some identity [0 "this string is non-empty" []]) (assert-equal (some identity [0 "this string is non-empty" []])
"this string is non-empty") "this string is non-empty")
; nil if collection is empty ; None if collection is empty
(assert-nil (some even? []))) (assert-none (some even? [])))
(defn test-string? [] (defn test-string? []
"NATIVE: testing string?" "NATIVE: testing string?"
@ -546,7 +537,7 @@
(setv res (list (take 0 (repeat "s")))) (setv res (list (take 0 (repeat "s"))))
(assert-equal res []) (assert-equal res [])
(try (do (list (take -1 (repeat "s"))) (assert False)) (try (do (list (take -1 (repeat "s"))) (assert False))
(except [e [ValueError]] nil)) (except [e [ValueError]] None))
(setv res (list (take 6 [1 2 None 4]))) (setv res (list (take 6 [1 2 None 4])))
(assert-equal res [1 2 None 4])) (assert-equal res [1 2 None 4]))
@ -570,10 +561,10 @@
(setv res (list (take-nth 3 [1 2 3 None 5 6]))) (setv res (list (take-nth 3 [1 2 3 None 5 6])))
(assert-equal res [1 None]) (assert-equal res [1 None])
;; using 0 should raise ValueError ;; using 0 should raise ValueError
(let [passed false] (let [passed False]
(try (try
(setv res (list (take-nth 0 [1 2 3 4 5 6 7]))) (setv res (list (take-nth 0 [1 2 3 4 5 6 7])))
(except [ValueError] (setv passed true))) (except [ValueError] (setv passed True)))
(assert passed))) (assert passed)))
(defn test-take-while [] (defn test-take-while []
@ -606,7 +597,7 @@
(assert (not (keyword? "foo"))) (assert (not (keyword? "foo")))
(assert (not (keyword? ":foo"))) (assert (not (keyword? ":foo")))
(assert (not (keyword? 1))) (assert (not (keyword? 1)))
(assert (not (keyword? nil)))) (assert (not (keyword? None))))
(defn test-import-init-hy [] (defn test-import-init-hy []
"NATIVE: testing import of __init__.hy" "NATIVE: testing import of __init__.hy"

View File

@ -43,10 +43,10 @@
(defn test-defclass-dynamic-inheritance [] (defn test-defclass-dynamic-inheritance []
"NATIVE: test defclass with dynamic inheritance" "NATIVE: test defclass with dynamic inheritance"
(defclass A [((fn [] (if true list dict)))] (defclass A [((fn [] (if True list dict)))]
[x 42]) [x 42])
(assert (isinstance (A) list)) (assert (isinstance (A) list))
(defclass A [((fn [] (if false list dict)))] (defclass A [((fn [] (if False list dict)))]
[x 42]) [x 42])
(assert (isinstance (A) dict))) (assert (isinstance (A) dict)))
@ -58,7 +58,7 @@
(try (try
(do (do
(x) (x)
(assert false)) (assert False))
(except [NameError]))) (except [NameError])))
(defn test-defclass-docstring [] (defn test-defclass-docstring []
@ -110,8 +110,8 @@
(assert foo 2) (assert foo 2)
(assert (.greet a) "hello")) (assert (.greet a) "hello"))
(defn test-defclass-implicit-nil-for-init [] (defn test-defclass-implicit-none-for-init []
"NATIVE: test that defclass adds an implicit nil to --init--" "NATIVE: test that defclass adds an implicit None to --init--"
(defclass A [] (defclass A []
[--init-- (fn [self] (setv self.x 1) 42)]) [--init-- (fn [self] (setv self.x 1) 42)])
(defclass B [] (defclass B []

View File

@ -53,7 +53,7 @@
(defn test-setv-empty [] (defn test-setv-empty []
"NATIVE: test setv works with no arguments" "NATIVE: test setv works with no arguments"
(assert (is (setv) nil))) (assert (is (setv) None)))
(defn test-setv-get [] (defn test-setv-get []
@ -71,12 +71,6 @@
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e))))) (except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(setv None 1)) (try (eval '(setv None 1))
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e))))) (except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(setv false 1))
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(setv true 0))
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(setv nil 1))
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(defn defclass [] (print "hello"))) (try (eval '(defn defclass [] (print "hello")))
(except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e))))) (except [e [TypeError]] (assert (in "Can't assign to a builtin" (str e)))))
(try (eval '(defn get [] (print "hello"))) (try (eval '(defn get [] (print "hello")))
@ -101,28 +95,28 @@
(try (try
(do (do
(eval '(setv (do 1 2) 1)) (eval '(setv (do 1 2) 1))
(assert false)) (assert False))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "Can't assign or delete a non-expression")))) (assert (= e.message "Can't assign or delete a non-expression"))))
(try (try
(do (do
(eval '(setv 1 1)) (eval '(setv 1 1))
(assert false)) (assert False))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "Can't assign or delete a HyInteger")))) (assert (= e.message "Can't assign or delete a HyInteger"))))
(try (try
(do (do
(eval '(setv {1 2} 1)) (eval '(setv {1 2} 1))
(assert false)) (assert False))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "Can't assign or delete a HyDict")))) (assert (= e.message "Can't assign or delete a HyDict"))))
(try (try
(do (do
(eval '(del 1 1)) (eval '(del 1 1))
(assert false)) (assert False))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "Can't assign or delete a HyInteger"))))) (assert (= e.message "Can't assign or delete a HyInteger")))))
@ -224,8 +218,8 @@
(defn test-not [] (defn test-not []
"NATIVE: test not" "NATIVE: test not"
(assert (not (= 1 2))) (assert (not (= 1 2)))
(assert (= true (not false))) (assert (= True (not False)))
(assert (= false (not 42))) ) (assert (= False (not 42))) )
(defn test-inv [] (defn test-inv []
@ -266,22 +260,22 @@
(defn test-is [] (defn test-is []
"NATIVE: test is can deal with None" "NATIVE: test is can deal with None"
(setv a nil) (setv a None)
(assert (is a nil)) (assert (is a None))
(assert (is-not a "b")) (assert (is-not a "b"))
(assert (none? a))) (assert (none? a)))
(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))
@ -291,7 +285,7 @@
(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))
@ -303,9 +297,9 @@
(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 None None) (setv x true) (assert x)]) [(is None None) (setv x True) (assert x)])
(assert (= (cond) nil))) (assert (= (cond) None)))
(defn test-if [] (defn test-if []
@ -314,18 +308,18 @@
(assert (= 1 (if 1))) (assert (= 1 (if 1)))
(assert (= 1 (if 0 -1 (assert (= 1 (if 0 -1
1))) 1)))
;; with an even number of args, the default is nil ;; with an even number of args, the default is None
(assert (is nil (if))) (assert (is None (if)))
(assert (is nil (if 0 1))) (assert (is None (if 0 1)))
;; test deeper nesting ;; test deeper nesting
(assert (= 42 (assert (= 42
(if 0 0 (if 0 0
nil 1 None 1
"" 2 "" 2
1 42 1 42
1 43))) 1 43)))
;; test shortcutting ;; test shortcutting
(setv x nil) (setv x None)
(if 0 (setv x 0) (if 0 (setv x 0)
"" (setv x "") "" (setv x "")
42 (setv x 42) 42 (setv x 42)
@ -359,9 +353,9 @@
(defn test-imported-bits [] (defn test-imported-bits []
"NATIVE: test the imports work" "NATIVE: test the imports work"
(assert (is (exists ".") true)) (assert (is (exists ".") True))
(assert (is (isdir ".") true)) (assert (is (isdir ".") True))
(assert (is (isfile ".") false))) (assert (is (isfile ".") False)))
(defn test-kwargs [] (defn test-kwargs []
@ -432,7 +426,7 @@
(defn test-bare-try [] (try (defn test-bare-try [] (try
(try (raise ValueError)) (try (raise ValueError))
(except [ValueError]) (except [ValueError])
(else (assert false)))) (else (assert False))))
(defn test-exceptions [] (defn test-exceptions []
@ -449,70 +443,70 @@
(try (do) (except [IOError]) (except)) (try (do) (except [IOError]) (except))
;; 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))
;; Test (finally) + (raise) + (else) ;; Test (finally) + (raise) + (else)
(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))
(except [[IOError]] (assert false)) (except [[IOError]] (assert False))
(except [e [KeyError]] (assert e))) (except [e [KeyError]] (assert e)))
(try (try
(raise (KeyError)) (raise (KeyError))
(except [[IOError]] (assert false)) (except [[IOError]] (assert False))
(except [e [KeyError]] (assert e))) (except [e [KeyError]] (assert e)))
(try (try
(get [1] 3) (get [1] 3)
(except [IndexError] (assert true)) (except [IndexError] (assert True))
(except [IndexError] (do))) (except [IndexError] (do)))
(try (try
(print foobar42ofthebaz) (print foobar42ofthebaz)
(except [IndexError] (assert false)) (except [IndexError] (assert False))
(except [NameError] (do))) (except [NameError] (do)))
(try (try
@ -553,10 +547,10 @@
(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]
@ -648,7 +642,7 @@
(defn test-pass [] (defn test-pass []
"NATIVE: Test pass worksish" "NATIVE: Test pass worksish"
(if true (do) (do)) (if True (do) (do))
(assert (= 1 1))) (assert (= 1 1)))
@ -687,7 +681,7 @@
(defn test-first [] (defn test-first []
"NATIVE: test firsty things" "NATIVE: test firsty things"
(assert (= (first [1 2 3 4 5]) 1)) (assert (= (first [1 2 3 4 5]) 1))
(assert (is (first []) nil)) (assert (is (first []) None))
(assert (= (car [1 2 3 4 5]) 1))) (assert (= (car [1 2 3 4 5]) 1)))
@ -868,18 +862,18 @@
"NATIVE: test let works rightish" "NATIVE: test let works rightish"
;; TODO: test sad paths for let ;; TODO: test sad paths for let
(assert (= (let [x 1 y 2 z 3] (+ x y z)) 6)) (assert (= (let [x 1 y 2 z 3] (+ x y z)) 6))
(assert (= (let [x 1 a nil y 2 b nil] (if a 1 2)) 2)) (assert (= (let [x 1 a None y 2 b None] (if a 1 2)) 2))
(assert (= (let [x nil] x) nil)) (assert (= (let [x None] x) None))
(assert (= (let [x "x not bound"] (setv x "x bound by setv") x) (assert (= (let [x "x not bound"] (setv x "x bound by setv") x)
"x bound by setv")) "x bound by setv"))
(assert (= (let [x "let nests scope correctly"] (assert (= (let [x "let nests scope correctly"]
(let [y nil] x)) (let [y None] x))
"let nests scope correctly")) "let nests scope correctly"))
(assert (= (let [x 999999] (assert (= (let [x 999999]
(let [x "x being rebound"] x)) (let [x "x being rebound"] x))
"x being rebound")) "x being rebound"))
(assert (= (let [x "x not being rebound"] (assert (= (let [x "x not being rebound"]
(let [x 2] nil) (let [x 2] None)
x) x)
"x not being rebound")) "x not being rebound"))
(assert (= (let [x (set [3 2 1 3 2]) y x z y] z) (set [1 2 3]))) (assert (= (let [x (set [3 2 1 3 2]) y x z y] z) (set [1 2 3])))
@ -897,7 +891,7 @@
(defn test-if-mangler [] (defn test-if-mangler []
"NATIVE: test that we return ifs" "NATIVE: test that we return ifs"
(assert (= true (if true true true)))) (assert (= True (if True True True))))
(defn test-nested-mangles [] (defn test-nested-mangles []
@ -966,7 +960,7 @@
(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))
(assert (= or-false nil)) (assert (= or-false None))
(assert (= or-single 1))) (assert (= or-single 1)))
; short circuiting ; short circuiting
(setv a 1) (setv a 1)
@ -976,19 +970,19 @@
(defn test-xor [] (defn test-xor []
"NATIVE: test the xor macro" "NATIVE: test the xor macro"
(let [xor-both-true (xor true true) (let [xor-both-true (xor True True)
xor-both-false (xor false false) xor-both-false (xor False False)
xor-true-false (xor true false)] xor-true-false (xor True False)]
(assert (= xor-both-true false)) (assert (= xor-both-true False))
(assert (= xor-both-false false)) (assert (= xor-both-false False))
(assert (= xor-true-false true)))) (assert (= xor-true-false True))))
(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]
@ -1015,9 +1009,9 @@
(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 []
@ -1057,8 +1051,8 @@
; yo dawg ; yo dawg
(try (eval '(eval)) (except [e HyTypeError]) (else (assert False))) (try (eval '(eval)) (except [e HyTypeError]) (else (assert False)))
(try (eval '(eval "snafu")) (except [e HyTypeError]) (else (assert False))) (try (eval '(eval "snafu")) (except [e HyTypeError]) (else (assert False)))
(try (eval 'false []) (except [e HyTypeError]) (else (assert False))) (try (eval 'False []) (except [e HyTypeError]) (else (assert False)))
(try (eval 'false {} 1) (except [e HyTypeError]) (else (assert False)))) (try (eval 'False {} 1) (except [e HyTypeError]) (else (assert False))))
(defn test-import-syntax [] (defn test-import-syntax []
@ -1122,7 +1116,7 @@
(defn test-if-let-mixing [] (defn test-if-let-mixing []
"NATIVE: test that we can now mix if and let" "NATIVE: test that we can now mix if and let"
(assert (= 0 (if true (let [x 0] x) 42)))) (assert (= 0 (if True (let [x 0] x) 42))))
(defn test-if-in-if [] (defn test-if-in-if []
"NATIVE: test that we can use if in if" "NATIVE: test that we can use if in if"
@ -1261,7 +1255,7 @@
(assert (= test [0 1 2 3])) (assert (= test [0 1 2 3]))
(del (get test 2)) (del (get test 2))
(assert (= test [0 1 3])) (assert (= test [0 1 3]))
(assert (= (del) nil))) (assert (= (del) None)))
(defn test-macroexpand [] (defn test-macroexpand []
@ -1279,7 +1273,7 @@
(defn test-merge-with [] (defn test-merge-with []
"NATIVE: test merge-with" "NATIVE: test merge-with"
(assert (= (merge-with + {} {}) nil)) (assert (= (merge-with + {} {}) None))
(assert (= (merge-with + {"a" 10 "b" 20} {}) {"a" 10 "b" 20})) (assert (= (merge-with + {"a" 10 "b" 20} {}) {"a" 10 "b" 20}))
(assert (= (merge-with + {} {"a" 10 "b" 20}) {"a" 10 "b" 20})) (assert (= (merge-with + {} {"a" 10 "b" 20}) {"a" 10 "b" 20}))
(assert (= (merge-with + {"a" 10 "b" 20} {"a" 1 "c" 30}) (assert (= (merge-with + {"a" 10 "b" 20} {"a" 1 "c" 30})
@ -1309,7 +1303,7 @@
"Module(\n body=[Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[])),\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[])),\n Expr(value=Call(func=Name(id='macros'), args=[], keywords=[]))])")) "Module(\n body=[Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[])),\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[])),\n Expr(value=Call(func=Name(id='macros'), args=[], keywords=[]))])"))
(assert (= (disassemble '(do (leaky) (leaky) (macros))) (assert (= (disassemble '(do (leaky) (leaky) (macros)))
"Module(\n body=[\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[], starargs=None, kwargs=None)),\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[], starargs=None, kwargs=None)),\n Expr(value=Call(func=Name(id='macros'), args=[], keywords=[], starargs=None, kwargs=None))])"))) "Module(\n body=[\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[], starargs=None, kwargs=None)),\n Expr(value=Call(func=Name(id='leaky'), args=[], keywords=[], starargs=None, kwargs=None)),\n Expr(value=Call(func=Name(id='macros'), args=[], keywords=[], starargs=None, kwargs=None))])")))
(assert (= (disassemble '(do (leaky) (leaky) (macros)) true) (assert (= (disassemble '(do (leaky) (leaky) (macros)) True)
"leaky()\nleaky()\nmacros()"))) "leaky()\nleaky()\nmacros()")))

View File

@ -59,19 +59,19 @@
(eval '(defmacro f [&kwonly a b])) (eval '(defmacro f [&kwonly a b]))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "macros cannot use &kwonly"))) (assert (= e.message "macros cannot use &kwonly")))
(else (assert false))) (else (assert False)))
(try (try
(eval '(defmacro f [&kwargs kw])) (eval '(defmacro f [&kwargs kw]))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "macros cannot use &kwargs"))) (assert (= e.message "macros cannot use &kwargs")))
(else (assert false))) (else (assert False)))
(try (try
(eval '(defmacro f [&key {"kw" "xyz"}])) (eval '(defmacro f [&key {"kw" "xyz"}]))
(except [e HyTypeError] (except [e HyTypeError]
(assert (= e.message "macros cannot use &key"))) (assert (= e.message "macros cannot use &key")))
(else (assert false)))) (else (assert False))))
(defn test-fn-calling-macro [] (defn test-fn-calling-macro []
"NATIVE: test macro calling a plain function" "NATIVE: test macro calling a plain function"
@ -208,16 +208,15 @@
:no)) :no))
(assert (= (if-not False :yes :no) (assert (= (if-not False :yes :no)
:yes)) :yes))
(assert (nil? (if-not True :yes))) (assert (none? (if-not True :yes)))
(assert (= (if-not False :yes) (assert (= (if-not False :yes)
:yes))) :yes)))
(defn test-lif [] (defn test-lif []
"test that lif works as expected" "test that lif works as expected"
;; nil is false ;; None is false
(assert (= (lif None "true" "false") "false")) (assert (= (lif None "true" "false") "false"))
(assert (= (lif nil "true" "false") "false"))
;; But everything else is True! Even falsey things. ;; But everything else is True! Even falsey things.
(assert (= (lif True "true" "false") "true")) (assert (= (lif True "true" "false") "true"))
@ -226,21 +225,20 @@
(assert (= (lif "some-string" "true" "false") "true")) (assert (= (lif "some-string" "true" "false") "true"))
(assert (= (lif "" "true" "false") "true")) (assert (= (lif "" "true" "false") "true"))
(assert (= (lif (+ 1 2 3) "true" "false") "true")) (assert (= (lif (+ 1 2 3) "true" "false") "true"))
(assert (= (lif nil "true" "false") "false")) (assert (= (lif None "true" "false") "false"))
(assert (= (lif 0 "true" "false") "true")) (assert (= (lif 0 "true" "false") "true"))
;; Test ellif [sic] ;; Test ellif [sic]
(assert (= (lif nil 0 (assert (= (lif None 0
nil 1 None 1
0 2 0 2
3) 3)
2))) 2)))
(defn test-lif-not [] (defn test-lif-not []
"test that lif-not works as expected" "test that lif-not works as expected"
; nil is false ; None is false
(assert (= (lif-not None "false" "true") "false")) (assert (= (lif-not None "false" "true") "false"))
(assert (= (lif-not nil "false" "true") "false"))
; But everything else is True! Even falsey things. ; But everything else is True! Even falsey things.
(assert (= (lif-not True "false" "true") "true")) (assert (= (lif-not True "false" "true") "true"))
@ -249,7 +247,7 @@
(assert (= (lif-not "some-string" "false" "true") "true")) (assert (= (lif-not "some-string" "false" "true") "true"))
(assert (= (lif-not "" "false" "true") "true")) (assert (= (lif-not "" "false" "true") "true"))
(assert (= (lif-not (+ 1 2 3) "false" "true") "true")) (assert (= (lif-not (+ 1 2 3) "false" "true") "true"))
(assert (= (lif-not nil "false" "true") "false")) (assert (= (lif-not None "false" "true") "false"))
(assert (= (lif-not 0 "false" "true") "true"))) (assert (= (lif-not 0 "false" "true") "true")))

View File

@ -15,9 +15,9 @@
(defn test-kwonly [] (defn test-kwonly []
"NATIVE: test keyword-only arguments" "NATIVE: test keyword-only arguments"
;; keyword-only with default works ;; keyword-only with default works
(let [kwonly-foo-default-false (fn [&kwonly [foo false]] foo)] (let [kwonly-foo-default-false (fn [&kwonly [foo False]] foo)]
(assert (= (apply kwonly-foo-default-false) false)) (assert (= (apply kwonly-foo-default-false) False))
(assert (= (apply kwonly-foo-default-false [] {"foo" true}) true))) (assert (= (apply kwonly-foo-default-false [] {"foo" True}) True)))
;; keyword-only without default ... ;; keyword-only without default ...
(let [kwonly-foo-no-default (fn [&kwonly foo] foo) (let [kwonly-foo-no-default (fn [&kwonly foo] foo)
attempt-to-omit-default (try attempt-to-omit-default (try

View File

@ -10,9 +10,9 @@
(defn test-quoted-hoistable [] (defn test-quoted-hoistable []
"NATIVE: check whether quote works on hoisted things" "NATIVE: check whether quote works on hoisted things"
(setv f (quote (if true true true))) (setv f (quote (if True True True)))
(assert (= (car f) (quote if))) (assert (= (car f) (quote if)))
(assert (= (cdr f) (quote (true true true))))) (assert (= (cdr f) (quote (True True True)))))
(defn test-quoted-macroexpand [] (defn test-quoted-macroexpand []

View File

@ -1,10 +1,8 @@
(defn test-unless [] (defn test-unless []
"NATIVE: test unless" "NATIVE: test unless"
(assert (= (unless false 1) 1)) (assert (= (unless False 1) 1))
(assert (= (unless false 1 2) 2)) (assert (= (unless False 1 2) 2))
(assert (= (unless false 1 3) 3)) (assert (= (unless False 1 3) 3))
(assert (= (unless true 2) None)) (assert (= (unless True 2) None))
(assert (= (unless true 2) nil))
(assert (= (unless (!= 1 2) 42) None)) (assert (= (unless (!= 1 2) 42) None))
(assert (= (unless (!= 1 2) 42) nil))
(assert (= (unless (!= 2 2) 42) 42))) (assert (= (unless (!= 2 2) 42) 42)))

View File

@ -1,10 +1,8 @@
(defn test-when [] (defn test-when []
"NATIVE: test when" "NATIVE: test when"
(assert (= (when true 1) 1)) (assert (= (when True 1) 1))
(assert (= (when true 1 2) 2)) (assert (= (when True 1 2) 2))
(assert (= (when true 1 3) 3)) (assert (= (when True 1 3) 3))
(assert (= (when false 2) None)) (assert (= (when False 2) None))
(assert (= (when (= 1 2) 42) None)) (assert (= (when (= 1 2) 42) None))
(assert (= (when false 2) nil))
(assert (= (when (= 1 2) 42) nil))
(assert (= (when (= 2 2) 42) 42))) (assert (= (when (= 2 2) 42) 42)))