ps, python: fix keyword? on empty string.
authorJoel Martin <github@martintribe.org>
Mon, 15 Feb 2016 15:30:16 +0000 (09:30 -0600)
committerJoel Martin <github@martintribe.org>
Mon, 15 Feb 2016 15:30:16 +0000 (09:30 -0600)
Issue #166.

ps/types.ps
python/mal_types.py
python/printer.py

index 3f1d13c..871817c 100644 (file)
@@ -204,7 +204,7 @@ end } def
 /_false? { false eq } def
 /_string? {
     dup type /stringtype eq {
-        dup length 0 eq { % length > 0
+        dup length 0 eq { % if length == 0
             pop true
         }{
             0 get 127 eq not
@@ -237,7 +237,11 @@ end } def
 
 /_keyword? {
     dup type /stringtype eq {
-        0 get 127 eq
+        dup length 0 eq { % if length == 0
+            pop false
+        }{
+            0 get 127 eq
+        } ifelse
     }{
         pop false
     } ifelse
index cf1ca0f..047426f 100644 (file)
@@ -63,7 +63,11 @@ def _clone(obj):
 def _nil_Q(exp):    return exp is None
 def _true_Q(exp):   return exp is True
 def _false_Q(exp):  return exp is False
-def _string_Q(exp): return type(exp) in str_types
+def _string_Q(exp):
+    if type(exp) in str_types:
+        return len(exp) == 0 or exp[0] != _u("\u029e")
+    else:
+        return False
 
 # Symbols
 class Symbol(str): pass
@@ -74,9 +78,12 @@ def _symbol_Q(exp): return type(exp) == Symbol
 # A specially prefixed string
 def _keyword(str):
     if str[0] == _u("\u029e"): return str
-    else:                     return _u("\u029e") + str
+    else:                      return _u("\u029e") + str
 def _keyword_Q(exp):
-    return _string_Q(exp) and exp[0] == _u("\u029e")
+    if type(exp) in str_types:
+        return len(exp) != 0 and exp[0] == _u("\u029e")
+    else:
+        return False
 
 # Functions
 def _function(Eval, Env, ast, env, params):
index a2837bd..32d2708 100644 (file)
@@ -14,7 +14,7 @@ def _pr_str(obj, print_readably=True):
         for k in obj.keys():
             ret.extend((_pr_str(k), _pr_str(obj[k],_r)))
         return "{" + " ".join(ret) + "}"
-    elif types._string_Q(obj):
+    elif type(obj) in types.str_types:
         if len(obj) > 0 and obj[0] == types._u('\u029e'):
             return ':' + obj[1:]
         elif print_readably: