all repos — min @ 4d6a557b01de5a2c87c414fd1db1039ef890eefc

A small but practical concatenative programming language.

Updated docs (ref: #50)
h3rald h3rald@h3rald.com
Wed, 17 Jun 2020 17:25:28 +0200
commit

4d6a557b01de5a2c87c414fd1db1039ef890eefc

parent

bfb9c735c7611d9f60cbaa71e55406a04d3bb9a3

M Min_DeveloperGuide.mdMin_DeveloperGuide.md

@@ -68,6 +68,10 @@ ### Definitions

{@ site/contents/learn-definitions.md || 2 @} +### Scopes + +{@ site/contents/learn-scopes.md || 2 @} + ### Control Flow {@ site/contents/learn-control-flow.md || 2 @}
M site/contents/_defs_.mdsite/contents/_defs_.md

@@ -98,6 +98,7 @@ > * [Data Types](/learn-data-types)

> * [Operators](/learn-operators) > * [Quotations](/learn-quotations) > * [Definitions](/learn-definitions) +> * [Scopes](/learn-scopes) > * [Control Flow](/learn-control-flow) > * [Shell](/learn-shell) > * [Extending min](/learn-extending)
M site/contents/learn-definitions.mdsite/contents/learn-definitions.md

@@ -105,10 +105,10 @@ ...because the `quote` symbol is only defined in the root scope and can therefore be redefined in child scopes.

If you want, you can {#link-operator||lang||seal#} your own symbols so that they may not be redefined using the {#link-operator||lang||bind#} operator or deleted using the {#link-operator||lang||delete#}. -> %info% +> %note% > Note > > The {#link-operator||lang||unseal#} operator can be used to effectively un-seal a previously-sealed symbol. Use with caution! -{#link-learn||control-flow||Control Flow#} +{#link-learn||scopes||Scopes#}
A site/contents/learn-scopes.md

@@ -0,0 +1,60 @@

+----- +content-type: "page" +title: "Scopes" +----- +{@ _defs_.md || 0 @} + +As explained in [Definitions](/learn-definitions), min uses lexical scoping to resolve symbol. A *scope* is an execution context (a symbol table really) that: +* is created while a a new quotation is being dequoted or a dictiionary is created. +* is destroyed after a quotation has been dequoted. +* is attached to a dictionary. + +The main, root-level scope in min can be accessed using the {#link-operator||lang||ROOT#} symbol and it typically contains all symbols and sigils imported from all the standard library modules. The ROOT symbol pushes a module on the stack that references the ROOT scope: + +> %min-terminal% +> [[/Users/h3rald/test]$](class:prompt) ROOT +> { +> <native> :! +> <native> :!= +> ... +> <native> :xor +> <native> :zip +> ;module +> } + +> %note% +> Note +> +> <native> values cannot be retrieved using the {#link-operator||dict||dget#} operator. + +## Accessing the current scope + +You can access the current scope using the {#link-operator||lang||scope#} operator, which pushes a module on the stack that references the current scope. + +Consider the following program: + + {} :innerscope ("This is a test" :test scope @myscope) -> myscope scope-symbols + +In this case: + +1. A new variable called `innerscope` is defined on the ROOT scope. +2. A quotation is dequoted, but its scope is retrieved using the `scope` operator and bound to `innerscope`. +3. After the quotation is dequoted, myscope is accessed and its symbols (`test` in this case) are pushed on the stack using the {#link-operator||lang||scope-symbols#} operator. + +Note that scopes can only be accessed if they are bound to a dictionary, hence the `ROOT` and `scope` operators push a module on the stack, and a module is nothing but a typed dictionary. + +## Dequoting a quotation within the context of a specific scope + +The {#link-operator||lang||with#} operator can be used to dequote a quotation within a specific scope instead of the current one. + +Consider the following program, which leaves `2` on the stack: + + (4 2 minus) {'- :minus} with -> + +In this case, when `with` is pushed on the stack, it will dequote `(4 2 minus)`. Note that the symbol `minus` is defined in the dictionary that will be used by `with` as the current scope, so after `with` is pushed on the stack, the stack contents are: + + 4 2 (-) + +At this points, the {#link-operator||lang||dequote#} operator is pushed on the stack and the subtraction is executed leaving `2` on the stack. + +{#link-learn||control-flow||Control Flow#}
M site/contents/reference-lang.mdsite/contents/reference-lang.md

@@ -381,7 +381,7 @@ > > (count 10 <=)

> > (count puts succ @count) while #} {#op||with||{{q1}} {{q2}}||{{a0p}}|| -Applies quotation {{q1}} within the scope of {{q2}}. +Dequotes a quotation {{q1}} within the scope of {{q2}}. > > %sidebar% > > Example
M site/settings.jsonsite/settings.json

@@ -5,6 +5,6 @@ "templates": "templates",

"temp": "temp", "output": "output", "title": "min language", - "version": "0.19.6", + "version": "0.20.0", "rules": "rules.min" }