init commit again

This commit is contained in:
Peter
2023-11-01 09:29:33 +01:00
parent 448147e7da
commit d6c745207b
250 changed files with 15552 additions and 1 deletions

View File

@@ -0,0 +1,269 @@
### Binding
[
Type environments Alias envs
Datatype identifiers Alias ids
Funcon identifier-tagged Alias id-tagged
Funcon fresh-identifier
Entity environment Alias env
Funcon initialise-binding
Funcon bind-value Alias bind
Funcon unbind
Funcon bound-directly
Funcon bound-value Alias bound
Funcon closed
Funcon scope
Funcon accumulate
Funcon collateral
Funcon bind-recursively
Funcon recursive
]
Meta-variables
T <: values
#### Environments
Type
environments ~> maps(identifiers, values?)
Alias
envs = environments
/*
An environment represents bindings of identifiers to values.
Mapping an identifier to `( )` represents that its binding is hidden.
Circularity in environments (due to recursive bindings) is represented using
bindings to cut-points called `links`. Funcons are provided for making
declarations recursive and for referring to bound values without explicit
mention of links, so their existence can generally be ignored.
*/
Datatype
identifiers ::= {_:strings} | identifier-tagged(_:identifiers, _:values)
Alias
ids = identifiers
Alias
id-tagged = identifier-tagged
/*
An identifier is either a string of characters, or an identifier tagged with
some value (e.g., with the identifier of a namespace).
*/
Funcon
fresh-identifier : =>identifiers
/*
`fresh-identifier` computes an identifier distinct from all previously
computed identifiers.
*/
Rule
fresh-identifier ~> identifier-tagged("generated", fresh-atom)
#### Current bindings
Entity
environment(_:environments) |- _ ---> _
Alias
env = environment
/*
The environment entity allows a computation to refer to the current bindings
of identifiers to values.
*/
Funcon
initialise-binding(X:=>T) : =>T
~> initialise-linking(initialise-generating(closed(X)))
/*
`initialise-binding(X)` ensures that `X` does not depend on non-local bindings.
It also ensures that the linking entity (used to represent potentially cyclic
bindings) and the generating entity (for creating fresh identifiers) are
initialised.
*/
Funcon
bind-value(I:identifiers, V:values) : =>environments
~> { I |-> V }
Alias
bind = bind-value
/*
`bind-value(I, X)` computes the environment that binds only `I` to the value
computed by `X`.
*/
Funcon
unbind(I:identifiers) : =>environments
~> { I |-> ( ) }
/*
`unbind(I)` computes the environment that hides the binding of `I`.
*/
Funcon
bound-directly(_:identifiers) : =>values
/*
`bound-directly(I)` returns the value to which `I` is currently bound, if any,
and otherwise fails.
`bound-directly(I)` does *not* follow links. It is used only in connection with
recursively-bound values when references are not encapsulated in abstractions.
*/
Rule
lookup(Rho, I) ~> (V:values)
--------------------------------------------------------
environment(Rho) |- bound-directly(I:identifiers) ---> V
Rule
lookup(Rho, I) ~> ( )
-----------------------------------------------------------
environment(Rho) |- bound-directly(I:identifiers) ---> fail
Funcon
bound-value(I:identifiers) : =>values
~> follow-if-link(bound-directly(I))
Alias
bound = bound-value
/*
`bound-value(I)` inspects the value to which `I` is currently bound, if any,
and otherwise fails. If the value is a link, `bound-value(I)` returns the
value obtained by following the link, if any, and otherwise fails. If the
inspected value is not a link, `bound-value(I)` returns it.
`bound-value(I)` is used for references to non-recursive bindings and to
recursively-bound values when references are encapsulated in abstractions.
*/
#### Scope
Funcon
closed(X:=>T) : =>T
/*
`closed(X)` ensures that `X` does not depend on non-local bindings.
*/
Rule
environment(map( )) |- X ---> X'
-------------------------------------------
environment(_) |- closed(X) ---> closed(X')
Rule
closed(V:T) ~> V
Funcon
scope(_:environments, _:=>T) : =>T
/*
`scope(D,X)` executes `D` with the current bindings, to compute an environment
`Rho` representing local bindings. It then executes `X` to compute the result,
with the current bindings extended by `Rho`, which may shadow or hide previous
bindings.
`closed(scope(Rho, X))` ensures that `X` can reference only the bindings
provided by `Rho`.
*/
Rule
environment(map-override(Rho1, Rho0)) |- X ---> X'
---------------------------------------------------------------------
environment(Rho0) |- scope(Rho1:environments, X) ---> scope(Rho1, X')
Rule
scope(_:environments, V:T) ~> V
Funcon
accumulate(_:(=>environments)*) : =>environments
/*
`accumulate(D1, D2)` executes `D1` with the current bindings, to compute an
environment `Rho1` representing some local bindings. It then executes `D2` to
compute an environment `Rho2` representing further local bindings, with the
current bindings extended by `Rho1`, which may shadow or hide previous
current bindings. The result is `Rho1` extended by `Rho2`, which may shadow
or hide the bindings of `Rho1`.
`accumulate(_, _)` is associative, with `map( )` as unit, and extends to any
number of arguments.
*/
Rule
D1 ---> D1'
-------------------------------------------
accumulate(D1, D2) ---> accumulate(D1', D2)
Rule
accumulate(Rho1:environments, D2) ~> scope(Rho1, map-override(D2, Rho1))
Rule
accumulate( ) ~> map( )
Rule
accumulate(D1) ~> D1
Rule
accumulate(D1, D2, D+) ~> accumulate(D1, accumulate(D2, D+))
Funcon
collateral(Rho*:environments*) : =>environments
~> checked map-unite(Rho*)
/*
`collateral(D1, ...)` pre-evaluates its arguments with the current bindings,
and unites the resulting maps, which fails if the domains are not pairwise
disjoint.
`collateral(D1, D2)` is associative and commutative with `map( )` as unit,
and extends to any number of arguments.
*/
#### Recurse
Funcon
bind-recursively(I:identifiers, E:=>values) : =>environments
~> recursive({I}, bind-value(I, E))
/*
`bind-recursively(I, E)` binds `I` to a link that refers to the value of `E`,
representing a recursive binding of `I` to the value of `E`.
Since `bound-value(I)` follows links, it should not be executed during the
evaluation of `E`.
*/
Funcon
recursive(SI:sets(identifiers), D:=>environments) : =>environments
~> re-close(bind-to-forward-links(SI), D)
/*
`recursive(SI, D)` executes `D` with potential recursion on the bindings of
the identifiers in the set `SI` (which need not be the same as the set of
identifiers bound by `D`).
*/
Auxiliary Funcon
re-close(M:maps(identifiers, links), D:=>environments) : =>environments
~> accumulate(scope(M, D), sequential(set-forward-links(M), map( )))
/*
`re-close(M, D)` first executes `D` in the scope `M`, which maps identifiers
to freshly allocated links. This computes an environment `Rho` where the bound
values may contain links, or implicit references to links in abstraction
values. It then sets the link for each identifier in the domain of `M` to
refer to its bound value in `Rho`, and returns `Rho` as the result.
*/
Auxiliary Funcon
bind-to-forward-links(SI:sets(identifiers)) : =>maps(identifiers, links)
~> map-unite(interleave-map(bind-value(given, fresh-link(values)),
set-elements(SI)))
/*
`bind-to-forward-links(SI)` binds each identifier in the set `SI` to a
freshly allocated link.
*/
Auxiliary Funcon
set-forward-links(M:maps(identifiers, links)) : =>null-type
~> effect(interleave-map(set-link(map-lookup(M, given), bound-value(given)),
set-elements(map-domain(M))))
/*
For each identifier `I` in the domain of `M`, `set-forward-links(M)` sets the
link to which `I` is mapped by `M` to the current bound value of `I`.
*/

View File

@@ -0,0 +1,320 @@
---
layout: default
title: "Binding"
parent: Normal
ancestor: Funcons-beta
---
[Funcons-beta] : [Binding.cbs]
-----------------------------
### Binding
<div class="highlighter-rouge"><pre class="highlight"><code>[
<i class="keyword">Type</i> <span class="name"><a href="#Name_environments">environments</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_envs">envs</a></span>
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_identifiers">identifiers</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_ids">ids</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_identifier-tagged">identifier-tagged</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_id-tagged">id-tagged</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_fresh-identifier">fresh-identifier</a></span>
<i class="keyword">Entity</i> <span class="name"><a href="#Name_environment">environment</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_env">env</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_initialise-binding">initialise-binding</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bind-value">bind-value</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_bind">bind</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_unbind">unbind</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bound-directly">bound-directly</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bound-value">bound-value</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_bound">bound</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_closed">closed</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_scope">scope</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_accumulate">accumulate</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_collateral">collateral</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bind-recursively">bind-recursively</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_recursive">recursive</a></span>
]</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
<span id="PartVariable_T"><i class="var">T</i></span> <: <span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span></code></pre></div>
#### Environments
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
<span class="name"><span id="Name_environments">environments</span></span> ~> <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span><sup class="sup">?</sup>)
<i class="keyword">Alias</i>
<span class="name"><span id="Name_envs">envs</span></span> = <span class="name"><a href="#Name_environments">environments</a></span></code></pre></div>
An environment represents bindings of identifiers to values.
Mapping an identifier to <code>( )</code> represents that its binding is hidden.
Circularity in environments (due to recursive bindings) is represented using
bindings to cut-points called <code><span class="name"><a href="../Linking/index.html#Name_links">links</a></span></code>. Funcons are provided for making
declarations recursive and for referring to bound values without explicit
mention of links, so their existence can generally be ignored.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
<span class="name"><span id="Name_identifiers">identifiers</span></span> ::= {_:<span class="name"><a href="../../../Values/Composite/Strings/index.html#Name_strings">strings</a></span>} | <span id="Name_identifier-tagged">identifier-tagged</span>(_:<span class="name"><a href="#Name_identifiers">identifiers</a></span>, _:<span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>)
<i class="keyword">Alias</i>
<span class="name"><span id="Name_ids">ids</span></span> = <span class="name"><a href="#Name_identifiers">identifiers</a></span></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Alias</i>
<span class="name"><span id="Name_id-tagged">id-tagged</span></span> = <span class="name"><a href="#Name_identifier-tagged">identifier-tagged</a></span></code></pre></div>
An identifier is either a string of characters, or an identifier tagged with
some value (e.g., with the identifier of a namespace).
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_fresh-identifier">fresh-identifier</span></span> : =><span class="name"><a href="#Name_identifiers">identifiers</a></span></code></pre></div>
<code><span class="name"><a href="#Name_fresh-identifier">fresh-identifier</a></span></code> computes an identifier distinct from all previously
computed identifiers.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_fresh-identifier">fresh-identifier</a></span> ~> <span class="name"><a href="#Name_identifier-tagged">identifier-tagged</a></span>("generated", <span class="name"><a href="../Generating/index.html#Name_fresh-atom">fresh-atom</a></span>)</code></pre></div>
#### Current bindings
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Entity</i>
<span class="ent-name"><span id="Name_environment">environment</span></span>(_:<span class="name"><a href="#Name_environments">environments</a></span>) |- _ ---> _</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Alias</i>
<span class="name"><span id="Name_env">env</span></span> = <span class="name"><a href="#Name_environment">environment</a></span></code></pre></div>
The environment entity allows a computation to refer to the current bindings
of identifiers to values.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_initialise-binding">initialise-binding</span></span>(<span id="Variable306_X"><i class="var">X</i></span>:=><span id="Variable311_T"><i class="var">T</i></span>) : =><span id="Variable326_T"><i class="var">T</i></span>
~> <span class="name"><a href="../Linking/index.html#Name_initialise-linking">initialise-linking</a></span>(<span class="name"><a href="../Generating/index.html#Name_initialise-generating">initialise-generating</a></span>(<span class="name"><a href="#Name_closed">closed</a></span>(<a href="#Variable306_X"><i class="var">X</i></a>)))</code></pre></div>
<code><span class="name"><a href="#Name_initialise-binding">initialise-binding</a></span>(<i class="var">X</i>)</code> ensures that <code><i class="var">X</i></code> does not depend on non-local bindings.
It also ensures that the linking entity (used to represent potentially cyclic
bindings) and the generating entity (for creating fresh identifiers) are
initialised.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_bind-value">bind-value</span></span>(<span id="Variable401_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span id="Variable410_V"><i class="var">V</i></span>:<span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> { <a href="#Variable401_I"><i class="var">I</i></a> |-> <a href="#Variable410_V"><i class="var">V</i></a> }
<i class="keyword">Alias</i>
<span class="name"><span id="Name_bind">bind</span></span> = <span class="name"><a href="#Name_bind-value">bind-value</a></span></code></pre></div>
<code><span class="name"><a href="#Name_bind-value">bind-value</a></span>(<i class="var">I</i>, <i class="var">X</i>)</code> computes the environment that binds only <code><i class="var">I</i></code> to the value
computed by <code><i class="var">X</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_unbind">unbind</span></span>(<span id="Variable509_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> { <a href="#Variable509_I"><i class="var">I</i></a> |-> ( ) }</code></pre></div>
<code><span class="name"><a href="#Name_unbind">unbind</a></span>(<i class="var">I</i>)</code> computes the environment that hides the binding of <code><i class="var">I</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_bound-directly">bound-directly</span></span>(_:<span class="name"><a href="#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span></code></pre></div>
<code><span class="name"><a href="#Name_bound-directly">bound-directly</a></span>(<i class="var">I</i>)</code> returns the value to which <code><i class="var">I</i></code> is currently bound, if any,
and otherwise fails.
<code><span class="name"><a href="#Name_bound-directly">bound-directly</a></span>(<i class="var">I</i>)</code> does *not* follow links. It is used only in connection with
recursively-bound values when references are not encapsulated in abstractions.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_lookup">lookup</a></span>(<a href="#Variable711_Rho"><i class="var">Rho</i></a>, <a href="#Variable728_I"><i class="var">I</i></a>) ~> (<span id="Variable692_V"><i class="var">V</i></span>:<span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>)
--------------------------------------------------------
<span class="ent-name"><a href="#Name_environment">environment</a></span>(<span id="Variable711_Rho"><i class="var">Rho</i></span>) |- <span class="name"><a href="#Name_bound-directly">bound-directly</a></span>(<span id="Variable728_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>) ---> <a href="#Variable692_V"><i class="var">V</i></a>
<i class="keyword">Rule</i>
<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_lookup">lookup</a></span>(<a href="#Variable782_Rho"><i class="var">Rho</i></a>, <a href="#Variable799_I"><i class="var">I</i></a>) ~> ( )
-----------------------------------------------------------
<span class="ent-name"><a href="#Name_environment">environment</a></span>(<span id="Variable782_Rho"><i class="var">Rho</i></span>) |- <span class="name"><a href="#Name_bound-directly">bound-directly</a></span>(<span id="Variable799_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>) ---> <span class="name"><a href="../../Abnormal/Failing/index.html#Name_fail">fail</a></span></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_bound-value">bound-value</span></span>(<span id="Variable823_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>
~> <span class="name"><a href="../Linking/index.html#Name_follow-if-link">follow-if-link</a></span>(<span class="name"><a href="#Name_bound-directly">bound-directly</a></span>(<a href="#Variable823_I"><i class="var">I</i></a>))
<i class="keyword">Alias</i>
<span class="name"><span id="Name_bound">bound</span></span> = <span class="name"><a href="#Name_bound-value">bound-value</a></span></code></pre></div>
<code><span class="name"><a href="#Name_bound-value">bound-value</a></span>(<i class="var">I</i>)</code> inspects the value to which <code><i class="var">I</i></code> is currently bound, if any,
and otherwise fails. If the value is a link, <code><span class="name"><a href="#Name_bound-value">bound-value</a></span>(<i class="var">I</i>)</code> returns the
value obtained by following the link, if any, and otherwise fails. If the
inspected value is not a link, <code><span class="name"><a href="#Name_bound-value">bound-value</a></span>(<i class="var">I</i>)</code> returns it.
<code><span class="name"><a href="#Name_bound-value">bound-value</a></span>(<i class="var">I</i>)</code> is used for references to non-recursive bindings and to
recursively-bound values when references are encapsulated in abstractions.
#### Scope
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_closed">closed</span></span>(<span id="Variable991_X"><i class="var">X</i></span>:=><span id="Variable996_T"><i class="var">T</i></span>) : =><span id="Variable1011_T"><i class="var">T</i></span></code></pre></div>
<code><span class="name"><a href="#Name_closed">closed</a></span>(<i class="var">X</i>)</code> ensures that <code><i class="var">X</i></code> does not depend on non-local bindings.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="ent-name"><a href="#Name_environment">environment</a></span>(<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map">map</a></span>( )) |- <a href="#Variable1113_X"><i class="var">X</i></a> ---> <span id="Variable1085_X'"><i class="var">X&prime;</i></span>
-------------------------------------------
<span class="ent-name"><a href="#Name_environment">environment</a></span>(_) |- <span class="name"><a href="#Name_closed">closed</a></span>(<span id="Variable1113_X"><i class="var">X</i></span>) ---> <span class="name"><a href="#Name_closed">closed</a></span>(<a href="#Variable1085_X'"><i class="var">X&prime;</i></a>)
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_closed">closed</a></span>(<span id="Variable1145_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> <a href="#Variable1145_V"><i class="var">V</i></a></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_scope">scope</span></span>(_:<span class="name"><a href="#Name_environments">environments</a></span>, _:=><span id="Variable1183_T"><i class="var">T</i></span>) : =><span id="Variable1199_T"><i class="var">T</i></span></code></pre></div>
<code><span class="name"><a href="#Name_scope">scope</a></span>(<i class="var">D</i>,<i class="var">X</i>)</code> executes <code><i class="var">D</i></code> with the current bindings, to compute an environment
<code><i class="var">Rho</i></code> representing local bindings. It then executes <code><i class="var">X</i></code> to compute the result,
with the current bindings extended by <code><i class="var">Rho</i></code>, which may shadow or hide previous
bindings.
<code><span class="name"><a href="#Name_closed">closed</a></span>(<span class="name"><a href="#Name_scope">scope</a></span>(<i class="var">Rho</i>, <i class="var">X</i>))</code> ensures that <code><i class="var">X</i></code> can reference only the bindings
provided by <code><i class="var">Rho</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="ent-name"><a href="#Name_environment">environment</a></span>(<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-override">map-override</a></span>(<a href="#Variable1422_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></a>, <a href="#Variable1404_Rho0"><i class="var">Rho<sub class="sub">0</sub></i></a>)) |- <a href="#Variable1430_X"><i class="var">X</i></a> ---> <span id="Variable1391_X'"><i class="var">X&prime;</i></span>
---------------------------------------------------------------------
<span class="ent-name"><a href="#Name_environment">environment</a></span>(<span id="Variable1404_Rho0"><i class="var">Rho<sub class="sub">0</sub></i></span>) |- <span class="name"><a href="#Name_scope">scope</a></span>(<span id="Variable1422_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></span>:<span class="name"><a href="#Name_environments">environments</a></span>, <span id="Variable1430_X"><i class="var">X</i></span>) ---> <span class="name"><a href="#Name_scope">scope</a></span>(<a href="#Variable1422_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></a>, <a href="#Variable1391_X'"><i class="var">X&prime;</i></a>)
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_scope">scope</a></span>(_:<span class="name"><a href="#Name_environments">environments</a></span>, <span id="Variable1477_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> <a href="#Variable1477_V"><i class="var">V</i></a></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_accumulate">accumulate</span></span>(_:(=><span class="name"><a href="#Name_environments">environments</a></span>)<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_environments">environments</a></span></code></pre></div>
<code><span class="name"><a href="#Name_accumulate">accumulate</a></span>(<i class="var">D<sub class="sub">1</sub></i>, <i class="var">D<sub class="sub">2</sub></i>)</code> executes <code><i class="var">D<sub class="sub">1</sub></i></code> with the current bindings, to compute an
environment <code><i class="var">Rho<sub class="sub">1</sub></i></code> representing some local bindings. It then executes <code><i class="var">D<sub class="sub">2</sub></i></code> to
compute an environment <code><i class="var">Rho<sub class="sub">2</sub></i></code> representing further local bindings, with the
current bindings extended by <code><i class="var">Rho<sub class="sub">1</sub></i></code>, which may shadow or hide previous
current bindings. The result is <code><i class="var">Rho<sub class="sub">1</sub></i></code> extended by <code><i class="var">Rho<sub class="sub">2</sub></i></code>, which may shadow
or hide the bindings of <code><i class="var">Rho<sub class="sub">1</sub></i></code>.
<code><span class="name"><a href="#Name_accumulate">accumulate</a></span>(_, _)</code> is associative, with <code><span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map">map</a></span>( )</code> as unit, and extends to any
number of arguments.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<a href="#Variable1741_D1"><i class="var">D<sub class="sub">1</sub></i></a> ---> <span id="Variable1727_D1'"><i class="var">D<sub class="sub">1</sub>&prime;</i></span>
-------------------------------------------
<span class="name"><a href="#Name_accumulate">accumulate</a></span>(<span id="Variable1741_D1"><i class="var">D<sub class="sub">1</sub></i></span>, <span id="Variable1747_D2"><i class="var">D<sub class="sub">2</sub></i></span>) ---> <span class="name"><a href="#Name_accumulate">accumulate</a></span>(<a href="#Variable1727_D1'"><i class="var">D<sub class="sub">1</sub>&prime;</i></a>, <a href="#Variable1747_D2"><i class="var">D<sub class="sub">2</sub></i></a>)
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_accumulate">accumulate</a></span>(<span id="Variable1788_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></span>:<span class="name"><a href="#Name_environments">environments</a></span>, <span id="Variable1797_D2"><i class="var">D<sub class="sub">2</sub></i></span>) ~> <span class="name"><a href="#Name_scope">scope</a></span>(<a href="#Variable1788_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></a>, <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-override">map-override</a></span>(<a href="#Variable1797_D2"><i class="var">D<sub class="sub">2</sub></i></a>, <a href="#Variable1788_Rho1"><i class="var">Rho<sub class="sub">1</sub></i></a>))
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_accumulate">accumulate</a></span>( ) ~> <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map">map</a></span>( )
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_accumulate">accumulate</a></span>(<span id="Variable1863_D1"><i class="var">D<sub class="sub">1</sub></i></span>) ~> <a href="#Variable1863_D1"><i class="var">D<sub class="sub">1</sub></i></a>
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_accumulate">accumulate</a></span>(<span id="Variable1885_D1"><i class="var">D<sub class="sub">1</sub></i></span>, <span id="Variable1891_D2"><i class="var">D<sub class="sub">2</sub></i></span>, <span id="Variable1897_D+"><i class="var">D<sup class="sup">+</sup></i></span>) ~> <span class="name"><a href="#Name_accumulate">accumulate</a></span>(<a href="#Variable1885_D1"><i class="var">D<sub class="sub">1</sub></i></a>, <span class="name"><a href="#Name_accumulate">accumulate</a></span>(<a href="#Variable1891_D2"><i class="var">D<sub class="sub">2</sub></i></a>, <a href="#Variable1897_D+"><i class="var">D<sup class="sup">+</sup></i></a>))</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_collateral">collateral</span></span>(<span id="Variable1949_Rho*"><i class="var">Rho<sup class="sup">*</sup></i></span>:<span class="name"><a href="#Name_environments">environments</a></span><sup class="sup">*</sup>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> <span class="name"><a href="../../Abnormal/Failing/index.html#Name_checked">checked</a></span> <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-unite">map-unite</a></span>(<a href="#Variable1949_Rho*"><i class="var">Rho<sup class="sup">*</sup></i></a>)</code></pre></div>
<code><span class="name"><a href="#Name_collateral">collateral</a></span>(<i class="var">D<sub class="sub">1</sub></i>, ...)</code> pre-evaluates its arguments with the current bindings,
and unites the resulting maps, which fails if the domains are not pairwise
disjoint.
<code><span class="name"><a href="#Name_collateral">collateral</a></span>(<i class="var">D<sub class="sub">1</sub></i>, <i class="var">D<sub class="sub">2</sub></i>)</code> is associative and commutative with <code><span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map">map</a></span>( )</code> as unit,
and extends to any number of arguments.
#### Recurse
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_bind-recursively">bind-recursively</span></span>(<span id="Variable2086_I"><i class="var">I</i></span>:<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span id="Variable2095_E"><i class="var">E</i></span>:=><span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> <span class="name"><a href="#Name_recursive">recursive</a></span>({<a href="#Variable2086_I"><i class="var">I</i></a>}, <span class="name"><a href="#Name_bind-value">bind-value</a></span>(<a href="#Variable2086_I"><i class="var">I</i></a>, <a href="#Variable2095_E"><i class="var">E</i></a>))</code></pre></div>
<code><span class="name"><a href="#Name_bind-recursively">bind-recursively</a></span>(<i class="var">I</i>, <i class="var">E</i>)</code> binds <code><i class="var">I</i></code> to a link that refers to the value of <code><i class="var">E</i></code>,
representing a recursive binding of <code><i class="var">I</i></code> to the value of <code><i class="var">E</i></code>.
Since <code><span class="name"><a href="#Name_bound-value">bound-value</a></span>(<i class="var">I</i>)</code> follows links, it should not be executed during the
evaluation of <code><i class="var">E</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_recursive">recursive</span></span>(<span id="Variable2273_SI"><i class="var">SI</i></span>:<span class="name"><a href="../../../Values/Composite/Sets/index.html#Name_sets">sets</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>), <span id="Variable2289_D"><i class="var">D</i></span>:=><span class="name"><a href="#Name_environments">environments</a></span>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> <span class="name"><a href="#Name_re-close">re-close</a></span>(<span class="name"><a href="#Name_bind-to-forward-links">bind-to-forward-links</a></span>(<a href="#Variable2273_SI"><i class="var">SI</i></a>), <a href="#Variable2289_D"><i class="var">D</i></a>)</code></pre></div>
<code><span class="name"><a href="#Name_recursive">recursive</a></span>(<i class="var">SI</i>, <i class="var">D</i>)</code> executes <code><i class="var">D</i></code> with potential recursion on the bindings of
the identifiers in the set <code><i class="var">SI</i></code> (which need not be the same as the set of
identifiers bound by <code><i class="var">D</i></code>).
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Auxiliary</i> <i class="keyword">Funcon</i>
<span class="name"><span id="Name_re-close">re-close</span></span>(<span id="Variable2410_M"><i class="var">M</i></span>:<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span class="name"><a href="../Linking/index.html#Name_links">links</a></span>), <span id="Variable2429_D"><i class="var">D</i></span>:=><span class="name"><a href="#Name_environments">environments</a></span>) : =><span class="name"><a href="#Name_environments">environments</a></span>
~> <span class="name"><a href="#Name_accumulate">accumulate</a></span>(<span class="name"><a href="#Name_scope">scope</a></span>(<a href="#Variable2410_M"><i class="var">M</i></a>, <a href="#Variable2429_D"><i class="var">D</i></a>), <span class="name"><a href="../Flowing/index.html#Name_sequential">sequential</a></span>(<span class="name"><a href="#Name_set-forward-links">set-forward-links</a></span>(<a href="#Variable2410_M"><i class="var">M</i></a>), <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map">map</a></span>( )))</code></pre></div>
<code><span class="name"><a href="#Name_re-close">re-close</a></span>(<i class="var">M</i>, <i class="var">D</i>)</code> first executes <code><i class="var">D</i></code> in the scope <code><i class="var">M</i></code>, which maps identifiers
to freshly allocated links. This computes an environment <code><i class="var">Rho</i></code> where the bound
values may contain links, or implicit references to links in abstraction
values. It then sets the link for each identifier in the domain of <code><i class="var">M</i></code> to
refer to its bound value in <code><i class="var">Rho</i></code>, and returns <code><i class="var">Rho</i></code> as the result.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Auxiliary</i> <i class="keyword">Funcon</i>
<span class="name"><span id="Name_bind-to-forward-links">bind-to-forward-links</span></span>(<span id="Variable2617_SI"><i class="var">SI</i></span>:<span class="name"><a href="../../../Values/Composite/Sets/index.html#Name_sets">sets</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>)) : =><span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span class="name"><a href="../Linking/index.html#Name_links">links</a></span>)
~> <span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-unite">map-unite</a></span>(<span class="name"><a href="../Giving/index.html#Name_interleave-map">interleave-map</a></span>(<span class="name"><a href="#Name_bind-value">bind-value</a></span>(<span class="name"><a href="../Giving/index.html#Name_given">given</a></span>, <span class="name"><a href="../Linking/index.html#Name_fresh-link">fresh-link</a></span>(<span class="name"><a href="../../../Values/Value-Types/index.html#Name_values">values</a></span>)),
<span class="name"><a href="../../../Values/Composite/Sets/index.html#Name_set-elements">set-elements</a></span>(<a href="#Variable2617_SI"><i class="var">SI</i></a>)))</code></pre></div>
<code><span class="name"><a href="#Name_bind-to-forward-links">bind-to-forward-links</a></span>(<i class="var">SI</i>)</code> binds each identifier in the set <code><i class="var">SI</i></code> to a
freshly allocated link.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Auxiliary</i> <i class="keyword">Funcon</i>
<span class="name"><span id="Name_set-forward-links">set-forward-links</span></span>(<span id="Variable2742_M"><i class="var">M</i></span>:<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="#Name_identifiers">identifiers</a></span>, <span class="name"><a href="../Linking/index.html#Name_links">links</a></span>)) : =><span class="name"><a href="../../../Values/Primitive/Null/index.html#Name_null-type">null-type</a></span>
~> <span class="name"><a href="../Flowing/index.html#Name_effect">effect</a></span>(<span class="name"><a href="../Giving/index.html#Name_interleave-map">interleave-map</a></span>(<span class="name"><a href="../Linking/index.html#Name_set-link">set-link</a></span>(<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-lookup">map-lookup</a></span>(<a href="#Variable2742_M"><i class="var">M</i></a>, <span class="name"><a href="../Giving/index.html#Name_given">given</a></span>), <span class="name"><a href="#Name_bound-value">bound-value</a></span>(<span class="name"><a href="../Giving/index.html#Name_given">given</a></span>)),
<span class="name"><a href="../../../Values/Composite/Sets/index.html#Name_set-elements">set-elements</a></span>(<span class="name"><a href="../../../Values/Composite/Maps/index.html#Name_map-domain">map-domain</a></span>(<a href="#Variable2742_M"><i class="var">M</i></a>))))</code></pre></div>
For each identifier <code><i class="var">I</i></code> in the domain of <code><i class="var">M</i></code>, <code><span class="name"><a href="#Name_set-forward-links">set-forward-links</a></span>(<i class="var">M</i>)</code> sets the
link to which <code><i class="var">I</i></code> is mapped by <code><i class="var">M</i></code> to the current bound value of <code><i class="var">I</i></code>.
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Binding.cbs]: Binding.cbs
"CBS SOURCE FILE"
[Funcons-beta]: /CBS-beta/docs/Funcons-beta
"FUNCONS-BETA"
[Unstable-Funcons-beta]: /CBS-beta/docs/Unstable-Funcons-beta
"UNSTABLE-FUNCONS-BETA"
[Languages-beta]: /CBS-beta/docs/Languages-beta
"LANGUAGES-BETA"
[Unstable-Languages-beta]: /CBS-beta/docs/Unstable-Languages-beta
"UNSTABLE-LANGUAGES-BETA"
[CBS-beta]: /CBS-beta "CBS-BETA"
[PLanCompS Project]: https://plancomps.github.io
"PROGRAMMING LANGUAGE COMPONENTS AND SPECIFICATIONS PROJECT HOME PAGE"
[CBS-beta issues...]: https://github.com/plancomps/CBS-beta/issues
"CBS-BETA ISSUE REPORTS ON GITHUB"
[Suggest an improvement...]: mailto:plancomps@gmail.com?Subject=CBS-beta%20-%20comment&Body=Re%3A%20CBS-beta%20specification%20at%20Computations/Normal/Binding/Binding.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"

View File

@@ -0,0 +1,27 @@
general {
funcon-term:
initialise-binding
tuple(
accumulate( ),
accumulate(bind-value("x", true)),
accumulate(bind-value("x", true),
bind-value("y", bound-directly"x")),
accumulate(bind-value("x", true),
bind-value("y", bound-directly"x"),
bind-value("z", bound-directly"x")),
accumulate(bind-value("x", true),
bind-value("y", true),
bind-value("x", bound-directly"x")))
;
}
tests {
result-term:
tuple(
map( ),
{"x"|->true},
{"x"|->true, "y"|->true},
{"x"|->true, "y"|->true, "z"|->true},
{"y"|->true, "x"|->true})
;
}

View File

@@ -0,0 +1,16 @@
general {
funcon-term:
initialise-binding
scope(
bind-recursively("x",
thunk closure
is-value bound-value"x"),
force bound-value"x")
;
}
tests {
result-term:
true
;
}

View File

@@ -0,0 +1,9 @@
general {
funcon-term:
bind-value("x", 1)
;
}
tests {
result-term: {"x"|->1};
}

View File

@@ -0,0 +1,15 @@
general {
funcon-term:
initialise-binding
scope(
{"x"|->true, "y"|->fresh-link(booleans)},
and(
bound-directly"x",
is-in-type(bound-directly"y", links),
else(bound-directly"z", true)))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,15 @@
general {
funcon-term:
initialise-binding
scope(
{"x"|->true, "y"|->fresh-initialised-link(booleans,true)},
and(
bound-value"x",
bound-value"y",
else(bound-value"z",true)))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,11 @@
general {
funcon-term:
initialise-binding
scope({"x"|->1},
closed(else(bound-directly"x", true)))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,27 @@
general {
funcon-term:
initialise-binding tuple(
collateral( ),
collateral(bind-value("x", true)),
collateral(bind-value("x", true),
bind-value("y", false)),
collateral(bind-value("x", true),
bind-value("y", false),
unbind"z"),
scope(bind-value("x",true),
collateral(bind-value("x", false),
bind-value("y", true),
bind-value("z", bound-directly"x"))))
;
}
tests {
result-term:
tuple(
map( ),
{"x"|->true},
{"x"|->true, "y"|->false},
{"x"|->true, "y"|->false, "z"|->( )},
{"x"|->false,"y"|->true, "z"|->true})
;
}

View File

@@ -0,0 +1,12 @@
general {
funcon-term:
and(
is-in-type(map(),environments),
is-in-type({"x"|->true},environments),
is-in-type({"x"|->true, "y"|->false},environments))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,10 @@
general {
funcon-term:
initialise-generating
not is-equal(fresh-identifier, fresh-identifier)
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,14 @@
general {
funcon-term:
and(
is-in-type("x", identifiers),
is-in-type(identifier-tagged("x",false), identifiers),
is-in-type(identifier-tagged(identifier-tagged("x",true),false), identifiers),
is-in-type(identifier-tagged("x",identifier-tagged("x",true)), identifiers)
)
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,10 @@
general {
funcon-term:
initialise-binding(print"OK")
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,17 @@
general {
funcon-term:
initialise-binding
scope(
recursive(
{"x"},
bind-value("x", thunk closure
if-true-else(not is-equal(null-value, bound-value"x"), true, false))),
force bound-value"x")
;
}
tests {
result-term:
true
;
}

View File

@@ -0,0 +1,15 @@
general {
funcon-term:
initialise-binding
and(
scope(bind-value("x", false),
scope(bind-value("x", true),
bound-directly"x")),
scope(bind-value("x", false),
true))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,9 @@
general {
funcon-term:
unbind("x")
;
}
tests {
result-term: {"x"|->( )};
}