all repos — min @ ed0ce1f1b5700ab5d9c1c260cb3edf399fd94e8c

A small but practical concatenative programming language.

Stylesheet improvements; documented operators and quotations.
h3rald h3rald@h3rald.com
Sat, 29 Jul 2017 21:46:01 +0200
commit

ed0ce1f1b5700ab5d9c1c260cb3edf399fd94e8c

parent

617ef6e735550975bc331fa0af66457f6e726b3b

M site/assets/styles/min-lang.csssite/assets/styles/min-lang.css

@@ -3,7 +3,7 @@ --primary-foreground:#89968B;

--primary-background:#262625; --secondary-background: #474745; --primary-accent:#4BAA76; - --secondary-accent:#3A4C4B; + --secondary-accent:#2B4737; } body {

@@ -23,6 +23,18 @@ .pure-g [class *= "pure-u"] {

font-family: 'Lato', sans-serif; } +tr td, th { + border: 1px solid var(--secondary-background); +} + +td, th { + padding: 5px; +} + +th { + background: var(--secondary-accent); +} + a, a:visited { text-decoration: none; color: var(--primary-accent);

@@ -45,6 +57,13 @@ .luxbar-menu-light .active, .luxbar-menu-light .luxbar-item:hover,

.luxbar-menu-light .active a, .luxbar-menu-light .luxbar-item:hover a { background: var(--primary-background); color: var(--primary-accent); +} + + +.luxbar-menu-light .luxbar-hamburger span, +.luxbar-menu-light .luxbar-hamburger span::before, +.luxbar-menu-light .luxbar-hamburger span::after { + background-color: var(--primary-foreground); } .pure-button-primary, .pure-button-selected, a.pure-button-primary, a.pure-button-selected {

@@ -199,4 +218,4 @@ font-size: 80%;

text-align: center; margin: auto; padding: 5px; -}+}
M site/contents/_includes/_defs_.mdsite/contents/_includes/_defs_.md

@@ -77,9 +77,11 @@ >

> See [$2](#op-$2). #} +{# link-page => [$2](/$1/) #} + {# link-module => [`$1` Module](/reference-$1/) #} -{# link-operator => [`$2`](/reference-$1/$2) #} +{# link-operator => [`$2`](/reference-$1#op-$2) #} {# link-learn => → Continue to [*$2*](/learn-$1) #}

@@ -92,4 +94,4 @@ > * [Operators](/learn-operators)

> * [Quotations](/learn-quotations) > * [Variables](/learn-variables) > * [Shell](/learn-shell) -}}+}}
M site/contents/_includes/_learn-operators.mdsite/contents/_includes/_learn-operators.md

@@ -1,2 +1,57 @@

{@ _defs_.md || 0 @} -Coming soon... + +Every min program needs _operators_ to: + +* Manipulate elements on the stack +* Perform operations on data +* Provide side effects (read/print to standard input/output/files, etc.) + +There are two types of operators: _symbols_ and _sigils_. + +_Symbols_ are the most common type of operator. A min symbol is a single word that is either provided by one of the predefined min {#link-page||reference||modules#} like `dup` or `.` or defined by the user. User-defined symbols must: + +* Start with a letter or an underscore (\_). +* Contain zero or more letters, numbers and/or any of the following characters: `/ ! ? + * . _ -` + +It is possible to define symbols using the {#link-operator||lang||define#} symbol. The following min program defines a new symbol called square that duplicates the first element on the stack and multiplies the two elements: + + (dup *) square define + +Besides symbols, min provides a set of predefined _sigils_ for commonly-used symbols. For example, the previous definition could be rewritten as follows using sigils: + + (dup *) :square + +A sigil like `:` can be prepended to a single-word string instead of using the corresponding symbol. Essentially, sigils are nothing more than syntactic sugar. Currently min provides the following sigils: + ++ +: Alias for {#link-operator||lang||module#}. +~ +: Alias for {#link-operator||lang||delete#}. +' +: Alias for {#link-operator||lang||quote#}. +\: +: Alias for {#link-operator||lang||define#}. +^ +: Alias for {#link-operator||lang||call#}. +/ +: Alias for {#link-operator||lang||dget#}. +% +: Alias for {#link-operator||lang||dset#}. +@ +: Alias for {#link-operator||lang||bind#}. +> +: Alias for {#link-operator||lang||save-symbol#}. +< +: Alias for {#link-operator||lang||load-symbol#}. +&#61; +: Alias for {#link-operator||lang||quote-bind#}. +\# +: Alias for {#link-operator||lang||quote-define#}. +! +: Alias for {#link-operator||sys||system#}. +& +: Alias for {#link-operator||sys||run#}. +$ +: Alias for {#link-operator||sys||get-env#}. + +{#link-learn||quotations||Quotations#}
M site/contents/_includes/_learn-quotations.mdsite/contents/_includes/_learn-quotations.md

@@ -1,2 +1,80 @@

{@ _defs_.md || 0 @} -Coming soon... + +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: + + . ls (ftype 'file ==) filter + +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. + +Let's examine this program step-by-step: + +{{fdlist => ("dir1" "dir2" file1.txt "file2.txt" "file3.md" "file4.md")}} +{{flist => ("file1.txt" "file2.txt" "file3.md" "file4.md")}} + +<table> + <tr> + <th>Element</th><th>Stack</th><th>Explanation</th> + </tr> + <tr> + <td> + <code>.</code> + </td> + <td> + <ol> + <li><code>"/Users/h3rald/test"</code></li> + <ol> + </td> + <td> + The symbol <code>.</code> is pushed on the stack, and it is resolved to the full path to the current folder. + </td> + </tr> + <tr> + <td> + <code>ls</code> + </td> + <td> + <ol> + <li><code>{{fdlist}}</code></li> + </ol> + </td> + <td> + The symbol <code>ls</code> is pushed on the stack, and a list containing all files and folders in the current folder is pushed on the stack. + </td> + </tr> + <tr> + <td> + <code>(ftype 'file ==)</code> + </td> + <td> + <ol> + <li><code>(ftype 'file ==)</code></li> + <li><code>{{fdlist}}</code></li> + </ol> + </td> + <td> + The quotation <code>(ftype 'file ==)</code> is pushed on the stack. + </td> + </tr> + <tr> + <td> + <code>filter</code> + </td> + <td> + <ol> + <li><code>{{flist}}</code></li> + </ol> + </td> + <td> + The symbol <code>filter</code> is pushed on the stack, and an array containing only the files present in the current folder is pushed on the stack. + </td> + </tr> +</table> + +> %tip% +> Tip +> +> The {{#link-module||seq#}} provides several symbols to work with quotations in a functional way. + +{#link-learn||variables||Variables#}
M site/contents/_includes/_learn.mdsite/contents/_includes/_learn.md

@@ -6,6 +6,7 @@ *min* is a stack-based, concatenative programming language that uses postfix notation. If you already know [Forth](http://www.forth.org/), [Factor](http://factorcode.org/) or [Joy](http://www.kevinalbrecht.com/code/joy-mirror/), or if you ever used an [RPN](https://en.wikipedia.org/wiki/Reverse_Polish_notation) calculator, then min will look somewhat familiar to you.

If not, well, here's how a short min program looks like: + ; This is a comment (1 2 3 4 5) (dup *) map This program returns a list containing the square values of the first five integer numbers:
M site/rules.minsite/rules.min

@@ -53,6 +53,18 @@ ((".md" ext ==) (process-md-content))

) case ) :process-content +( + (dict) expect -> =meta + "" :contents + " - Processing CSS file: $1" ((meta /path)) => % notice + meta ( + (input-fread @contents meta) + (=temp contents preprocess-css @contents temp) + (contents %contents) + ) tap + output-fwrite +) :process-css-asset + ;Main contents ( (dict) expect ->

@@ -62,4 +74,12 @@ ((/id "^_includes" match) ()) ;Ignore files starting with underscore.

((true) (process-content set-destination output-fwrite)) ) case ) foreach -assets (copy2output) foreach + +assets ( + (dict) expect -> + dup + ( + ((/ext ".css" match) (process-css-asset)) + ((true) (copy2output)) + ) case +) foreach