From 55a7ab1667583d95a514e33a5df62c376078c2f5 Mon Sep 17 00:00:00 2001 From: Bob Tolbert Date: Fri, 27 Dec 2013 13:50:19 -0700 Subject: [PATCH] add nil as synonym for None --- hy/lex/parser.py | 1 + tests/native_tests/language.hy | 7 ++++--- tests/native_tests/unless.hy | 2 ++ tests/native_tests/when.hy | 2 ++ 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/hy/lex/parser.py b/hy/lex/parser.py index 70d43f8..9e11069 100644 --- a/hy/lex/parser.py +++ b/hy/lex/parser.py @@ -229,6 +229,7 @@ def t_identifier(p): table = { "true": "True", "false": "False", + "nil": "None", "null": "None", } diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index 4efe768..ec110ae 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -86,9 +86,10 @@ (defn test-is [] "NATIVE: test is can deal with None" - (setv a null) - (assert (is a null)) - (assert (is-not a "b"))) + (setv a nil) + (assert (is a nil)) + (assert (is-not a "b")) + (assert (none? a))) (defn test-branching [] diff --git a/tests/native_tests/unless.hy b/tests/native_tests/unless.hy index f8c298a..2b957fe 100644 --- a/tests/native_tests/unless.hy +++ b/tests/native_tests/unless.hy @@ -4,5 +4,7 @@ (assert (= (unless false 1 2) 2)) (assert (= (unless false 1 3) 3)) (assert (= (unless true 2) null)) + (assert (= (unless true 2) nil)) (assert (= (unless (!= 1 2) 42) null)) + (assert (= (unless (!= 1 2) 42) nil)) (assert (= (unless (!= 2 2) 42) 42))) diff --git a/tests/native_tests/when.hy b/tests/native_tests/when.hy index 1409b3b..c281439 100644 --- a/tests/native_tests/when.hy +++ b/tests/native_tests/when.hy @@ -5,4 +5,6 @@ (assert (= (when true 1 3) 3)) (assert (= (when false 2) null)) (assert (= (when (= 1 2) 42) null)) + (assert (= (when false 2) nil)) + (assert (= (when (= 1 2) 42) nil)) (assert (= (when (= 2 2) 42) 42)))