all repos — min @ fdcacd95b472f3dd952e88834ff0fdfcbdd61472

A small but practical concatenative programming language.

Reviewed type notation.
h3rald h3rald@h3rald.com
Fri, 14 Apr 2017 17:15:25 +0200
commit

fdcacd95b472f3dd952e88834ff0fdfcbdd61472

parent

ea21d459d9661f4ffb66011a353832341392ee97

D site/contents/_includes/_defs.md

@@ -1,51 +0,0 @@

- -{#op => -<a id="op-$1"></> -## $1 - -> %operator% -> [ $2 **&rArr;** $3](class:kwd) -> -> $4 - #} - -{#alias => -## $1 - -> %operator% -> [ $1 **&rArr;** $2](class:kwd) -> -> See [$2](#op-$2). - #} - -{#sig => -## $1 [](class:sigil) - -> %operator% -> [ $1S **&rArr;** S $2](class:kwd) -> -> See [$2](#op-$2). - #} - -{# link-module => [`$1` Module](/reference-$1/) #} - -{{q => [(\*)](class:kwd)}} -{{1e => [1](class:kwd)}} -{{2e => [2](class:kwd)}} -{{1 => [(1)](class:kwd)}} -{{2 => [(2)](class:kwd)}} -{{3 => [(3)](class:kwd)}} -{{4 => [(4)](class:kwd)}} -{{e => [(E)](class:kwd)}} -{{d => [(D)](class:kwd)}} -{{i => [I](class:kwd)}} -{{n => [N](class:kwd)}} -{{any => [\*](class:kwd)}} -{{s => [S](class:kwd)}} -{{s1 => [S1](class:kwd)}} -{{s2 => [S2](class:kwd)}} -{{sp => [S+](class:kwd)}} -{{sl => [§](class:kwd)}} -{{f => [false](class:kwd)}} -{{t => [true](class:kwd)}} -{{null => &#x2205;}}
A site/contents/_includes/_defs_.md

@@ -0,0 +1,58 @@

+{{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)}} +{{q4 => [quot<sub>4</sub>](class:kwd)}} +{{1 => [<sub>1</sub>](class:kwd)}} +{{2 => [<sub>2</sub>](class:kwd)}} +{{3 => [<sub>3</sub>](class:kwd)}} +{{4 => [<sub>4</sub>](class:kwd)}} +{{e => [err](class:kwd)}} +{{d => [dict](class:kwd)}} +{{i => [int](class:kwd)}} +{{n => [num](class:kwd)}} +{{any => [any](class:kwd)}} +{{a0p => [any<sub>\*</sub>](class:kwd)}} +{{s0p => [string<sub>\*</sub>](class:kwd)}} +{{s => [string](class:kwd)}} +{{b => [bool](class:kwd)}} +{{01 => [<sub>?</sub>](class:kwd)}} +{{0p => [<sub>\*</sub>](class:kwd)}} +{{1p => [<sub>\+</sub>](class:kwd)}} +{{sl => [&apos;sym](class:kwd)}} +{{f => [false](class:kwd)}} +{{t => [true](class:kwd)}} +{{null => &#x2205;}} +{{m => _min_}} + +{#op => +<a id="op-$1"></> +## $1 + +> %operator% +> [ $2 **&rArr;** $3](class:kwd) +> +> $4 + #} + +{#alias => +## $1 + +> %operator% +> [ $1 **&rArr;** $2](class:kwd) +> +> See [$2](#op-$2). + #} + +{#sig => +## $1 [](class:sigil) + +> %operator% +> [ $1{{s}} **&rArr;** {{s}} $2](class:kwd) +> +> See [$2](#op-$2). + #} + +{# link-module => [`$1` Module](/reference-$1/) #} +
M site/contents/_includes/_reference-lang.mdsite/contents/_includes/_reference-lang.md

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

{@ _defs_.md || 0 @} -{#sig||'||quote#} +{#sig||&apos;||quote#} -{#alias||'||quote#} +{#alias||&apos;||quote#} {#sig||:||define#}

@@ -36,19 +36,19 @@ {#sig||#||quote-define#}

{#sig||=||quote-bind#} -{#op||bind||\* §||{{null}}|| +{#op||bind||{{any}} {{sl}}||{{null}}|| Binds the specified value (auto-quoted) to an existing symbol {{sl}}.#} -{#op||call||(\*) §||\*?|| +{#op||call||{{q}} {{sl}}||{{a0p}}|| Calls operator {{sl}} defined in scope {{q}}. #} -{#op||case||(1)||\*?|| -> {{1}} is a quotation containing _n_ different conditional branches. +{#op||case||(({{q1}} {{q2}}){{0p}})||{{a0p}}|| +> This operator takes a quotation containing _n_ different conditional branches. > > Each branch must be a quotation containing two quotations, and it is processed as follows: > -> * if the first quotation evaluates to {{t}}, then the second quotation is executed. -> * if the first quotation evaluates to {{f}}, then the following branch is processed (if any). +> * if {{q1}} evaluates to {{t}}, then the {{q2}} is executed. +> * if {{q1}} evaluates to {{f}}, then the following branch is processed (if any). > > > %sidebar% > > Example

@@ -64,25 +64,25 @@

{#op||debug||{{null}}||{{null}}|| Toggles debug mode. #} -{#op||debug?||{{null}}||B|| +{#op||debug?||{{null}}||{{b}}|| Returns {{t}} if debug mode is on, {{f}} otherwise. #} -{#op||define||\* §||{{null}}|| -Defines a new symbol {{sl}}, containing the specified value (auto-quoted).#} +{#op||define||{{any}} {{sl}}||{{null}}|| +Defines a new symbol {{sl}}, containing the specified value (auto-quoted if not already a quotation).#} -{#op||delete||§||{{null}}|| +{#op||delete||{{sl}}||{{null}}|| Deletes the specified symbol {{sl}}.#} -{#op||eval||S||\*?|| +{#op||eval||{{s}}||{{a0p}}|| Parses and interprets {{s}}. #} {#op||exit||{{null}}||{{null}}|| Exits the program or shell. #} -{#op||foreach||(2) (1)||\*?|| -Applies the quotation {{1}} to each element of {{2}}.#} +{#op||foreach||{{q1}} {{q2}}||{{a0p}}|| +Applies the quotation {{q2}} to each element of {{q1}}.#} -{#op||format-error||(E)||S|| +{#op||format-error||{{e}}||{{s}}|| Formats the error {{e}} as a string. > %sidebar%

@@ -94,22 +94,22 @@ > `((error "MyError") (message "This is a test error")) format-error`

> > produces: `"This is a test error"`#} -{#op||from-json||S||\*|| -Converts a JSON string into {{M -> min}} data.#} +{#op||from-json||{{s}}||{{a0p}}|| +Converts a JSON string into {{m}} data.#} -{#op||if||(3) (2) (1)||\*?|| -If {{3}} evaluates to {{t}} then evaluates {{2}}, otherwise evaluates {{1}}.#} +{#op||if||{{q1}} {{q2}} {{q3}}||{{a0p}}|| +If {{q1}} evaluates to {{t}} then evaluates {{q2}}, otherwise evaluates {{q3}}.#} -{#op||import||§||{{null}}|| +{#op||import||{{sl}}||{{null}}|| Imports the a previously-loaded module {{sl}}, defining all its symbols in the current scope. #} -{#op||linrec||(4) (3) (2) (1)||\*?|| +{#op||linrec||{{q1}} {{q2}} {{q3}} {{q4}}||{{a0p}}|| > Implements linear recursions as follows: > -> 1. Evaluates {{4}}. -> * If {{4}} evaluates to {{t}}, then it evaluates {{3}}. -> * Otherwises it executes {{2}} and recurses using the same four quotations. -> 2. Finally, it executes {{1}}. +> 1. Evaluates {{q1}}. +> * If {{q1}} evaluates to {{t}}, then it evaluates {{q2}}. +> * Otherwises it executes {{q3}} and recurses using the same four quotations. +> 2. Finally, it executes {{q4}}. > > > %sidebar% > > Example

@@ -119,13 +119,13 @@ > >

> > (dup 0 ==) 'succ (dup pred) '* linrec #} -{#op||load||S||\*?|| -Parses and interprets the specified {{M}} file {{s}}, adding [.min](class:ext) if not specified. #} +{#op||load||{{sl}}||{{a0p}}|| +Parses and interprets the specified {{m}} file, adding [.min](class:ext) if not specified. #} -{#op||load-symbol||§||\*|| +{#op||load-symbol||{{sl}}||{{a0p}}|| Loads the contents of symbol {{sl}} from the [.min\_symbols](class:file) file. #} -{#op||loglevel||§||{{null}}|| +{#op||loglevel||{{sl}}||{{null}}|| > Sets the current logging level to {{sl}}. {{sl}} must be one of the following strings or quoted symbols: > > * debug

@@ -140,17 +140,17 @@ > > Note

> > > > The default logging level is _notice_.#} -{#op||module||(\*) §||{{null}}|| +{#op||module||{{q}} {{sl}}||{{null}}|| Creates a new module {{sl}} based on quotation {{q}}. #} -{#op||module-sigils||(\*)||(S+)|| +{#op||module-sigils||{{q}}||({{s0p}})|| Returns a list of all sigils defined in module {{q}}.#} -{#op||module-symbols||(\*)||(S+)|| +{#op||module-symbols||{{q}}||({{s0p}})|| Returns a list of all symbols defined in module {{q}}.#} -{#op||publish||§ (*)||{{null}}|| -Publishes symbol {{sl}} to the scope of [(\*)](class:kwd). +{#op||publish||{{sl}} {{q}}||{{null}}|| +Publishes symbol {{sl}} to the scope of {{q}}. > > > %sidebar% > > Example

@@ -158,53 +158,53 @@ > >

> Publish symbol [my-local-symbol](class:kwd) to [ROOT](class:kwd) scope: > > `'my-local-symbol ROOT publish` #} -{#op||quote||\*||(\*)|| -Wraps [\*](class:kwd) in a quotation. #} +{#op||quote||{{any}}||({{any}})|| +Wraps {{any}} in a quotation. #} -{#op||quote-bind||\* §||{{null}}|| +{#op||quote-bind||{{any}} {{sl}}||{{null}}|| Quotes {{any}} and binds the quotation to the existing symbol {{sl}}. #} -{#op||quote-define||\* §||{{null}}|| +{#op||quote-define||{{any}} {{sl}}||{{null}}|| Quotes {{any}} and assigns the quotation to the symbol {{sl}}, creating it if not already defined. #} -{#op||raise||(E)||{{null}}|| +{#op||raise||{{e}}||{{null}}|| Raises the error specified via the dictionary {{e}}.#} -{#op||remove-symbol||§||{{null}}|| +{#op||remove-symbol||{{sl}}||{{null}}|| Removes the symbol {{sl}} from the [.min\_symbols](class:file) file. #} -{#op||save-symbol||§||{{null}}|| +{#op||save-symbol||{{sl}}||{{null}}|| Saves the contents of symbol {{sl}} to the [.min\_symbols](class:file) file. #} -{#op||seal||§||{{null}}|| +{#op||seal||{{sl}}||{{null}}|| Seals symbol {{sl}}, so that it cannot be re-assigned. #} -{#op||sigils||{{null}}||(S+)|| +{#op||sigils||{{null}}||({{s0p}})|| Returns a list of all sigils defined in the [ROOT](class:kwd) scope.#} -{#op||source||§||(\*)|| -Display the source code of symbol {{sl}} (if it has been implemented a {{M}} quotation). #} +{#op||source||{{sl}}||{{q}}|| +Display the source code of symbol {{sl}} (if it has been implemented a {{m}} quotation). #} -{#op||stored-symbols||{{null}}||(S+)|| +{#op||stored-symbols||{{null}}||({{s0p}})|| Returns a quotation containing all symbols stored in the [.min\_symbols](class:file) file. #} -{#op||symbols||{{null}}||(S+)|| +{#op||symbols||{{null}}||({{s0p}})|| Returns a list of all symbols defined in the [ROOT](class:kwd) scope.#} -{#op||times||(\*) I||\*?|| +{#op||times||{{q}} {{i}}||{{a0p}}|| Applies the quotation {{q}} {{i}} times.#} -{#op||to-json||(\*)||S|| -Converts a quotation into a JSON string {{s}}.#} +{#op||to-json||{{q}}||{{s}}|| +Converts {{q}} into a JSON string {{s}}.#} -{#op||try||(\*)||\*?|| -Evaluates quotation {{q}} as a try/catch/finally block. +{#op||try||({{q1}} {{q}}{{2}}{{01}} {{q}}{{3}}{{01}})||{{a0p}}|| +Evaluates a quotation as a try/catch/finally block. > -> {{q}} must contain the following elements: +> The must contain the following elements: > -> 1. A quotation containing the code to be evaluated (_try_ block). -> 1. _(optional)_ A quotation containing the code to execute in case of error (_catch_ block). -> 1. _(optional)_ A quotation containing the code to execute after the code has been evaluated, whether an error occurred or not (_finally_ block). +> 1. A quotation {{q1}} containing the code to be evaluated (_try_ block). +> 1. _(optional)_ A quotation {{q2}} containing the code to execute in case of error (_catch_ block). +> 1. _(optional)_ A quotation {{q3}} containing the code to execute after the code has been evaluated, whether an error occurred or not (_finally_ block). > > > %sidebar% > > Example

@@ -217,23 +217,23 @@ > > (format-error puts)

> > (0) > > ) try #} -{#op||unless||(2) (1)||\*?|| -If {{2}} evaluates to {{f}} then evaluates {{1}}.#} +{#op||unless||{{q1}} {{q2}}||{{a0p}}|| +If {{1}} evaluates to {{f}} then evaluates {{2}}.#} -{#op||unquote||(\*)||\*|| +{#op||unquote||{{q}}||{{a0p}}|| Pushes the contents of quotation {{q}} on the stack. #} -{#op||unseal||§||{{null}}|| +{#op||unseal||{{sl}}||{{null}}|| Unseals symbol {{sl}}, so that it can be re-assigned. #} -{#op||version||{{null}}||S|| +{#op||version||{{null}}||{{s}}|| Returns the current min version number. #} -{#op||when||(2) (1)||\*?|| -If {{2}} evaluates to {{t}} then evaluates {{1}}.#} +{#op||when||{{q1}} {{q2}}||{{a0p}}|| +If {{q1}} evaluates to {{t}} then evaluates {{q2}}.#} -{#op||while||(2) (1)||\*?|| -> Executes {{1}} while {{2}} evaluates to {{t}}. +{#op||while||{{q1}} {{q2}}||{{a0p}}|| +> Executes {{q2}} while {{q1}} evaluates to {{t}}. > > > %sidebar% > > Example

@@ -244,6 +244,5 @@ > > 0 :count

> > (count 10 <=) > > (count puts succ @count) while #} -{#op||with||(2) (1)||\*?|| -Applies quotation {{2}} within the scope of {{1}}. #} - +{#op||with||{{q1}} {{q2}}||{{a0p}}|| +Applies quotation {{q1}} within the scope of {{q2}}. #}
M site/contents/_includes/_reference-seq.mdsite/contents/_includes/_reference-seq.md

@@ -70,7 +70,7 @@

{#op||reverse||(1)||(\*)|| Returns a new quotation {{q}} containing all elements of {{1}} in reverse order. #} -{#op||shorten|(\*) I||(\*)|| +{#op||shorten||(\*) I||(\*)|| Returns a quotation containing the first {{i}} values of the input quotation. #} {#op||size||(\*)||I||

@@ -87,5 +87,4 @@ > >

> > (1 9 5 13 16 3 7) '> sort #} {#op||values||(D)||(\*+)|| -Returns a quotation containing all the values of dictionary {{d}}. #} - +Returns a quotation containing all the values of dictionary {{d}}. #}
M site/contents/_includes/_reference-stack.mdsite/contents/_includes/_reference-stack.md

@@ -40,5 +40,4 @@ {#op||unstack||(\*)||\*?||

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.#} - +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

@@ -3,9 +3,11 @@

min includes a small but powerful standard library organized into the following _modules_: {#link-module||lang#} -: Defines the basic language constructs, such as control flow, symbol definition and binding, exception handling, basic stack operators, etc. +: Defines the basic language constructs, such as control flow, symbol definition and binding, exception handling, etc. {#link-module||stack#} : Defines combinators and stack-shufflers like dip, dup, swap, cons, etc. +{#link-module||seq#} +: Defines operators for quotations and dictionaries, like map, filter, reduce, etc. {#link-module||io#} : Provides operators for reading and writing files as well as printing to STDOUT and reading from STDIN. {#link-module||fs#}

@@ -27,56 +29,59 @@ ## Notation

The following notation is used in the signature of all min operators: +### Types and Values + +{{null}} +: No value. {{any}} -: Any value. -[\*?](class:kwd) -: Zero or more values of any type. -B -: A boolean value. +: A value of any type. +{{b}} +: A boolean value +{{i}} +: An integer value. +{{n}} +: A numeric value. +{{s}} +: A string value. +{{sl}} +: A string-like value (string or quoted symbol). {{q}} -: A quotation. -{{1e}} -: The first element on the stack. -{{2e}} -: The second element on the stack. -{{1}} -: The first quotation on the stack. -{{2}} -: The second quotation on the stack. -{{3}} -: The third quotation on the stack. -{{4}} -: The fourth quotation on the stack. +: A quotation (also expressed as parenthesis enclosing other values). +{{qq}} +: Quotation of quotations. {{d}} -: A dictionary quotation. +: A dictionary value. {{e}} : An error dictionary: <pre><code>( (error "MyError") (message "An error occurred") - (symbol "symbol1") ;Optional - (filename "dir1/file1.min") ;Optional - (line 3) ;Optional - (column 13) ;Optional + (symbol "symbol1") + (filename "dir1/file1.min") + (line 3) + (column 13) ) </code></pre> -{{i}} -: An integer value. -{{n}} -: A numeric value. -{{s}} -: A string value. -{{s1}} -: The first string on the stack. -{{s2}} -: The second string on the stack. -{{sp}} -: One or more string values. -{{sl}} -: String-like (a string or quoted sumbol). -{{f}} -: false (boolean type). {{t}} : true (boolean type). -{{null}} -: No value. +{{f}} +: false (boolean type) + +### Suffixes + +The following suffixes can be placed at the end of a value or type to indicate ordering or quantities. + +{{1}} +: The first value of the specified type. +{{2}} +: The second value of the specified type. +{{3}} +: The third value of the specified type. +{{4}} +: The fourth value of the specified type. +{{01}} +: Zero or one. +{{0p}} +: Zero more. +{{1p}} +: One or more