aboutsummaryrefslogtreecommitdiff
path: root/interpreter.py
diff options
context:
space:
mode:
authormryouse2022-06-06 00:47:21 +0000
committermryouse2022-06-06 00:47:21 +0000
commit0cbfbba377cfc0e88a87361b774c3f46ddfe12e5 (patch)
tree51b628e532e4fb0b84e99b6062c29cb16ec8d75a /interpreter.py
parent9e7e462a2b47342e1f1b10469fa4cba1b105c0bb (diff)
'split' without splitter turns into a char list
Diffstat (limited to 'interpreter.py')
-rw-r--r--interpreter.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/interpreter.py b/interpreter.py
index 74095ac..b3c5fcd 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -454,13 +454,15 @@ def interpretSplit(symbol, args, env):
target = evaluate(args[0], env)
if not isinstance(target, String):
raise InterpretPanic(symbol, "requires a :string as its first argument", target)
+ if len(args) == 1:
+ return List([String(char) for char in target.value], True)
splitter = evaluate(args[1], env)
if not isinstance(splitter, String):
raise InterpretPanic(symbol, "requires a :string as its second argument", splitter)
ret = target.value.split(splitter.value)
return List([String(r) for r in ret], True)
-GLOBALS.register("split", Builtin(interpretSplit, 2))
+GLOBALS.register("split", Builtin(interpretSplit, 1, 2))
# - get the length of a list
def interpretListLength(symbol, args, env):