diff --git a/README.md b/README.md index 5876baa..c4b1b42 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ wt :-1: :-1: wl .. (wsplit :-1: toFloat 4 >) filter (wl) each # 7. Print the total number of fields in all input lines -# { nf = nf + $NF } +# { nf = nf + NF } # END { print nf } .. (wsplit len) map sum wl diff --git a/examples/awk/7.awk b/examples/awk/7.awk new file mode 100644 index 0000000..9be2e6d --- /dev/null +++ b/examples/awk/7.awk @@ -0,0 +1,2 @@ +{ nf = nf + NF } +END { print nf } diff --git a/examples/awk/7.msh b/examples/awk/7.msh new file mode 100644 index 0000000..502366c --- /dev/null +++ b/examples/awk/7.msh @@ -0,0 +1 @@ +.. (wsplit len) map sum wl diff --git a/examples/awk/test.sh b/examples/awk/test.sh index 44c11bd..c6eb9b5 100755 --- a/examples/awk/test.sh +++ b/examples/awk/test.sh @@ -32,5 +32,6 @@ else fi emp_test 6 +emp_test 7 exit "$FAIL" diff --git a/lib/std.msh b/lib/std.msh index f4c5488..82bdf9f 100644 --- a/lib/std.msh +++ b/lib/std.msh @@ -53,6 +53,26 @@ def filter drop drop @filter-accum end +# foldl (quote initial list -- result) +def foldl + # quote initial list + swap foldl-accum! # Accumulator, + # quote list + swap foldl-quote! # Quote + # list + ( + @foldl-accum swap # Accumulator item + @foldl-quote x # Execute quote + foldl-accum! # Update accumulator + ) each + + @foldl-accum +end + +# sum (list -- value) +def sum + (+) 0 rot foldl +end # .. (-- list[str]), equals kinda looks like lines. def .. stdin lines end diff --git a/mshell/Lexer.go b/mshell/Lexer.go index d7cdf31..12ab63d 100644 --- a/mshell/Lexer.go +++ b/mshell/Lexer.go @@ -181,7 +181,7 @@ func (t Token) ToJson() string { } func (t Token) DebugString() string { - return fmt.Sprintf("%d:%d: %s %s", t.Line, t.Column, t.Type, t.Lexeme) + return fmt.Sprintf("'%s'", t.Lexeme) } type Lexer struct { diff --git a/tests/sum.msh b/tests/sum.msh new file mode 100644 index 0000000..7b674c2 --- /dev/null +++ b/tests/sum.msh @@ -0,0 +1 @@ +[1 2 3 4] sum wl diff --git a/tests/sum.msh.stdout b/tests/sum.msh.stdout new file mode 100644 index 0000000..f599e28 --- /dev/null +++ b/tests/sum.msh.stdout @@ -0,0 +1 @@ +10