all repos — min @ cd651c879623e43c0d73b82091e3522516221479

A small but practical concatenative programming language.

Implemented get-raw.
h3rald h3rald@h3rald.com
Sat, 01 Jan 2022 15:09:44 +0100
commit

cd651c879623e43c0d73b82091e3522516221479

parent

93a2c7b46acd34b42d41a2cf820af491a13877a5

M min.nimblemin.nimble

@@ -13,7 +13,7 @@ installDirs = @["minpkg"]

# Dependencies -requires "nim >= 1.4.4, zippy >= 0.5.6" +requires "nim >= 1.6.2, zippy >= 0.5.6" before install: exec "nimble install -y nifty"
M minpkg/lib/min_seq.nimminpkg/lib/min_seq.nim

@@ -85,7 +85,22 @@ let ix = index.intVal

if q.qVal.len < ix or ix < 0: raiseOutOfBounds("Index out of bounds") i.push q.qVal[ix.int] - + + def.symbol("get-raw") do (i: In): + let vals = i.expect("int", "quot") + let index = vals[0] + let q = vals[1] + let ix = index.intVal + if q.qVal.len < ix or ix < 0: + raiseOutOfBounds("Index out of bounds") + let v = q.qVal[ix.int] + 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("set") do (i: In): let vals = i.expect("int", "a", "quot") let index = vals[0]
M next-release.mdnext-release.md

@@ -1,8 +1,11 @@

+### New Features + +* Added **quoted-symbol?** predicate. +* Added **get-raw** operator to retrieve information on an element of a quotation without evaluating it. ### 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). -* Added **quoted-symbol?** predicate. * Documented previously-undocumented **type** operator.
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -53,6 +53,7 @@ {{no-win => (not supported on Windows systems)}}

{{help => [dict:help](class:kwd)}} {{sock => [dict:socket](class:kwd)}} {{url => [dict:url](class:kwd)}} +{{rawval => [dict:rawval](class:kwd)}} {{req => [dict:http-request](class:kwd)}} {{res => [dict:http-response](class:kwd)}} {{sock1 => [dict:socket<sub>1</sub>](class:kwd)}}
M site/contents/reference-seq.mdsite/contents/reference-seq.md

@@ -132,6 +132,9 @@

{#op||quote-map||{{q1}}||{{q2}}|| Returns a new quotation {{q2}} obtained by quoting each element of {{q1}}.#} +{#op||raw-get||{{q}} {{i}}||{{rawval}}|| +Returns the _n^th_ element of {{q}} (zero-based) wrapped in a {{rawval}}.#} + {#op||reduce||{{q1}} {{a1}} {{q2}}||{{a2}}|| > Combines each successive element of {{q1}} using {{q2}}. On the first iteration, the first two inputs processed by {{q2}} are {{a1}} and the first element of {{q1}}. >
M site/contents/reference.mdsite/contents/reference.md

@@ -129,6 +129,15 @@ "stream" :type

"tcp" :protocol ;socket } +{{rawval}} +: A raw value dictionary obtained via the {#link-operator||seq||get-raw#} or {#link-operator||dict||dget-raw#} operators: + + { + "sym" :type + "my-symbol" :str + my-symbol :val + ;rawval + } {{dstore}} : A datastore dictionary that must be created through the {#link-operator||dstore||dsinit#} or {#link-operator||dstore||dsread#} operator:
M tests/seq.mintests/seq.min

@@ -17,6 +17,8 @@ (0 (1 2 3) prepend (0 1 2 3) ==) *test/assert

((1 2 3 4) 2 get 3 ==) *test/assert + ((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 4) 2 remove (1 2 4) ==) *test/assert

@@ -86,4 +88,4 @@

((1 2 "test") ("test" "a" true 1) symmetric-difference (true "a" 2) ==) *test/assert *test/report - clear-stack+ clear-stack