Merge pull request #762 from larme/add-is-symbol-function

add `symbol?` function to `hy.core`
This commit is contained in:
Abhishek L 2015-01-29 23:06:11 +05:30
commit 31edaf6dee
4 changed files with 32 additions and 1 deletions

View File

@ -58,3 +58,4 @@
* Adam Schwalm <adamschwalm@gmail.com>
* Ilia Choly <ilia.choly@gmail.com>
* Shrayas Rajagopal <shrayasr@gmail.com>
* Shenyang Zhao <dev@zsy.im>

View File

@ -736,6 +736,23 @@ Returns ``True`` if *x* is a string.
=> (string? -2)
False
.. _symbol?-fn:
symbol?
-------
Usage: ``(symbol? x)``
Returns ``True`` if *x* is a symbol.
.. code-block:: hy
=> (symbol? 'foo)
True
=> (symbol? '[a b c])
False
.. _zero?-fn:
zero?

View File

@ -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])

View File

@ -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]])