aboutsummaryrefslogtreecommitdiff
path: root/interpreter.py
diff options
context:
space:
mode:
authormryouse2022-05-23 01:03:44 +0000
committermryouse2022-05-23 01:03:44 +0000
commit28877d03e9e8b0545ba4c7a07a0f4bf644562049 (patch)
treec492c591431a9fed99b13c34cad8e712b1839dfe /interpreter.py
parent8fa2ede632127492bc207ab7fd0dbce9cd19c7c3 (diff)
implement split
Diffstat (limited to 'interpreter.py')
-rw-r--r--interpreter.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/interpreter.py b/interpreter.py
index c491150..0905368 100644
--- a/interpreter.py
+++ b/interpreter.py
@@ -356,6 +356,17 @@ GLOBALS.register("strip", Builtin(interpretStrip, 1))
# - string->int and string->float
# - split a string by a given field
+def interpretSplit(symbol, args, env):
+ target = evaluate(args[0], env)
+ if not isinstance(target, str):
+ raise Exception("'split' expects a string")
+ splitter = evaluate(args[1], env)
+ if not isinstance(splitter, str):
+ raise Exception("'split' expects a string as it's splitter")
+ return List(target.split(splitter))
+
+GLOBALS.register("split", Builtin(interpretSplit, 2))
+
# - get the length of a list
def interpretListLength(symbol, args, env):
ev = evaluate(args[0], env)
@@ -397,7 +408,7 @@ def interpretMap(symbol, args, env):
out = []
for arg in lst.args:
ev = evaluate(List([func, arg]), env)
- out.append(ev)
+ out.append(Literal(ev)) # TODO this is probably wrong
return List(out)
GLOBALS.register("map", Builtin(interpretMap, 2))