all repos — min @ 963c9a0a01ee9f3e578b229af5d8ce3317eb9087

A small but practical concatenative programming language.

Fixed examples.
h3rald h3rald@h3rald.com
Sat, 26 Oct 2024 19:42:25 +0200
commit

963c9a0a01ee9f3e578b229af5d8ce3317eb9087

parent

86026c18dd6b68d0bfa7cfd7661fe2034f35cc61

M site/contents/home.mdsite/contents/home.md

@@ -45,7 +45,7 @@ <p>The following example shows how to find recursively all files in the current folder that were modified in the last hour:</p>

<pre> <code>sys.pwd sys.ls-r (fs.mtime time.now 3600 - >) -seq.filter</code> +filter</code> </pre> <p>The following example shows how to calculate the factorial of 5 using the <code>linrec</code> combinator:</p> <pre>
M site/contents/learn-control-flow.mdsite/contents/learn-control-flow.md

@@ -75,8 +75,8 @@ (

(fs.size) (stack.pop 0) ) try - ) seq.map - 1 (+) seq.reduce + ) map + 1 (+) reduce This program calculates the size in bytes of all files included in the current directory. Because the {#link-operator||fs||size#} symbol throws an error if the argument provided is not a file (for example, if it is a directory), the `try` symbol is used to remove the error from the stack and push `0` on the stack instead.
M site/contents/learn-quotations.mdsite/contents/learn-quotations.md

@@ -8,7 +8,7 @@ Quotations are the most important thing to understand in min. Besides being the data type used for lists, they are also used to delimit blocks of min code that is not going to be immediately executed.

Consider for example the following min code which returns all the files present in the current folder sorted by name: - sys.pwd sys.ls (fs.type "file" ==) seq.filter '> seq.sort + sys.pwd sys.ls (fs.type "file" ==) filter '> sort The symbol {#link-operator||seq||filter#} takes two quotations as arguments -- the first quotation on the stack is applied to all the elements of the second quotation on the stack, to determine which elements of the second quotation will be part of the resulting quotation. This is an example of how quotations can be used both as lists and programs.

@@ -20,9 +20,9 @@

1. The `sys.pwd` symbol is pushed on the stack, and it is immediately evaluated to the full path to the current directory. 2. The `sys.ls` symbol is pushed on the stack, it consumes the string already on the stack and returns a quotation containing all files and directories within the current directory. 3. The quotation `(fs.type 'file ==)` is pushed on the stack. It is treated exactly like a list of data and it is not evaluated. -4. The `seq.filter` symbol is pushed on the stack. This symbol takes two quotations as input, and applies the result of the first quotation on the stack (`(fs.type "file" ==)`) to all elements of the second quotation of the stack (the list of files and directories), returning a new quotation containing only those elements of the second quotation on the stack that satisfy the result of the first quotation. In this case, it returns a new quotation containing only files. +4. The `filter` symbol is pushed on the stack. This symbol takes two quotations as input, and applies the result of the first quotation on the stack (`(fs.type "file" ==)`) to all elements of the second quotation of the stack (the list of files and directories), returning a new quotation containing only those elements of the second quotation on the stack that satisfy the result of the first quotation. In this case, it returns a new quotation containing only files. 5. `'>` is pushed on the stack. The `'` sigil can be used instead of the `quote` symbol to quote a single symbol, `>` in this case. In other words, it is instantly evaluated to the quotation `(>)`. -6. The symbol `seq.sort` is pushed on the stack. This symbol, like `seq.filter`, takes two quotations as input, and applies the first quotation to each element of the second quotation, effectively sorting each element of the second quotation using the predicate expressed by the first quotation. In this case, all files are sorted by name in ascending order. +6. The symbol `sort` is pushed on the stack. This symbol, like `filter`, takes two quotations as input, and applies the first quotation to each element of the second quotation, effectively sorting each element of the second quotation using the predicate expressed by the first quotation. In this case, all files are sorted by name in ascending order. > %tip% > Tip

@@ -36,11 +36,11 @@ When a quotation is created, it is treated as data, no matter what it contains: it is placed on the stack, like an integer or a string would. However, unlike other data types, a quotation can be evaluated in certain situations and when it happens its contents are pushed on the stack.

Consider the following program: - (1 2 3 4 5 6 7) (odd?) seq.filter + (1 2 3 4 5 6 7) (odd?) filter This program returns a new quotation containing all odd numbers contained in quotation `(1 2 3 4 5 6 7)`. -In this case, the second quotation is used to _quote_ the symbol `odd?` so that instead of being executed immediately, it will be executed by the symbol `seq.filter` on each element of the first quotation. In this way, we may say that `(odd?)` is _dequoted_ by the symbol `seq.filter`. +In this case, the second quotation is used to _quote_ the symbol `odd?` so that instead of being executed immediately, it will be executed by the symbol `filter` on each element of the first quotation. In this way, we may say that `(odd?)` is _dequoted_ by the symbol `filter`. The symbol {#link-global-operator||dequote#} or its alias `->` can be used to dequote a quotation by pushing all its elements on the main stack. Essentially, this *executes* the quotation in the current context.
M site/contents/learn.mdsite/contents/learn.md

@@ -11,7 +11,7 @@

If not, well, here's how a short min program looks like: ; This is a comment - (1 2 3 4 5) (stack.dup *) seq.map + (1 2 3 4 5) (stack.dup *) map #| This is a... ...multiline comment |#

@@ -23,7 +23,7 @@ Let's see how it works:

1. First, a list containing the first five integers is pushed on the stack. 2. Then, another list containing two symbols (`stack.dup` and `*`) is pushed on the stack. This constitutes a quoted program which, when executed duplicates the first element on the stack &mdash; this is done by `stack.dup`&mdash; and then multiplies &mdash; with `*`&mdash; the two elements together. -3. Finally, the symbol `seq.map` is pushed on the stack. Map takes a list of elements and a quoted program and applies the program to each element. +3. Finally, the symbol `map` is pushed on the stack. Map takes a list of elements and a quoted program and applies the program to each element. Note that:
M site/contents/reference-global.mdsite/contents/reference-global.md

@@ -241,7 +241,7 @@ > > Example

> > > > The following program leaves `(2)` on the stack: > > -> > (1 2 "test") ("test" "a" true 1) seq.difference #} +> > (1 2 "test") ("test" "a" true 1) difference #} {#op||div||{{i1}} {{i2}}||{{i3}}|| Divides {{i1}} by {{i2}} (integer division). #}

@@ -304,7 +304,7 @@ > >

> > The following program leaves `(2 6 8 12)` on the stack: > > > > (1 37 34 2 6 8 12 21) -> > (stackdup 20 < stack.swap even? and) seq.filter #} +> > (stackdup 20 < stack.swap even? and) filter #} {#op||find||{{q1}} {{q2}}||{{i}}|| > Returns the index of the first element within {{q1}} that satisfies predicate {{q2}}, or -1 if no element satisfies it.

@@ -315,7 +315,7 @@ > >

> > The following program leaves `3` on the stack: > > > > (1 2 4 8 16) -> > (5 >) seq.find #} +> > (5 >) find #} {#op||first||{{q}}||{{any}}|| Returns the first element of {{q}}. #}

@@ -329,7 +329,7 @@ > >

> > The following program leaves `(1 2 3 4 5 6 7 8)` on the stack: > > > > (1 (2 3 4) 5 (6 7) 8) -> > seq.flatten #} +> > flatten #} {#op||float||{{any}}||{{flt}}|| > Converts {{any}} to a float value based on the following rules:

@@ -407,7 +407,7 @@ > >

> > The following program leaves `(1 2 3)` on the stack: > > > > (1 () () () 2 () 3) -> > seq.harvest #} +> > harvest #} {#op||help||{{sl}}||{{none}}|| Prints the help text for {{sl}}, if available. #}

@@ -477,7 +477,7 @@ > > Example

> > > > The following code (executed in a directory called '/Users/h3rald/Development/min' containing 19 files): > > -> > `"Directory '$1' includes $2 files." (sys.pwd (sys.pwd sys.ls 'fs.file? seq.filter size)) apply interpolate` +> > `"Directory '$1' includes $2 files." (sys.pwd (sys.pwd sys.ls 'fs.file? filter size)) apply interpolate` > > > > produces: > >

@@ -491,7 +491,7 @@ > > Example

> > > > The following program leaves `(1 "test")` on the stack: > > -> > (1 2 "test") ("test" "a" true 1) seq.intersection #} +> > (1 2 "test") ("test" "a" true 1) intersection #} {#op||join||{{q}} {{sl}}||{{s}}|| Joins the elements of {{q}} using separator {{sl}}, producing {{s}}.#}

@@ -568,7 +568,7 @@ > >

> > The following program leaves `35` on the stack: > > > > (1 3 5) -> > (stack.dup *) (+) seq.map-reduce #} +> > (stack.dup *) (+) map-reduce #} {#op||match?||{{s1}} {{s2}}||{{b}}|| > Returns {{t}} if {{s2}} matches {{s1}}, {{f}} otherwise.

@@ -669,7 +669,7 @@ > >

> > The following program leaves `(1 3 5) (2 4 6)` on the stack: > > > > (1 2 3 4 5 6) -> > (odd?) seq.partition #} +> > (odd?) partition #} {#op||pred||{{i1}}||{{i2}}|| Returns the predecessor of {{i1}}.#}

@@ -770,7 +770,7 @@ > >

> > The following program leaves `120` on the stack: > > > > (1 2 3 4 5) -> > 1 (*) seq.reduce #} +> > 1 (*) reduce #} {#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`)#}

@@ -950,7 +950,7 @@ > >

> > The following program leaves `(3 4 5)` on the stack: > > > > (1 2 3 4 5 6) -> > 2 4 seq.slice #} +> > 2 4 slice #} {#op||sort||{{q1}} {{q2}}||{{q3}}|| > Sorts all elements of {{q1}} according to predicate {{q2}}.

@@ -960,7 +960,7 @@ > > Example

> > > > The following program leaves `(1 3 5 7 9 13 16)` on the stack: > > -> > (1 9 5 13 16 3 7) '> seq.sort #} +> > (1 9 5 13 16 3 7) '> sort #} {#op||source||{{sl}}||{{q}}|| Display the source code of symbol {{sl}} (if it has been implemented a {{m}} quotation). #}

@@ -1006,7 +1006,7 @@ > > Example

> > > > The following program leaves `(true "a" 2)` on the stack: > > -> > (1 2 "test") ("test" "a" true 1) seq.symmetric-difference #} +> > (1 2 "test") ("test" "a" true 1) symmetric-difference #} {#op||take||{{q1}} {{i}}||{{q2}}|| Returns a quotation {{q2}} containing the first _n_ values of the input quotation {{q1}}, or {{q1}} itself if {{i}} is greater than the length of {{q1}}. #}

@@ -1104,7 +1104,7 @@ > > Example

> > > > The following program leaves `(true 1 "test" "a" 2)` on the stack: > > -> > (1 2 "test") ("test" "a" true 1) seq.union #} +> > (1 2 "test") ("test" "a" true 1) union #} {#op||unless||{{q1}} {{q2}}||{{a0p}}|| If {{1}} evaluates to {{f}} then evaluates {{2}}.#}