all repos — min @ 153dfd58457bdba6d9d845900242f0f9cc783080

A small but practical concatenative programming language.

Simplified REPL when printing results (fixes #54)
h3rald h3rald@h3rald.com
Sun, 02 Feb 2020 13:54:47 +0100
commit

153dfd58457bdba6d9d845900242f0f9cc783080

parent

da5244f4297b0d41b633a55a3109d180dc39e07e

3 files changed, 17 insertions(+), 14 deletions(-)

jump to
M core/parser.nimcore/parser.nim

@@ -627,7 +627,6 @@ var c = 0

while p.token != tkBraceRi: c = c+1 let v = p.parseMinValue(i) - echo(c mod 2) if val.isNil: val = v elif v.kind == minSymbol:
M min.nimmin.nim

@@ -221,26 +221,26 @@ return

if i.stack.len > 0: let n = $i.stack.len if res.isQuotation and res.qVal.len > 1: - echo "{$1} -> (" % n + echo " (" for item in res.qVal: - echo " " & $item - echo " ".repeat(n.len) & " )" + echo " " & $item + echo " ".repeat(n.len) & ")" elif res.isDictionary and res.dVal.len > 1: - echo "{$1} -> {" % n + echo " {" for item in res.dVal.pairs: var v = "" if item.val.kind == minProcOp: v = "<native>" else: v = $item.val.val - echo " " & v & " :" & $item.key + echo " " & v & " :" & $item.key if res.objType == "": - echo " ".repeat(n.len) & " }" + echo " ".repeat(n.len) & "}" else: - echo " ".repeat(n.len) & " ;" & res.objType - echo " ".repeat(n.len) & " }" + echo " ".repeat(n.len) & " ;" & res.objType + echo " ".repeat(n.len) & "}" else: - echo "[$1] -> $2" % [$i.stack.len, $i.stack[i.stack.len - 1]] + echo " $1" % [$i.stack[i.stack.len - 1]] proc minRepl*(i: var MinInterpreter, simple = false) = i.stdLib()

@@ -257,7 +257,9 @@ let v = vals[0]

let prompt = v.getString() stdout.write(prompt) line = stdin.readLine() - i.printResult i.interpret($line) + let r = i.interpret($line) + if $line != "": + i.printResult(r) else: while true: let symbols = toSeq(i.scope.symbols.keys)

@@ -269,7 +271,9 @@ let vals = i.expect("string")

let v = vals[0] let prompt = v.getString() line = ed.readLine(prompt) - i.printResult i.interpret($line) + let r = i.interpret($line) + if $line != "": + i.printResult(r) proc minRepl*(simple = false) = var i = newMinInterpreter(filename = "<repl>")
M site/contents/download.mdsite/contents/download.md

@@ -54,14 +54,14 @@ You can type min code and press [ENTER](class:kbd) to evaluate it immediately:

> %min-terminal% > [[/Users/h3rald/test]$](class:prompt) 2 2 + -> {1} -> 4 +> 4 > [[/Users/h3rald/test]$](class:prompt) The result of each operation will be placed on top of the stack, and it will be available to subsequent operation > %min-terminal% > [[/Users/h3rald/test]$](class:prompt) dup * -> {1} -> 16 +> 16 > [[/Users/h3rald/test]$](class:prompt) To exit min shell, press [CTRL+C](class:kbd) or type [0 exit](class:cmd) and press [ENTER](class:kbd).