all repos — min @ a0f34672a8ee03a8934709c274a8d753389a9210

A small but practical concatenative programming language.

Implemented get-raw, set-sym, dset-sym
h3rald h3rald@h3rald.com
Sat, 01 Jan 2022 15:26:57 +0100
commit

a0f34672a8ee03a8934709c274a8d753389a9210

parent

cd651c879623e43c0d73b82091e3522516221479

M minpkg/lib/min_dict.nimminpkg/lib/min_dict.nim

@@ -21,11 +21,30 @@ let vals = i.expect("'sym", "dict")

let k = vals[0] let d = vals[1] i.push i.dget(d, k) + + def.symbol("dget-raw") do (i: In): + let vals = i.expect("'sym", "dict") + let k = vals[0] + let d = vals[1] + let v = i.dget(d, k) + var rv = newDict(i.scope) + rv.objType = "rawval" + i.dset(rv, "type", v.typeName.newVal) + i.dset(rv, "val", v) + i.dset(rv, "str", newVal($v)) + i.push rv def.symbol("dset") do (i: In): let vals = i.expect("'sym", "a", "dict") let k = vals[0] let m = vals[1] + var d = vals[2] + i.push i.dset(d, k, m) + + def.symbol("dset-sym") do (i: In): + let vals = i.expect("'sym", "'sym", "dict") + let k = vals[0] + let m = newSym(vals[1].getString) var d = vals[2] i.push i.dset(d, k, m)
M minpkg/lib/min_seq.nimminpkg/lib/min_seq.nim

@@ -105,7 +105,18 @@ def.symbol("set") do (i: In):

let vals = i.expect("int", "a", "quot") let index = vals[0] let val = vals[1] - let q = vals[2] + var q = newVal(vals[2].qVal) + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + q.qVal[ix.int] = val + i.push q + + def.symbol("set-sym") do (i: In): + let vals = i.expect("int", "'sym", "quot") + let index = vals[0] + let val = newSym(vals[1].getString) + var q = newVal(vals[2].qVal) let ix = index.intVal if q.qVal.len < ix or ix < 0: raiseOutOfBounds("Index out of bounds")
M next-release.mdnext-release.md

@@ -2,10 +2,14 @@ ### New Features

* Added **quoted-symbol?** predicate. * Added **get-raw** operator to retrieve information on an element of a quotation without evaluating it. +* Added **dget-raw** operator to retrieve information on an element of a dictionary without evaluating it. +* Added **set-sym** operator to set an element of a quotation to a symbol (specified as a string). +* Added **dset-sym** operator to set a key of a dictionary to a symbol (specified as a string). ### Fixes and Improvements * Miscellaneous documentation fixes. * Now clearing the stack after every HTTP request received by **http-server**. * Fixed #174 (cons operator was not creating a new quotation). * Fixed #176 (times can now execute a quotation 0 times). +* **set** now actually creates a copy of the specified quotation. * Documented previously-undocumented **type** operator.
M site/contents/reference-dict.mdsite/contents/reference-dict.md

@@ -17,6 +17,9 @@

{#op||dget||{{d}} {{sl}}||{{any}}|| Returns the value of key {{sl}} from dictionary {{d}}. #} +{#op||dget-raw||{{d}} {{sl}}||{{rawval}}|| +Returns the value of key {{sl}} from dictionary {{d}}, wrapped in a {{rawval}}. #} + {#op||dhas?||{{d}} {{sl}}||{{b}}|| > Returns {{t}} if dictionary {{d}} contains the key {{sl}}, {{f}} otherwise. >

@@ -47,6 +50,9 @@ Returns a quotation containing all the keys (odd items) and values (even items) of dictiionary {{d}}. #}

{#op||dset||{{d}} {{any}} {{sl}}||{{d}}|| Sets the value of the {{sl}} of {{d1}} to {{any}}, and returns the modified dictionary {{d}}. #} + +{#op||dset||{{d}} {{sl}} {{sl}}||{{d}}|| +Sets the value of the {{sl}} of {{d1}} to {{sl}} (treating it as a symbol), and returns the modified dictionary {{d}}. #} {#op||dtype||{{d}}||{{s}}|| Returns a string set to the type of {{d}} (empty if the dictionary has no type). #}
M site/contents/reference-seq.mdsite/contents/reference-seq.md

@@ -161,6 +161,9 @@

{#op||set||{{q1}} {{any}} {{i}}||{{q2}}|| Sets the value of the _n^th_ element {{q1}} (zero-based) to {{any}}, and returns the modified copy of the quotation {{q2}}. #} +{#op||set-sym||{{q1}} {{sl}} {{i}}||{{q2}}|| +Sets the value of the _n^th_ element {{q1}} (zero-based) to {{sl}} (treating it as a symbol), and returns the modified copy of the quotation {{q2}}. #} + {#op||shorten||{{q1}} {{i}}||{{q2}}|| Returns a quotation {{q2}} containing the first _n_ values of the input quotation {{q1}}. #}
M tests/dict.mintests/dict.min

@@ -29,6 +29,10 @@ (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})

@@ -54,4 +58,4 @@ ) foreach

archives {{"a" :code} :a {"aa" :code} :aa {"aaa" :code} :aaa} ==) *test/assert *test/report - clear-stack+ clear-stack
M tests/seq.mintests/seq.min

@@ -21,6 +21,8 @@ ((a b c) 1 get-raw /type "sym" ==) *test/assert

((1 2 3 4) 222 2 set (1 2 222 4) ==) *test/assert + ((1 2 3) "test" 1 set-sym (1 test 3) ==) *test/assert + ((1 2 3 4) 2 remove (1 2 4) ==) *test/assert ((1 2 3 4) 333 2 insert (1 2 333 3 4) ==) *test/assert