Add number?, fn?, macro? in stepA - tests and process guide
authorDov Murik <dov.murik@gmail.com>
Mon, 9 Oct 2017 20:23:39 +0000 (20:23 +0000)
committerDov Murik <dov.murik@gmail.com>
Mon, 9 Oct 2017 20:23:39 +0000 (20:23 +0000)
Ref #298

process/guide.md
process/stepA_mal.txt
tests/stepA_mal.mal

index 554c145..455a76e 100644 (file)
@@ -1635,6 +1635,10 @@ For extra information read [Peter Seibel's thorough discussion about
     new vector is returned with the elements added to the end of the
     given vector.
   * `string?`: returns true if the parameter is a string.
+  * `number?`: returns true if the parameter is a number.
+  * `fn?`: returns true if the parameter is a function (internal or
+    user-defined).
+  * `macro?`: returns true if the parameter is a macro.
   * `seq`: takes a list, vector, string, or nil. If an empty list,
     empty vector, or empty string ("") is passed in then nil is
     returned. Otherwise, a list is returned unchanged, a vector is
index 431a4b9..f16d6e3 100644 (file)
@@ -87,6 +87,9 @@ ns = {'=:        equal?,
       'symbol?:  symbol?,
       'keyword:  keyword,
       'keyword?: keyword?,
+      'number?:  number?,
+      'fn?:      fn?,
+      'macro?:   macro?,
 
       'pr-str:   (a) -> a.map(|s| pr_str(e,true)).join(" ")),
       'str:      (a) -> a.map(|s| pr_str(e,false)).join("")),
index a349c09..5c458e1 100644 (file)
 (get @e "bar")
 ;=>(1 2 3)
 
+;; ------------------------------------------------------------------
+;; TODO move these to optional functionality after adding them to all
+;; implementations
+;;
+;; Testing string? function
+(number? 123)
+;=>true
+(number? -1)
+;=>true
+(number? nil)
+;=>false
+(number? false)
+;=>false
+(number? "123")
+;=>false
+
+;; Testing fn? function
+(fn? +)
+;=>true
+(fn? not)
+;=>true
+(fn? cond)
+;=>false
+(fn? "+")
+;=>false
+(fn? :+)
+;=>false
+
+;; Testing macro? function
+(macro? cond)
+;=>true
+(macro? +)
+;=>false
+(macro? not)
+;=>false
+(macro? "+")
+;=>false
+(macro? :+)
+;=>false
+
+;; ------------------------------------------------------------------
 
 ;>>> soft=True
 ;>>> optional=True