all repos — min @ ddf6b549da1735f56a02859a199d64e6cae2528c

A small but practical concatenative programming language.

Removed quote- symbols. Analyzing implications.
h3rald h3rald@h3rald.com
Sat, 30 Jan 2021 04:04:10 +0000
commit

ddf6b549da1735f56a02859a199d64e6cae2528c

parent

af16cda221940a787a8f9f745f8c2b4c877bc651

3 files changed, 88 insertions(+), 97 deletions(-)

jump to
M minpkg/lib/min_lang.nimminpkg/lib/min_lang.nim

@@ -458,10 +458,8 @@ let vals = i.expect("'sym", "a")

let sym = vals[0] var q1 = vals[1] # existing (auto-quoted) var symbol: string - var isQuot = true - if not q1.isQuotation: - q1 = @[q1].newVal - isQuot = false + var isQuot = q1.isQuotation + q1 = @[q1].newVal symbol = sym.getString when not defined(mini): if not symbol.match USER_SYMBOL_REGEX:

@@ -476,10 +474,8 @@ let vals = i.expect("'sym", "a")

let sym = vals[0] var q1 = vals[1] # existing (auto-quoted) var symbol: string - var isQuot = true - if not q1.isQuotation: - q1 = @[q1].newVal - isQuot = false + var isQuot = q1.isQuotation + q1 = @[q1].newVal symbol = sym.getString info "[bind] $1 = $2" % [symbol, $q1] let res = i.scope.setSymbol(symbol, MinOperator(kind: minValOp, val: q1, quotation: isQuot))

@@ -630,18 +626,6 @@ if sym.kind == minValOp:

i.push sym.val else: raiseInvalid("No source available for native symbol '$1'." % str) - - # def.symbol("call") do (i: In): - # let vals = i.expect("'sym", "dict") - # let symbol = vals[0] - # let q = vals[1] - # let s = symbol.getString - # let origScope = i.scope - # i.scope = q.scope - # i.scope.parent = origScope - # let sym = i.scope.getSymbol(s) - # i.apply(sym) - # i.scope = origScope def.symbol("invoke") do (i: In): let vals = i.expect("'sym")

@@ -919,21 +903,21 @@ raiseInvalid("Attempting to unseal system sigil: " & sym)

s.sealed = false i.scope.setSigil(sym, s, true) - def.symbol("quote-bind") do (i: In): - let vals = i.expect("str", "a") - let s = vals[0] - let m = vals[1] - i.push @[m].newVal - i.push s - i.pushSym "bind" + #def.symbol("quote-bind") do (i: In): + # let vals = i.expect("str", "a") + # let s = vals[0] + # let m = vals[1] + # i.push @[m].newVal + # i.push s + # i.pushSym "bind" - def.symbol("quote-define") do (i: In): - let vals = i.expect("str", "a") - let s = vals[0] - let m = vals[1] - i.push @[m].newVal - i.push s - i.pushSym "define" + #def.symbol("quote-define") do (i: In): + # let vals = i.expect("str", "a") + # let s = vals[0] + # let m = vals[1] + # i.push @[m].newVal + # i.push s + # i.pushSym "define" def.symbol("args") do (i: In):

@@ -1094,12 +1078,6 @@ i.pushSym("quote-define")

# Shorthand symbol aliases - def.symbol("#") do (i: In): - i.pushSym("quote-bind") - - def.symbol("=") do (i: In): - i.pushSym("quote-define") - def.symbol("=-=") do (i: In): i.pushSym("expect-empty-stack")
M tests/lang.mintests/lang.min

@@ -14,18 +14,18 @@ 5 :five

(symbols "five" in?) *test/assert ( - ((1 2 3 4 5 6)) :test-data + (1 2 3 4 5 6) :test-data ( :item "_$1" (item) => % :namesym - (item dup *) namesym define + item (dup *) cons namesym define namesym ROOT publish ) :def - test-data (def) foreach + test-data def foreach - _2 _5 _1 + + + _2 -> _5 -> _1 -> + + 30 == ) *test/assert

@@ -110,7 +110,13 @@ ('sym1 remove-symbol saved-symbols "sym1" in? false ==) *test/assert

(0 :temp (1 2 3) (temp + @temp) foreach 6 temp ==) *test/assert - ((1 +) :mysucc 'mysucc source (1 +) ==) *test/assert + ( + ( + symbol mysucc + (num :n ==> num :o) + (n 1 + @o) + ) :: + 'mysucc source (1 +) ==) *test/assert (6 (

@@ -297,7 +303,7 @@ (a type "num" ==)

(a b + @result return) when (a type "quot" ==) - (a b concat #result return) + (a b concat @result return) when ) ) ::
M tests/test.mintests/test.min

@@ -1,61 +1,68 @@

-;; test module "." :ok -(" " print!) :padding +( + symbol padding + (==>) + (" " print!) +) :: -;; *test/describe ( - :name - "Testing: [" print! name print! "]" puts! - padding - () -) :describe + symbol describe + ('sym :name ==> quot :out) + ( + "Testing: [" print! name print! "]" puts! + padding + () @out + ) +) :: -;; *test/assert ( - ' :check ; save the check quotation to validate - ' :results ; save the result symbol to update - ( + symbol assert + (quot :results quot :check ==> quot :out) + ( ( - (check -> true ==) - (format-error puts! false) - ) try - - ) - ( - ok results append quote @results - "." print! - ) - ( - check results append quote @results - "x" print! - ) - if - results -) :assert - -;; *test/report -( - newline - ' :results ; save the results collected so far - 0 :total - 0 :failed - results ( - total succ @total - (ok !=) (failed succ @failed) () if - ) map - "$# tests executed - $# failed." (total failed) =% puts! - ( - =result - result - (ok !=) + ( + (check -> true ==) + (format-error puts! false) + ) try + ) + ( + ok results append @results + "." print! + ) ( - ('failures defined-symbol?) (failures succ @failures) () if - padding "FAILED: " print! result puts! + check results append @results + "x" print! ) - () if - ) - map - pop ;Remove results accomulator from get-stack -) :report + results @out + ) +) :: + +( + symbol report + (quot :results ==>) + ( + newline + 0 :total + 0 :failed + results ( + total succ @total + (ok !=) (failed succ @failed) () if + ) map + "$# tests executed - $# failed." (total failed) =% puts! + ( + :result + result + (ok !=) + ( + ('failures defined-symbol?) (failures succ @failures) () if + padding "FAILED: " print! result puts! + ) + () + if + ) + map + pop ;Remove results accomulator from get-stack + ) +) ::