all repos — min @ 75915243a6b1a7a28cde00ffaa859909b9f2dece

A small but practical concatenative programming language.

Documented lang and stack module; started documenting seq module.
h3rald h3rald@h3rald.com
Fri, 14 Apr 2017 21:55:04 +0200
commit

75915243a6b1a7a28cde00ffaa859909b9f2dece

parent

28a40c6da8e06b607d2b72031763d3ea0393e06a

M lib/min_stack.nimlib/min_stack.nim

@@ -57,12 +57,6 @@ .symbol("dupd") do (i: In):

i.push newVal(@["dup".newSym], i.scope) i.push "dip".newSym - #((dup) dip unquote) - .symbol("w") do (i: In): - i.push newVal(@["dup".newSym], i.scope) - i.push "dip".newSym - i.push "unquote".newSym - .symbol("dip") do (i: In): var q: MinValue i.reqQuotation q

@@ -107,12 +101,6 @@ let b = i.pop

i.push a i.push b - .symbol("nip") do (i: In): - i.reqStackSize 2 - let a = i.pop - discard i.pop - i.push a - .symbol("over") do (i: In): i.reqStackSize 2 let a = i.pop

@@ -154,60 +142,12 @@ .symbol("swapd") do (i: In):

i.push newVal(@["swap".newSym], i.scope) i.push "dip".newSym - # ((swap) dip unquote) - .symbol("c") do (i: In): - i.push newVal(@["swap".newSym], i.scope) - i.push "dip".newSym - i.push "unquote".newSym - .symbol("cons") do (i: In): var q: MinValue i.reqQuotation q let v = i.pop q.qVal = @[v] & q.qVal i.push q - - # (() cons dip) - .symbol("dig1") do (i: In): - i.push newVal(@[], i.scope) - i.push "cons".newSym - i.push "dip".newSym - - # (() cons cons dip) - .symbol("dig2") do (i: In): - i.push newVal(@[], i.scope) - i.push "cons".newSym - i.push "cons".newSym - i.push "dip".newSym - - # (() cons cons cons dip) - .symbol("dig3") do (i: In): - i.push newVal(@[], i.scope) - i.push "cons".newSym - i.push "cons".newSym - i.push "cons".newSym - i.push "dip".newSym - - # ((() cons) dip swap unquote) - .symbol("bury1") do (i: In): - i.push newVal(@[newVal(@[], i.scope), "cons".newSym], i.scope) - i.push "dip".newSym - i.push "swap".newSym - i.push "unquote".newSym - - # ((() cons cons) dip swap unquote) - .symbol("bury2") do (i: In): - i.push newVal(@[newVal(@[], i.scope), "cons".newSym, "cons".newSym], i.scope) - i.push "dip".newSym - i.push "swap".newSym - i.push "unquote".newSym - - # ((() cons cons cons) dip swap unquote) - .symbol("bury3") do (i: In): - i.push newVal(@[newVal(@[], i.scope), "cons".newSym, "cons".newSym, "cons".newSym], i.scope) - i.push "dip".newSym - i.push "swap".newSym - i.push "unquote".newSym .symbol("swons") do (i: In): i.push "swap".newSym
M min.vimmin.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 ask atime b bind bool bool? bury1 bury2 bury3 c call call! capitalize case cd chmod choose cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dig1 dig2 dig3 dip dir? dirname div dprint dprint! dset dup dupd encode env? error eval even? exists? exit 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 hardlink harvest hidden? id if import in? indent info insert int int? interpolate interval io join k 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 newstack nip not notice now num number? odd? 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 set 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 swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote unstack uppercase unzip values version warn when which while with xor zip +syntax keyword minDefaultSymbol ! != $ & ' * + # - % ^ -> . .. / : < <= == => =~ > >= @ ROOT aes all? and any? append ask atime bind bool bool? call call! capitalize case cd chmod choose cleave column-print concat confirm cons cp cpu crypto ctime datetime ddel debug decode define delete dget dictionary? dip dir? dirname div dprint dprint! dset dup dupd encode env? error eval even? exists? exit 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 hardlink harvest hidden? id if import in? indent info insert int int? 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 newstack nip not notice now num number? odd? 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 set 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 swapd swons symbols symlink symlink? sys system take tformat time timeinfo times timestamp titleize to-json try unquote unstack uppercase unzip values version warn when which while with xor zip syntax match minDefaultSigil ;\<[:@'~!$%&$=<>#^*#+/]; contained
M site/contents/_includes/_defs_.mdsite/contents/_includes/_defs_.md

@@ -1,5 +1,4 @@

{{q => [quot](class:kwd)}} -{{qq => [(quot<sub>+</sub>)](class:kwd)}} {{q1 => [quot<sub>1</sub>](class:kwd)}} {{q2 => [quot<sub>2</sub>](class:kwd)}} {{q3 => [quot<sub>3</sub>](class:kwd)}}

@@ -10,10 +9,15 @@ {{3 => [<sub>3</sub>](class:kwd)}}

{{4 => [<sub>4</sub>](class:kwd)}} {{e => [err](class:kwd)}} {{d => [dict](class:kwd)}} +{{d1 => [dict<sub>1</sub>](class:kwd)}} +{{d2 => [dict<sub>2</sub>](class:kwd)}} {{i => [int](class:kwd)}} {{n => [num](class:kwd)}} -{{any => [any](class:kwd)}} -{{a0p => [any<sub>\*</sub>](class:kwd)}} +{{any => [a](class:kwd)}} +{{a1 => [a<sub>1</sub>](class:kwd)}} +{{a2 => [a<sub>2</sub>](class:kwd)}} +{{a3 => [a<sub>3</sub>](class:kwd)}} +{{a0p => [a<sub>\*</sub>](class:kwd)}} {{s0p => [string<sub>\*</sub>](class:kwd)}} {{s => [string](class:kwd)}} {{b => [bool](class:kwd)}}
M site/contents/_includes/_reference-lang.mdsite/contents/_includes/_reference-lang.md

@@ -83,16 +83,15 @@ {#op||foreach||{{q1}} {{q2}}||{{a0p}}||

Applies the quotation {{q2}} to each element of {{q1}}.#} {#op||format-error||{{e}}||{{s}}|| -Formats the error {{e}} as a string. - -> %sidebar% -> Example -> -> The following: -> -> `((error "MyError") (message "This is a test error")) format-error` -> -> produces: `"This is a test error"`#} +> Formats the error {{e}} as a string. +> > %sidebar% +> > Example +> > +> > The following: +> > +> > `((error "MyError") (message "This is a test error")) format-error` +> > +> > produces: `"This is a test error"`#} {#op||from-json||{{s}}||{{a0p}}|| Converts a JSON string into {{m}} data.#}

@@ -114,7 +113,7 @@ >

> > %sidebar% > > Example > > -> > The following programs returns [120](class:kwd), the factorial of 5: +> > The following program leaves `120` on the stack, the factorial of 5: > > > > (dup 0 ==) 'succ (dup pred) '* linrec #}

@@ -150,7 +149,7 @@ {#op||module-symbols||{{q}}||({{s0p}})||

Returns a list of all symbols defined in module {{q}}.#} {#op||publish||{{sl}} {{q}}||{{null}}|| -Publishes symbol {{sl}} to the scope of {{q}}. +> Publishes symbol {{sl}} to the scope of {{q}}. > > > %sidebar% > > Example

@@ -198,7 +197,7 @@ {#op||to-json||{{q}}||{{s}}||

Converts {{q}} into a JSON string {{s}}.#} {#op||try||({{q1}} {{q}}{{2}}{{01}} {{q}}{{3}}{{01}})||{{a0p}}|| -Evaluates a quotation as a try/catch/finally block. +> Evaluates a quotation as a try/catch/finally block. > > The must contain the following elements: >
M site/contents/_includes/_reference-seq.mdsite/contents/_includes/_reference-seq.md

@@ -1,42 +1,42 @@

{@ _defs_.md || 0 @} -{#op||all?||(2) (1)||B|| -Applies predicate {{1}} to each element of {{2}} and returns {{t}} if all elements of {{2}} satisfy predicate {{1}}. #} +{#op||all?||{{q1}} {{q2}}||{{b}}|| +Applies predicate {{q2}} to each element of {{q1}} and returns {{t}} if all elements of {{q1}} satisfy predicate {{q2}}, {{f}} otherwise. #} -{#op||any?||(2) (1)||B|| -Applies predicate {{1}} to each element of {{2}} and returns {{t}} if at least one element of {{2}} satisfies predicate {{1}}. #} +{#op||any?||{{q1}} {{q2}}||B|| +Applies predicate {{q2}} to each element of {{q1}} and returns {{t}} if at least one element of {{q1}} satisfies predicate {{q2}}, {{f}} otherwise. #} -{#op||append||\* (1)||(\*)|| -Returns a new quotation containing the contents of {{1}} with {{any}} appended. #} +{#op||append||{{any}} {{q}}||({{a0p}} {{any}})|| +Returns a new quotation containing the contents of {{q}} with {{any}} appended. #} -{#op||apply||(1)||(\*)|| -Returns a new quotation {{q}} obtained by evaluating each element of {{1}} in a separate stack.#} +{#op||apply||{{q}}||({{a0p}})|| +Returns a new quotation {{q}} obtained by evaluating each element of {{q}} in a separate stack.#} -{#op||at||(\*) I||\*|| -Returns the {{i}}^th element of {{q}}.#} +{#op||get||{{q}} {{i}}||{{any}}|| +Returns the _n^th_ element of {{q}} (zero-based).#} -{#op||concat||(2) (1)||(\*)|| -Concatenates {{2}} with {{1}}. #} +{#op||concat||{{q1}} {{q2}}||{{q3}}|| +Concatenates {{q1}} with {{q2}}. #} -{#op||ddel||(D) §||(D')|| -Returns a copy of {{d}} without the element with key {{sl}}. #} +{#op||ddel||{{d1}} {{sl}}||{{d2}}|| +Returns a copy of {{d1}} without the element with key {{sl}}. #} -{#op||filter||(2) (1)||(\*)|| -> Returns a new quotation {{q}} containing all elements of {{2}} that satisfy predicate {{1}}. +{#op||filter||{{q1}} {{q2}}||{{q3}}|| +> Returns a new quotation {{q3}} containing all elements of {{q1}} that satisfy predicate {{q2}}. > > > %sidebar% > > Example > > -> > The following program returns [(2 6 8 12)](class:kwd): +> > The following program leaves `(2 6 8 12)` on the stack: > > > > (1 37 34 2 6 8 12 21) > > (dup 20 < swap even? and) filter #} -{#op||dget||(D) §||\*|| -Returns the value of key {{sl}}. #} +{#op||dget||{{d}} {{sl}}||{{any}}|| +Returns the value of key {{sl}} from dictionary {{d}}. #} -{#op||dhas?||(D) §||B|| -> Returns {{t}} if dictionary {{d}} contains the key {{sl}}. +{#op||dhas?||{{d}} {{sl}}||{{b}}|| +> Returns {{t}} if dictionary {{d}} contains the key {{sl}}, {{f}} otherwise. > > > %sidebar% > > Example

@@ -46,45 +46,57 @@ > >

> > ((a1 true) (a2 "aaa") (a3 false)) 'a2 dhas? #} -{#op||dset||(D) \* §||(D')|| -Sets the values of the {{sl}} of {{d}} to {{any}}, and return a modified copy of {{d}}. #} +{#op||dset||{{d1}} {{any}} {{sl}}||{{d2}}|| +Sets the value of the {{sl}} of {{d1}} to {{any}}, and returns the modified copy of the dictionary {{d2}}. #} -{#op||first||(\*)||\*|| +{#op||first||{{q}}||{{any}}|| Returns the first element of {{q}}. #} -{#op||in?||(\*) \*||B|| -Returns {{t}} if {{any}} is contained in {{q}}.#} +{#op||in?||{{q}} {{any}}||{{b}}|| +Returns {{t}} if {{any}} is contained in {{q}}, {{f}} otherwise.#} + +{#op||insert||{{q1}} {{any}} {{i}}||{{q2}}|| +Inserts {{any}} as the value of the _n^th_ element {{q1}} (zero-based), and returns the modified copy of the quotation {{q2}}. #} -{#op||keys||(D)||(S+)|| +{#op||keys||{{q}}||({{s}}{{0p}})|| Returns a quotation containing all the keys of dictionary {{d}}. #} -{#op||map||(2) (1)||(\*)|| -Returns a new quotation {{q}} obtained by applying {{1}} to each element of {{2}}.#} +{#op||map||{{q1}} {{q2}}||{{q3}}|| +Returns a new quotation {{q3}} obtained by applying {{q2}} to each element of {{q1}}.#} + +{#op||prepend||{{any}} {{q}}||({{any}} {{a0p}})|| +Returns a new quotation containing the contents of {{q}} with {{any}} prepended. #} -{#op||prepend||\* (\*)||(\*)|| -Returns a new quotation containing the contents of {{q}} with [\*](class:kwd) prepended. #} +{#op||reject||{{q1}} {{q2}}||{{q3}}|| +Returns a new quotatios {{q3}} including all elements of {{q1}} that do not satisfy predicate {{q2}} (i.e. the opposite of `filter`)#} + +{#op||remove||{{q1}} {{i}}||{{q2}}|| +Returns the _n^th_ element of {{q1}} (zero-based), and returns the modified copy of the quotation {{q2}}.#} + +{#op||rest||{{q1}}||{{q2}}|| +Returns a new quotation {{q2}} containing all elements of {{q1}} quotation except for the first. #} -{#op||rest||(\*)||(\*)|| -Returns a new quotation containing all elements of the input quotation except for the first. #} +{#op||reverse||{{q1}}||{{q2}}|| +Returns a new quotation {{q2}} containing all elements of {{q1}} in reverse order. #} -{#op||reverse||(1)||(\*)|| -Returns a new quotation {{q}} containing all elements of {{1}} in reverse order. #} +{#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||shorten||(\*) I||(\*)|| -Returns a quotation containing the first {{i}} values of the input quotation. #} +{#op||shorten||{{q1}} {{i}}||{{q2}}|| +Returns a quotation {{q2}} containing the first _n_ values of the input quotation {{q1}}. #} -{#op||size||(\*)||I|| +{#op||size||{{q}}||{{i}}|| Returns the length of {{q}}.#} -{#op||sort||(2) (1)||(\*)|| -> Sorts all elements of {{2}} according to predicate {{1}}. +{#op||sort||{{q1}} {{q2}}||{{q3}}|| +> Sorts all elements of {{q1}} according to predicate {{q2}}. > > > %sidebar% > > Example > > -> > The following programs returns [(1 3 5 7 9 13 16)](class:kwd): +> > The following program leaves `(1 3 5 7 9 13 16)` on the stack: > > > > (1 9 5 13 16 3 7) '> sort #} -{#op||values||(D)||(\*+)|| -Returns a quotation containing all the values of dictionary {{d}}. #}+{#op||values||{{d}}||({{a0p}})|| +Returns a quotation containing all the values of dictionary {{d}}. #}
M site/contents/_includes/_reference-stack.mdsite/contents/_includes/_reference-stack.md

@@ -1,43 +1,90 @@

{@ _defs_.md || 0 @} -{#op||dip||2 (1)||1 2|| +{#op||cleave||{{a1}} ({{q}}{{0p}})||{{a0p}}|| +> Applies each quotation contained in the first element to the second element {{a1}}. +> > %sidebar% +> > Example +> > +> > The following program leaves 2 on the stack: +> > +> > `(1 2 3) ((sum) (size)) cleave /`#} + +{#op||cons||{{a1}} ({{a0p}})||({{a1}} {{a0p}})|| +Prepends {{a1}} to the quotation on top of the stack.#} + +{#op||dip||{{a1}} ({{a2}})||{{a0p}} {{a1}}|| Removes the first and second element from the stack, unquotes the first element, and restores the second element.#} -{#op||dup||1||1 1|| +{#op||dup||{{a1}}||{{a1}} {{a1}}|| Duplicates the first element on the stack.#} -{#op||dupd||2 1||2 2 1|| +{#op||dupd||{{a1}} {{a2}}||{{a1}} {{a1}} {{a2}}|| Duplicates the second element on the stack.#} {#op||id||{{null}}||{{null}}|| Does nothing.#} -{#op||k||(2) (1)||1|| +{#op||k||{{a1}} ({{a2}})||{{a0p}}|| K combinator; removes the second element from the stack and unquotes the first element on the stack.#} + +{#op||keep||{{a1}} {{q}}||{{a0p}} {{a1}}|| +> Applies each quotation contained in the first element to each subsequent corresponding element. +> > %sidebar% +> > Example +> > +> > The following program leaves `5 3` on the stack: +> > +> > `2 3 '+ keep` #} {#op||newstack||{{null}}||{{null}}|| Empties the stack.#} -{#op||pop||\*||{{null}}|| +{#op||over||{{a1}} {{a2}}||{{a1}} {{a2}} {{a1}}|| +Pushes a copy of the second element on top of the stack.#} + +{#op||pick||{{a1}} {{a2}} {{a3}}||{{a1}} {{a2}} {{a3}} {{a1}}|| +Pushes a copy of the third element on top of the stack.#} + +{#op||pop||{{any}}||{{null}}|| Removes the first element from the stack.#} -{#op||popd||2 1||1|| +{#op||popd||{{a1}} {{a2}}||{{a2}}|| Removes the second element from the stack.#} -{#op||popop||2 1||{{null}}|| +{#op||popop||{{a1}} {{a2}}||{{null}}|| Removes the first two elements from the stack.#} -{#op||rollup||3 2 1||1 2 3|| - Moves the third and second element into second and third position and moves the first element into third position.#} +{#op||rolldown||{{a1}} {{a2}} {{a3}}||{{a2}} {{a3}} {{a1}}|| +Moves the third element in first position, the second in third position and the the first in second position.#} + +{#op||rollup||{{a1}} {{a2}} {{a3}}||{{a3}} {{a2}} {{a1}}|| +Moves the third and second element into second and third position and moves the first element into third position.#} + +{#op||sip||{{a1}} ({{a2}})||{{a0p}} {{a1}}|| +Saves the {{a1}}, unquotes {{a2}}, and restores {{a1}}.#} + +{#op||spread||{{a0p}} ({{q}}{{0p}})||{{a0p}}|| +> Applies each quotation contained in the first element to each subsequent corresponding element. +> > %sidebar% +> > Example +> > +> > The following program leaves `(1 4)` on the stack: +> > +> > `(1 2) (3 4) ((0 get) (1 get)) spread` #} -{#op||stack||{{null}}||(\*)|| +{#op||stack||{{null}}||({{a0p}})|| Returns a quotation containing the contents of the stack.#} -{#op||swap||2 1||1 2|| +{#op||swap||{{a1}} {{a2}}||{{a2}} {{a1}}|| Swaps the first two elements on the stack. #} -{#op||unstack||(\*)||\*?|| +{#op||swapd||{{a1}} {{a2}} {{a3}}||{{a2}} {{a1}} {{a3}}|| +Swaps the second and third elements on the stack. #} + +{#op||swons||({{a0p}}) {{a1}}||({{a1}} {{a0p}})|| +Prepends {{a1}} to the quotation that follows it.#} + +{#op||unstack||{{q}}||{{a0p}}|| Substitute the existing stack with the contents of {{q}}.#} -{#op||w||(2) (1)||(2) (2) 1|| -W combinator; duplicates the second element from the stack and unquotes the first element on the stack.#}+
M site/contents/_includes/_reference.mdsite/contents/_includes/_reference.md

@@ -47,8 +47,6 @@ {{sl}}

: A string-like value (string or quoted symbol). {{q}} : A quotation (also expressed as parenthesis enclosing other values). -{{qq}} -: Quotation of quotations. {{d}} : A dictionary value. {{e}}
M tests/stack.mintests/stack.min

@@ -25,8 +25,6 @@ ((1) (2 swap append) sip concat (1 2 1) ==) assert

(1 (2 3) cons (1 2 3) ==) assert - (1 2 nip 2 ==) assert - (1 2 over stack (1 2 1) ==) assert (1 2 3 pick stack (1 2 3 1) ==) assert