diff --git a/hy/core/language.hy b/hy/core/language.hy index 4df6ef4..20483ff 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -29,6 +29,7 @@ (import sys) (import [hy._compat [long-type]]) ; long for python2, int for python3 (import [hy.models.cons [HyCons]] + [hy.models.symbol [HySymbol]] [hy.models.keyword [HyKeyword *keyword-prefix*]]) (import [hy.lex [LexException PrematureEndOfInput tokenize]]) @@ -163,6 +164,10 @@ "Return True if x is float" (isinstance x float)) +(defn symbol? [s] + "Check whether s is a symbol" + (instance? HySymbol s)) + (import [threading [Lock]]) (setv _gensym_counter 1234) (setv _gensym_lock (Lock)) @@ -414,5 +419,5 @@ interpose iterable? iterate iterator? keyword keyword? list* macroexpand macroexpand-1 map merge-with name neg? nil? none? nth numeric? odd? pos? range read remove repeat repeatedly - rest reduce second some string string? take take-nth + rest reduce second some string string? symbol? take take-nth take-while zero? zip zip_longest zipwith]) diff --git a/tests/native_tests/core.hy b/tests/native_tests/core.hy index 2e92545..de5d8c7 100644 --- a/tests/native_tests/core.hy +++ b/tests/native_tests/core.hy @@ -233,6 +233,14 @@ (assert-true (float? -3.2)) (assert-false (float? "foo"))) +(defn test-symbol? [] + "NATIVE: testing the symbol? function" + (assert-false (symbol? "hello")) + (assert-false (symbol? [1 2 3])) + (assert-false (symbol? '[a b c])) + (assert-true (symbol? 'im-symbol)) + (assert-false (symbol? (name 'im-symbol)))) + (defn test-gensym [] "NATIVE: testing the gensym function" (import [hy.models.symbol [HySymbol]])