Implemented tap and tap!.
h3rald h3rald@h3rald.com
Fri, 21 Jul 2017 21:34:25 +0200
6 files changed,
89 insertions(+),
6 deletions(-)
M
lib/min_lang.nim
→
lib/min_lang.nim
@@ -297,6 +297,27 @@ def.symbol("dequote") do (i: In):
let vals = i.expect("quot") var q = vals[0] i.dequote(q) + + def.symbol("tap") do (i: In): + let vals = i.expect("quot", "a") + let programs = vals[0] + var a = vals[1] + for program in programs.qVal: + var p = program + i.push(a) + i.dequote(p) + a = i.pop + i.push(a) + + def.symbol("tap!") do (i: In): + let vals = i.expect("quot", "a") + let programs = vals[0] + var a = vals[1] + for program in programs.qVal: + var p = program + i.push(a) + i.dequote(p) + a = i.pop # Conditionals
M
min.nimble
→
min.nimble
@@ -1,6 +1,6 @@
[Package] name = "min" -version = "0.8.1" +version = "0.9.0" author = "Fabio Cevasco" description = "A tiny concatenative programming language and shell." license = "MIT"
M
min.vim
→
min.vim
@@ -11,7 +11,7 @@
setl iskeyword=@,36-39,+,-,/,*,.,:,~,!,48-57,60-65,94-95,192-255 setl iskeyword+=^ -syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define defined? delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json to-timestamp try dequote uppercase unzip values version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append args ask atime bind bool boolean? call call! capitalize case cd chmod choose clear-stack cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define defined? delete dget dictionary? dip dir? dirname div dprint dprint! dset dup encode env? error eval even? exists? exit expect fappend fatal find file? filename filter first flatten float float? foreach fperms fread from-json format-error fs fsize fstats ftype fwrite get gets get-env get-stack hardlink harvest hidden? id if import in? indent indexof info insert int integer? interpolate interval io join keep keys length linrec load load-symbol logic loglevel loglevel? lowercase ls ls-r map map-reduce match md5 mkdir mod module module-symbols module-sigils mtime mv newline nip not notice now num number? odd? opts os over partition password pick pop popd pred prepend print print! prompt publish puts puts! put-env q quotation? quote quote-bind quote-define random raise reduce regex reject remove remove-symbol repeat replace rest reverse rm rmdir run save-symbol scope scope? seal search seq set set-stack sha1 sha224 sha256 sha384 sha512 shorten sigils sip size sleep slice sort source split spread stack startup stored-symbols str string string? strip succ sum swap swons symbols symlink symlink? sys system take tap tap! tformat time timeinfo times timestamp titleize to-json to-timestamp try dequote uppercase unzip values version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
M
site/contents/_includes/_reference-lang.md
→
site/contents/_includes/_reference-lang.md
@@ -87,6 +87,9 @@
{#op||delete||{{sl}}||{{null}}|| Deletes the specified symbol {{sl}}.#} +{#op||dequote||{{q}}||{{a0p}}|| +Pushes the contents of quotation {{q}} on the stack. #} + {#op||eval||{{s}}||{{a0p}}|| Parses and interprets {{s}}. #}@@ -241,6 +244,50 @@
{#op||symbols||{{null}}||({{s0p}})|| Returns a list of all symbols defined in the [ROOT](class:kwd) scope.#} +{#op||tap||{{any}} {{q}}||{{any}}|| +> Performs the following operations: +> +> 1. Removes {{any}} from the stack. +> 2. For each quotation defined in {{q}} (which is a quotation of quotations each requiring one argument and returning one argument): +> 1. Pushes {{any}} back to the stack. +> 2. Dequotes the quotation and saves the result as {{any}}. +> 3. Push the resulting {{any}} back on the stack. +> +> > %sidebar% +> > Example +> > +> > The following program: +> > +> > ( +> > ((a 1) (b 2) (c 3)) ( +> > (dup /a succ succ %a) +> > (dup /b succ %b) +> > ) tap +> > +> > Returns `((a 3) (b 3) (c 3))`.#} + +{#op||tap!||{{any}} {{q}}||{{any}}|| +> Performs the following operations: +> +> 1. Removes {{any}} from the stack. +> 2. For each quotation defined in {{q}} (which is a quotation of quotations each requiring one argument and returning one argument): +> 1. Pushes {{any}} back to the stack. +> 2. Dequotes the quotation and saves the result as {{any}}. +> +> > %sidebar% +> > Example +> > +> > The following program: +> > +> > "" :s1 +> > "test" ( +> > (' "1" swap append "" join) +> > (' "2" swap append "" join) +> > (' "3" swap append "" join @s1 s1) +> > ) tap! +> > +> > Sets `s1` to `"test123"`. #} + {#op||times||{{q}} {{i}}||{{a0p}}|| Applies the quotation {{q}} {{i}} times.#}@@ -269,9 +316,6 @@ > > ) try #}
{#op||unless||{{q1}} {{q2}}||{{a0p}}|| If {{1}} evaluates to {{f}} then evaluates {{2}}.#} - -{#op||dequote||{{q}}||{{a0p}}|| -Pushes the contents of quotation {{q}} on the stack. #} {#op||unseal||{{sl}}||{{null}}|| Unseals symbol {{sl}}, so that it can be re-assigned. #}
M
site/settings.json
→
site/settings.json
@@ -5,6 +5,6 @@ "templates": "templates",
"temp": "temp", "output": "output", "title": "min language", - "version": "0.8.1", + "version": "0.9.0", "rules": "rules.min" }
M
tests/lang.min
→
tests/lang.min
@@ -174,6 +174,24 @@ (false float 0.0 ==) assert
("3.678" float 3.678 ==) assert + ( + ((a 1) (b 2) (c 3)) ( + (dup /a succ succ %a) + (dup /b succ %b) + ) tap + ((a 3) (b 3) (c 3)) == + ) assert + + ( + "" :s1 + "test" ( + (' "1" swap append "" join) + (' "2" swap append "" join) + (' "3" swap append "" join @s1 s1) + ) tap! + s1 "test123" == + ) assert + report ; Tidy up clear-stack