all repos — min @ 21b97963819fff18bb36b4e4e0fafe8041358e09

A small but practical concatenative programming language.

Changed behavior of dpairs symbol.
h3rald h3rald@h3rald.com
Fri, 01 Dec 2023 10:03:30 +0100
commit

21b97963819fff18bb36b4e4e0fafe8041358e09

parent

7ee8a5d8c5bce43b360b5c2104d09067864324bd

6 files changed, 29 insertions(+), 92 deletions(-)

jump to
M minpkg/core/utils.nimminpkg/core/utils.nim

@@ -120,8 +120,10 @@ var r = newSeq[MinValue](0)

for key, value in q.dVal.pairs: if value.kind == minProcOp: raiseInvalid("Dictionary contains operators that cannot be accessed.") - r.add key.newVal - r.add value.val + var p = newSeq[MinValue](0) + p.add value.val + p.add key.newVal + r.add p.newVal return r.newVal # JSON interop
M next-release.mdnext-release.md

@@ -1,5 +1,7 @@

### BREAKING CHANGES +* The `dpairs` symbol now returns a quotation of quotations, each containing a value/key pair. + ### New Features
M site/contents/reference-dict.mdsite/contents/reference-dict.md

@@ -46,7 +46,14 @@ > > {5 :q 4 :a 6 :c 7 :d "d" :a} ("a" "d") dpick

#} {#op||dpairs||{{d}}||({{a0p}})|| -Returns a quotation containing all the keys (odd items) and values (even items) of dictionary {{d}}. #} +> Returns a quotation containing a quotation for each value/key pair (value first, key second) of dictionary {{d}}. +> +> > %sidebar% +> > Example +> > +> > A The following program returns `((1 "a") (2 "b"))`: +> > {1 :a 2 :b} dpairs +#} {#op||dset||{{d}} {{any}} {{sl}}||{{d}}|| Sets the value of the {{sl}} of {{d1}} to {{any}}, and returns the modified dictionary {{d}}. #}
M tests/all.mintests/all.min

@@ -8,22 +8,23 @@ "=" 70 repeat puts!

"Total Symbols: $1" (total-symbols) => % puts! "Total Sigils: $1" (total-sigils) => % puts! "=" 70 repeat puts! +'crypto load +'dict load +'dstore load +'fs load +'io load 'lang load -'stack load -'seq load -'io load 'logic load +'math load 'num load +'seq load +'stack load 'str load 'sys load 'time load -'dstore load -'fs load -'crypto load -'math load +'xml load 'http load 'net load -'xml load "=" 70 repeat puts! "Total Failures: $1" (failures) => % puts! failures exit
M tests/dict.mintests/dict.min

@@ -25,24 +25,13 @@ ({} dtype "" ==) *test/assert

({1 :a 2 :b 3 :c 4 :d} ("b" "c") dpick {2 :b 3 :c} ==) *test/assert - (2 2 {+ :plus} ^plus 4 ==) *test/assert + (2 2 {+ :plus} /plus 4 ==) *test/assert (2 {(2 3 +) :sum} /sum -> + 7 ==) *test/assert ({a :test} "test" dget-raw /str "a" ==) *test/assert - ({} 'test 'aaa dset-sym {aaa :test} ==) *test/assert - - ( - {} :archives - ({"a" :a 2 :b} {"aa" :a 4 :b} {"aaa" :a 6 :b}) - ( - :article - article /a :code - {code :code} => - archives swap code dset @archives - ) foreach - archives {{"a" :code} :a {"aa" :code} :aa {"aaa" :code} :aaa} ==) *test/assert + ({} 'aaa 'test dset-sym {aaa :test} ==) *test/assert ( {} :archives

@@ -56,6 +45,10 @@ :archive

archives archive code dset @archives ) foreach archives {{"a" :code} :a {"aa" :code} :aa {"aaa" :code} :aaa} ==) *test/assert + + ( + {1 :a 2 :b 3 :c} dpairs ((1 "a") (2 "b") (3 "c")) == + ) *test/assert *test/report clear-stack
D tests/test.min

@@ -1,68 +0,0 @@

-"." :ok - -( - symbol padding - (==>) - (" " print!) -) :: - -( - symbol describe - ('sym :name ==> quot :out) - ( - "Testing: [" print! name print! "]" puts! - padding - () @out - ) -) :: - -( - symbol assert - (quot :results quot :check ==> quot :out) - ( - ( - ( - (check -> true ==) - (format-error puts! false) - ) try - ) - ( - ok results append @results - "." print! - ) - ( - check results append @results - "x" print! - ) - if - 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 - ) -) ::