diff options
| author | mryouse | 2022-06-21 01:49:29 +0000 |
|---|---|---|
| committer | mryouse | 2022-06-21 01:49:29 +0000 |
| commit | 776fe3193b515c028b5ac69326baed51d760d32f (patch) | |
| tree | db111c3fe7a20143b2f058259f86dbbecae4cbd6 /neb/std/repl.py | |
| parent | b1550660adaca68bb38541aed371e36b7000e124 (diff) | |
refactor: break stdlib into several files
Diffstat (limited to 'neb/std/repl.py')
| -rw-r--r-- | neb/std/repl.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/neb/std/repl.py b/neb/std/repl.py new file mode 100644 index 0000000..48a7811 --- /dev/null +++ b/neb/std/repl.py @@ -0,0 +1,24 @@ +from .. import TypeEnum, Environment, Arg, Builtin, UserFunction, evaluate +from ..structs import * + +REPL = Environment() + +def interpretHowTo(symbol, args, env, ns): + if not isinstance(args[0], Function): + raise InterpretPanic(symbol, "expects a :func", args[0]) + print(args[0].describe()) + return List([]) + +REPL.register("howto", Builtin(interpretHowTo, [Arg("symbol", TypeEnum.ANY)])) + +def interpretSymbols(symbol, args, env, ns): + keys = [Symbol(k, -1) for k,v in env.environment.items()] + return List(keys) + +REPL.register("symbols", Builtin(interpretSymbols, [])) + +def interpretUserSymbols(symbol, args, env, ns): + keys = [Symbol(k, -1) for k,v in env.environment.items() if isinstance(v, UserFunction) or isinstance(v, Literal)] + return List(keys) + +REPL.register("user-symbols", Builtin(interpretUserSymbols, [])) |
