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,92 @@
### Functions
[
Datatype functions
Funcon function
Funcon apply
Funcon supply
Funcon compose
Funcon uncurry
Funcon curry
Funcon partial-apply
]
Meta-variables
T, T', T1, T2 <: values
Datatype
functions(T,T') ::= function(A:abstractions(T=>T'))
/*
`functions(T, T')` consists of abstractions whose bodies may depend on
a given value of type `T`, and whose executions normally compute values
of type `T'`.
`function(abstraction(X))` evaluates to a function with dynamic bindings,
`function(closure(X))` computes a function with static bindings.
*/
Funcon
apply(_:functions(T, T'), _:T) : =>T'
/*
`apply(F, V)` applies the function `F` to the argument value `V`.
This corresponds to call by value; using thunks as argument values
corresponds to call by name. Moreover, using tuples as argument values
corresponds to application to multiple arguments.
*/
Rule
apply(function(abstraction(X)), V:T) ~> give(V, X)
Funcon
supply(_:functions(T, T'), _:T) : =>thunks(T')
/*
`supply(F, V)` determines the argument value of a function application,
but returns a thunk that defers executing the body of the function.
*/
Rule
supply(function(abstraction(X)), V:T) ~> thunk(abstraction(give(V, X)))
Funcon
compose(_:functions(T2, T'), _:functions(T1, T2)) : =>functions(T1, T')
/*
`compose(F2, F1)` returns the function that applies `F1` to its argument,
then applies `F2` to the result of `F1`.
*/
Rule
compose(function(abstraction(Y)), function(abstraction(X)))
~> function(abstraction(give(X, Y)))
Funcon
uncurry(F:functions(T1, functions(T2, T'))) :
=>functions(tuples(T1, T2), T')
~> function(abstraction(
apply(
apply(F, checked index(1, tuple-elements given)),
checked index(2, tuple-elements given))))
/*
`uncurry(F)` takes a curried function `F` and returns a function that takes
a pair of arguments..
*/
Funcon
curry(F:functions(tuples(T1, T2), T')) : =>functions(T1, functions(T2, T'))
~> function(abstraction(partial-apply(F, given)))
/*
`curry(F)` takes a function `F` that takes a pair of arguments, and returns
the corresponding 'curried' function.
*/
Funcon
partial-apply(F:functions(tuples(T1, T2), T'), V:T1) : =>functions(T2, T')
~> function(abstraction(apply(F,tuple(V,given))))
/*
`partial-apply(F, V)` takes a function `F` that takes a pair of arguments,
and determines the first argument, returning a function of the second
argument.
*/

View File

@@ -0,0 +1,135 @@
---
layout: default
title: "Functions"
parent: Abstraction
ancestor: Funcons-beta
---
[Funcons-beta] : [Functions.cbs]
-----------------------------
### Functions
<div class="highlighter-rouge"><pre class="highlight"><code>[
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_functions">functions</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_function">function</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_apply">apply</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_supply">supply</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_compose">compose</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_uncurry">uncurry</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_curry">curry</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_partial-apply">partial-apply</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 id="PartVariable_T'"><i class="var">T&prime;</i></span>, <span id="PartVariable_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="PartVariable_T2"><i class="var">T<sub class="sub">2</sub></i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
<span class="name"><span id="Name_functions">functions</span></span>(<span id="Variable78_T"><i class="var">T</i></span>,<span id="Variable85_T'"><i class="var">T&prime;</i></span>) ::= <span id="Name_function">function</span>(<span id="Variable99_A"><i class="var">A</i></span>:<span class="name"><a href="../Generic/index.html#Name_abstractions">abstractions</a></span>(<span id="Variable104_T"><i class="var">T</i></span>=><span id="Variable111_T'"><i class="var">T&prime;</i></span>))</code></pre></div>
<code><span class="name"><a href="#Name_functions">functions</a></span>(<i class="var">T</i>, <i class="var">T&prime;</i>)</code> consists of abstractions whose bodies may depend on
a given value of type <code><i class="var">T</i></code>, and whose executions normally compute values
of type <code><i class="var">T&prime;</i></code>.
<code><span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<i class="var">X</i>))</code> evaluates to a function with dynamic bindings,
<code><span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_closure">closure</a></span>(<i class="var">X</i>))</code> computes a function with static bindings.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_apply">apply</span></span>(_:<span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable257_T"><i class="var">T</i></span>, <span id="Variable263_T'"><i class="var">T&prime;</i></span>), _:<span id="Variable281_T"><i class="var">T</i></span>) : =><span id="Variable297_T'"><i class="var">T&prime;</i></span></code></pre></div>
<code><span class="name"><a href="#Name_apply">apply</a></span>(<i class="var">F</i>, <i class="var">V</i>)</code> applies the function <code><i class="var">F</i></code> to the argument value <code><i class="var">V</i></code>.
This corresponds to call by value; using thunks as argument values
corresponds to call by name. Moreover, using tuples as argument values
corresponds to application to multiple arguments.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_apply">apply</a></span>(<span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable366_X"><i class="var">X</i></span>)), <span id="Variable383_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_give">give</a></span>(<a href="#Variable383_V"><i class="var">V</i></a>, <a href="#Variable366_X"><i class="var">X</i></a>)</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_supply">supply</span></span>(_:<span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable427_T"><i class="var">T</i></span>, <span id="Variable433_T'"><i class="var">T&prime;</i></span>), _:<span id="Variable451_T"><i class="var">T</i></span>) : =><span class="name"><a href="../Thunks/index.html#Name_thunks">thunks</a></span>(<span id="Variable468_T'"><i class="var">T&prime;</i></span>)</code></pre></div>
<code><span class="name"><a href="#Name_supply">supply</a></span>(<i class="var">F</i>, <i class="var">V</i>)</code> determines the argument value of a function application,
but returns a thunk that defers executing the body of the function.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_supply">supply</a></span>(<span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable517_X"><i class="var">X</i></span>)), <span id="Variable534_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> <span class="name"><a href="../Thunks/index.html#Name_thunk">thunk</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_give">give</a></span>(<a href="#Variable534_V"><i class="var">V</i></a>, <a href="#Variable517_X"><i class="var">X</i></a>)))</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_compose">compose</span></span>(_:<span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable593_T2"><i class="var">T<sub class="sub">2</sub></i></span>, <span id="Variable599_T'"><i class="var">T&prime;</i></span>), _:<span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable619_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="Variable625_T2"><i class="var">T<sub class="sub">2</sub></i></span>)) : =><span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable649_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="Variable655_T'"><i class="var">T&prime;</i></span>)</code></pre></div>
<code><span class="name"><a href="#Name_compose">compose</a></span>(<i class="var">F<sub class="sub">2</sub></i>, <i class="var">F<sub class="sub">1</sub></i>)</code> returns the function that applies <code><i class="var">F<sub class="sub">1</sub></i></code> to its argument,
then applies <code><i class="var">F<sub class="sub">2</sub></i></code> to the result of <code><i class="var">F<sub class="sub">1</sub></i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_compose">compose</a></span>(<span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable749_Y"><i class="var">Y</i></span>)), <span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable768_X"><i class="var">X</i></span>)))
~> <span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_give">give</a></span>(<a href="#Variable768_X"><i class="var">X</i></a>, <a href="#Variable749_Y"><i class="var">Y</i></a>)))</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_uncurry">uncurry</span></span>(<span id="Variable828_F"><i class="var">F</i></span>:<span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable834_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable841_T2"><i class="var">T<sub class="sub">2</sub></i></span>, <span id="Variable847_T'"><i class="var">T&prime;</i></span>))) :
=><span class="name"><a href="#Name_functions">functions</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuples">tuples</a></span>(<span id="Variable878_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="Variable884_T2"><i class="var">T<sub class="sub">2</sub></i></span>), <span id="Variable897_T'"><i class="var">T&prime;</i></span>)
~> <span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(
<span class="name"><a href="#Name_apply">apply</a></span>(
<span class="name"><a href="#Name_apply">apply</a></span>(<a href="#Variable828_F"><i class="var">F</i></a>, <span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_checked">checked</a></span> <span class="name"><a href="../../Composite/Sequences/index.html#Name_index">index</a></span>(1, <span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-elements">tuple-elements</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>)),
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_checked">checked</a></span> <span class="name"><a href="../../Composite/Sequences/index.html#Name_index">index</a></span>(2, <span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-elements">tuple-elements</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>))))</code></pre></div>
<code><span class="name"><a href="#Name_uncurry">uncurry</a></span>(<i class="var">F</i>)</code> takes a curried function <code><i class="var">F</i></code> and returns a function that takes
a pair of arguments..
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_curry">curry</span></span>(<span id="Variable1020_F"><i class="var">F</i></span>:<span class="name"><a href="#Name_functions">functions</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuples">tuples</a></span>(<span id="Variable1027_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="Variable1033_T2"><i class="var">T<sub class="sub">2</sub></i></span>), <span id="Variable1046_T'"><i class="var">T&prime;</i></span>)) : =><span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable1069_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable1076_T2"><i class="var">T<sub class="sub">2</sub></i></span>, <span id="Variable1082_T'"><i class="var">T&prime;</i></span>))
~> <span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="#Name_partial-apply">partial-apply</a></span>(<a href="#Variable1020_F"><i class="var">F</i></a>, <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>)))</code></pre></div>
<code><span class="name"><a href="#Name_curry">curry</a></span>(<i class="var">F</i>)</code> takes a function <code><i class="var">F</i></code> that takes a pair of arguments, and returns
the corresponding 'curried' function.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_partial-apply">partial-apply</span></span>(<span id="Variable1174_F"><i class="var">F</i></span>:<span class="name"><a href="#Name_functions">functions</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuples">tuples</a></span>(<span id="Variable1181_T1"><i class="var">T<sub class="sub">1</sub></i></span>, <span id="Variable1187_T2"><i class="var">T<sub class="sub">2</sub></i></span>), <span id="Variable1200_T'"><i class="var">T&prime;</i></span>), <span id="Variable1215_V"><i class="var">V</i></span>:<span id="Variable1220_T1"><i class="var">T<sub class="sub">1</sub></i></span>) : =><span class="name"><a href="#Name_functions">functions</a></span>(<span id="Variable1237_T2"><i class="var">T<sub class="sub">2</sub></i></span>, <span id="Variable1243_T'"><i class="var">T&prime;</i></span>)
~> <span class="name"><a href="#Name_function">function</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="#Name_apply">apply</a></span>(<a href="#Variable1174_F"><i class="var">F</i></a>,<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple">tuple</a></span>(<a href="#Variable1215_V"><i class="var">V</i></a>,<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>))))</code></pre></div>
<code><span class="name"><a href="#Name_partial-apply">partial-apply</a></span>(<i class="var">F</i>, <i class="var">V</i>)</code> takes a function <code><i class="var">F</i></code> that takes a pair of arguments,
and determines the first argument, returning a function of the second
argument.
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Functions.cbs]: Functions.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%20Values/Abstraction/Functions/Functions.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"

View File

@@ -0,0 +1,16 @@
general {
funcon-term:
initialise-giving
initialise-binding
apply(
sequential(print 1, function abstraction print given),
sequential(print 2 , 3))
;
}
tests {
result-term: null-value;
standard-out: [1, 2, 3];
//Also:
// standard-out: [2, 1, 3];
}

View File

@@ -0,0 +1,20 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("f",
function abstraction
sequential(print given, integer-add(1,given))),
print apply(
compose(
bound-value"f",
function abstraction sequential(print 1, 2)),
99))
;
}
tests {
result-term: null-value;
standard-out: [1, 2, 3];
}

View File

@@ -0,0 +1,17 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("f",
function abstraction print given),
apply(
apply(curry(bound-value"f"), 1),
2))
;
}
tests {
result-term: null-value;
standard-out: [tuple(1,2)];
}

View File

@@ -0,0 +1,27 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",99),
give(
99,
give(
function abstraction(
sequential(
print given,
print bound-value"x")),
scope(
bind-value("x",4),
apply(
sequential(print 1, given),
sequential(print 2, 3))))))
;
}
tests {
result-term: null-value;
standard-out: [1, 2, 3, 4];
//Also:
// standard-out: [2, 1, 3, 4];
}

View File

@@ -0,0 +1,27 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",4),
give(
99,
give(
function closure(
sequential(
print given,
print bound-value"x")),
scope(
bind-value("x",99),
apply(
sequential(print 1, given),
sequential(print 2, 3))))))
;
}
tests {
result-term: null-value;
standard-out: [1, 2, 3, 4];
//Also:
// standard-out: [2, 1, 3, 4];
}

View File

@@ -0,0 +1,17 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("f",
function abstraction print given),
apply(
partial-apply(bound-value"f", 1),
2))
;
}
tests {
result-term: null-value;
standard-out: [tuple(1,2)];
}

View File

@@ -0,0 +1,17 @@
general {
funcon-term:
initialise-giving
initialise-binding
force(
supply(
sequential(print 1, function abstraction print given),
sequential(print 2 , 3)))
;
}
tests {
result-term: null-value;
standard-out: [1, 2, 3];
//Also:
// standard-out: [2, 1, 3];
}

View File

@@ -0,0 +1,17 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("f",
uncurry function abstraction
sequential(print given,
function abstraction print given)),
apply(bound-value"f", tuple(1,2)))
;
}
tests {
result-term: null-value;
standard-out: [1, 2];
}

View File

@@ -0,0 +1,49 @@
### Generic abstractions
[
Type abstractions
Funcon abstraction
Funcon closure
Funcon enact
]
Meta-variables
T <: values
T? <: values?
Type
abstractions(_:computation-types)
Funcon
abstraction(_:T?=>T) : abstractions(T?=>T)
/*
The funcon `abstraction(X)` forms abstraction values from computations.
References to bindings of identifiers in `X` are dynamic.
The funcon `closure(X)` forms abstractions with static bindings.
*/
Funcon
closure(_:T?=>T) : =>abstractions(T?=>T)
/*
`closure(X)` computes a closed abstraction from the computation `X`.
In contrast to `abstraction(X)`, references to bindings of identifiers
in `X` are static. Moreover, `closure(X)` is not a value constructor,
so it cannot be used in pattern terms in rules.
*/
Rule
environment(Rho) |- closure(X) ---> abstraction(closed(scope(Rho, X)))
Funcon
enact(_:abstractions(T?=>T)) : T?=>T
/*
`enact(A)` executes the computation of the abstraction `A`,
with access to all the current entities.
*/
Rule
enact(abstraction(X)) ~> X

View File

@@ -0,0 +1,85 @@
---
layout: default
title: "Generic"
parent: Abstraction
ancestor: Funcons-beta
---
[Funcons-beta] : [Generic.cbs]
-----------------------------
### Generic abstractions
<div class="highlighter-rouge"><pre class="highlight"><code>[
<i class="keyword">Type</i> <span class="name"><a href="#Name_abstractions">abstractions</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_abstraction">abstraction</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_closure">closure</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_enact">enact</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="../../Value-Types/index.html#Name_values">values</a></span>
<span id="PartVariable_T?"><i class="var">T<sup class="sup">?</sup></i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">?</sup></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
<span class="name"><span id="Name_abstractions">abstractions</span></span>(_:<span class="name"><a href="../../../Computations/Computation-Types/index.html#Name_computation-types">computation-types</a></span>)</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_abstraction">abstraction</span></span>(_:<span id="Variable80_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable86_T"><i class="var">T</i></span>) : <span class="name"><a href="#Name_abstractions">abstractions</a></span>(<span id="Variable102_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable108_T"><i class="var">T</i></span>)</code></pre></div>
The funcon <code><span class="name"><a href="#Name_abstraction">abstraction</a></span>(<i class="var">X</i>)</code> forms abstraction values from computations.
References to bindings of identifiers in <code><i class="var">X</i></code> are dynamic.
The funcon <code><span class="name"><a href="#Name_closure">closure</a></span>(<i class="var">X</i>)</code> forms abstractions with static bindings.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_closure">closure</span></span>(_:<span id="Variable186_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable192_T"><i class="var">T</i></span>) : =><span class="name"><a href="#Name_abstractions">abstractions</a></span>(<span id="Variable209_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable215_T"><i class="var">T</i></span>)</code></pre></div>
<code><span class="name"><a href="#Name_closure">closure</a></span>(<i class="var">X</i>)</code> computes a closed abstraction from the computation <code><i class="var">X</i></code>.
In contrast to <code><span class="name"><a href="#Name_abstraction">abstraction</a></span>(<i class="var">X</i>)</code>, references to bindings of identifiers
in <code><i class="var">X</i></code> are static. Moreover, <code><span class="name"><a href="#Name_closure">closure</a></span>(<i class="var">X</i>)</code> is not a value constructor,
so it cannot be used in pattern terms in rules.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="ent-name"><a href="../../../Computations/Normal/Binding/index.html#Name_environment">environment</a></span>(<span id="Variable323_Rho"><i class="var">Rho</i></span>) |- <span class="name"><a href="#Name_closure">closure</a></span>(<span id="Variable340_X"><i class="var">X</i></span>) ---> <span class="name"><a href="#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_closed">closed</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_scope">scope</a></span>(<a href="#Variable323_Rho"><i class="var">Rho</i></a>, <a href="#Variable340_X"><i class="var">X</i></a>)))</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_enact">enact</span></span>(_:<span class="name"><a href="#Name_abstractions">abstractions</a></span>(<span id="Variable396_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable402_T"><i class="var">T</i></span>)) : <span id="Variable423_T?"><i class="var">T<sup class="sup">?</sup></i></span>=><span id="Variable429_T"><i class="var">T</i></span></code></pre></div>
<code><span class="name"><a href="#Name_enact">enact</a></span>(<i class="var">A</i>)</code> executes the computation of the abstraction <code><i class="var">A</i></code>,
with access to all the current entities.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_enact">enact</a></span>(<span class="name"><a href="#Name_abstraction">abstraction</a></span>(<span id="Variable478_X"><i class="var">X</i></span>)) ~> <a href="#Variable478_X"><i class="var">X</i></a></code></pre></div>
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Generic.cbs]: Generic.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%20Values/Abstraction/Generic/Generic.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"

View File

@@ -0,0 +1,25 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",99),
give(
tuple(
99,
abstraction(
sequential(
print first tuple-elements given,
print bound-value"x"))),
scope(
bind-value("x",42),
give(
tuple(42, second tuple-elements given),
enact second tuple-elements given))))
;
}
tests {
result-term: null-value;
standard-out: [42, 42];
}

View File

@@ -0,0 +1,25 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",42),
give(
tuple(
99,
closure(
sequential(
print first tuple-elements given,
print bound-value"x"))),
scope(
bind-value("x",99),
give(
tuple(42, second tuple-elements given),
enact second tuple-elements given))))
;
}
tests {
result-term: null-value;
standard-out: [42, 42];
}

View File

@@ -0,0 +1,224 @@
### Patterns
[
Datatype patterns
Funcon pattern
Funcon pattern-any
Funcon pattern-bind
Funcon pattern-type
Funcon pattern-else
Funcon pattern-unite
Funcon match
Funcon match-loosely
Funcon case-match
Funcon case-match-loosely
Funcon case-variant-value
]
/*
General patterns are simple patterns or structured patterns.
Matching a pattern to a value either computes an environment or fails.
Simple patterns are constructed from abstractions whose bodies depend on
a given value, and whose executions either compute environments or fail.
Structured patterns are composite values whose components may include
simple patterns as well as other values.
Matching a structured value to a structured pattern is similar to assigning
a structured value to a structured variable, with simple pattern components
matching component values analogously to simple variable components assigned
component values.
Note that patterns match only values, not (empty or proper) sequences.
*/
Meta-variables
T, T' <: values
#### Simple patterns
Datatype
patterns ::= pattern(_:abstractions(values=>environments))
/*
`patterns` is the type of simple patterns that can match values of a
particular type.
`pattern(abstraction(X))` constructs a pattern with dynamic bindings, and
`pattern(closure(X))` computes a pattern with static bindings. However,
there is no difference between dynamic and static bindings when the pattern
is matched in the same scope where it is constructed.
*/
Funcon
pattern-any : =>patterns
~> pattern(abstraction(map( )))
/*
`pattern-any` matches any value, computing the empty environment.
*/
Funcon
pattern-bind(I:identifiers) : =>patterns
~> pattern(abstraction(bind-value(I, given)))
/*
`pattern-bind(I)` matches any value, computing the environment binding `I`
to that value.
*/
Funcon
pattern-type(T) : =>patterns
~> pattern(abstraction(if-true-else(is-in-type(given, T), map( ), fail)))
/*
`pattern-type(T)` matches any value of type `T`, computing the empty
environment.
*/
Funcon
pattern-else(_:values, _:values) : =>patterns
Rule
pattern-else(P1:values, P2:values)
~> pattern(abstraction(else(match(given, P1), match(given, P2))))
/*
`pattern-else(P1, P2)` matches all values matched by `P1` or by `P2`.
If a value matches `P1`, that match gives the computed environment;
if a value does not match `P1` but matches `P2`, that match gives
the computed environment; otherwise the match fails.
*/
Funcon
pattern-unite(_:values, _:values) : =>patterns
Rule
pattern-unite(P1:values, P2:values)
~> pattern(abstraction(collateral(match(given, P1), match(given, P2))))
/*
`pattern-unite(P1, P2)` matches all values matched by both `P1` and `P2`,
then uniting the computed environments, which fails if the domains of the
environments overlap.
*/
#### Pattern matching
Funcon
match(_:values, _:values) : =>environments
/*
`match(V, P)` takes a (potentially structured) value `V` and a
(potentially structured) pattern `P`. Provided that the structure and all
components of `P` exactly match the structure and corresponding components
of `V`, the environments computed by the simple pattern matches are united.
*/
Rule
match(V:values, pattern(abstraction(X))) ~> give(V, X)
Rule
I2 =/= "pattern"
--------------------------------------------
match(datatype-value(I1:identifiers, V1*:values*),
datatype-value(I2:identifiers, V2*:values*))
~> sequential(
check-true(is-equal(I1, I2)),
check-true(is-equal(length V1*, length V2*)),
collateral(interleave-map(
match(tuple-elements(given)),
tuple-zip(tuple(V1*), tuple(V2*)))))
Rule
dom(M2) == {}
------------------------------------------------------
match(M1:maps(_,_), M2:maps(_,_))
~> if-true-else(is-equal(dom(M1), {}), map( ), fail)
Rule
dom(M2) =/= {}
some-element(dom(M2)) ~> K
-------------------------------------------------------
match(M1:maps(_,_), M2:maps(_,_))
~> if-true-else(
is-in-set(K, dom(M1)),
collateral(
match(map-lookup(M1, K), map-lookup(M2, K)),
match(map-delete(M1, {K}), map-delete(M2, {K}))),
fail)
Rule
P : ~(datatype-values|maps(_,_))
-----------------------------------------------
match(V:values, P:values)
~> if-true-else(is-equal(V, P), map( ), fail)
Funcon
match-loosely(_:values, _:values) : =>environments
/*
`match-loosely(V, P)` takes a (potentially structured) value `V` and a
(potentially structured) pattern `P`. Provided that the structure and all
components of `P` loosely match the structure and corresponding components
of `V`, the environments computed by the simple pattern matches are united.
*/
Rule
match-loosely(V:values, pattern(abstraction(X))) ~> give(V, X)
Rule
I2 =/= "pattern"
---------------------------------------------------
match-loosely(datatype-value(I1:identifiers, V1*:values*),
datatype-value(I2:identifiers, V2*:values*))
~> sequential(
check-true(is-equal(I1, I2)),
check-true(is-equal(length V1*, length V2*)),
collateral(interleave-map(
match-loosely(tuple-elements(given)),
tuple-zip(tuple(V1*), tuple(V2*)))))
Rule
dom(M2) == {}
-------------------------------------------------
match-loosely(M1:maps(_,_), M2:maps(_,_)) ~> map()
Rule
dom(M2) =/= {}
some-element(dom(M2)) ~> K
--------------------------------------------------------------
match-loosely(M1:maps(_,_), M2:maps(_,_))
~> if-true-else(
is-in-set(K, dom(M1)),
collateral(
match-loosely(map-lookup(M1, K), map-lookup(M2, K)),
match-loosely(map-delete(M1, {K}), map-delete(M2, {K}))),
fail)
Rule
P : ~(datatype-values|maps(_,_))
-------------------------------------------
match-loosely(DV:values, P:values)
~> if-true-else(is-equal(DV, P), map( ), fail)
Funcon
case-match(_:values, _:=>T') : =>T'
/*
`case-match(P, X)` matches `P` exactly to the given value.
If the match succeeds, the computed bindings have scope `X`.
*/
Rule
case-match(P:values, X) ~> scope(match(given, P), X)
Funcon
case-match-loosely(_:values, _:=>T') : =>T'
/*
`case-match(P, X)` matches `P` loosely to the given value.
If the match succeeds, the computed bindings have scope `X`.
*/
Rule
case-match-loosely(P:values, X) ~> scope(match-loosely(given, P), X)
Funcon
case-variant-value(_:identifiers) : =>values
/*
`case-variant-value(I)` matches values of variant `I`, then
giving the value contained in the variant.
*/
Rule
case-variant-value(I:identifiers) ~>
case-match(variant(I, pattern-any), variant-value(given))

View File

@@ -0,0 +1,267 @@
---
layout: default
title: "Patterns"
parent: Abstraction
ancestor: Funcons-beta
---
[Funcons-beta] : [Patterns.cbs]
-----------------------------
### Patterns
<div class="highlighter-rouge"><pre class="highlight"><code>[
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_patterns">patterns</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern">pattern</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern-any">pattern-any</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern-bind">pattern-bind</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern-type">pattern-type</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern-else">pattern-else</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pattern-unite">pattern-unite</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_match">match</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_match-loosely">match-loosely</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_case-match">case-match</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_case-match-loosely">case-match-loosely</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_case-variant-value">case-variant-value</a></span>
]</code></pre></div>
General patterns are simple patterns or structured patterns.
Matching a pattern to a value either computes an environment or fails.
Simple patterns are constructed from abstractions whose bodies depend on
a given value, and whose executions either compute environments or fail.
Structured patterns are composite values whose components may include
simple patterns as well as other values.
Matching a structured value to a structured pattern is similar to assigning
a structured value to a structured variable, with simple pattern components
matching component values analogously to simple variable components assigned
component values.
Note that patterns match only values, not (empty or proper) sequences.
<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 id="PartVariable_T'"><i class="var">T&prime;</i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span></code></pre></div>
#### Simple patterns
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
<span class="name"><span id="Name_patterns">patterns</span></span> ::= <span id="Name_pattern">pattern</span>(_:<span class="name"><a href="../Generic/index.html#Name_abstractions">abstractions</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>=><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>))</code></pre></div>
<code><span class="name"><a href="#Name_patterns">patterns</a></span></code> is the type of simple patterns that can match values of a
particular type.
<code><span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<i class="var">X</i>))</code> constructs a pattern with dynamic bindings, and
<code><span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_closure">closure</a></span>(<i class="var">X</i>))</code> computes a pattern with static bindings. However,
there is no difference between dynamic and static bindings when the pattern
is matched in the same scope where it is constructed.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_pattern-any">pattern-any</span></span> : =><span class="name"><a href="#Name_patterns">patterns</a></span>
~> <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>( )))</code></pre></div>
<code><span class="name"><a href="#Name_pattern-any">pattern-any</a></span></code> matches any value, computing the empty environment.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_pattern-bind">pattern-bind</span></span>(<span id="Variable245_I"><i class="var">I</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="#Name_patterns">patterns</a></span>
~> <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_bind-value">bind-value</a></span>(<a href="#Variable245_I"><i class="var">I</i></a>, <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>)))</code></pre></div>
<code><span class="name"><a href="#Name_pattern-bind">pattern-bind</a></span>(<i class="var">I</i>)</code> matches any value, computing the environment binding <code><i class="var">I</i></code>
to that value.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_pattern-type">pattern-type</span></span>(<span id="Variable335_T"><i class="var">T</i></span>) : =><span class="name"><a href="#Name_patterns">patterns</a></span>
~> <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-in-type">is-in-type</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable335_T"><i class="var">T</i></a>), <span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>( ), <span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_fail">fail</a></span>)))</code></pre></div>
<code><span class="name"><a href="#Name_pattern-type">pattern-type</a></span>(<i class="var">T</i>)</code> matches any value of type <code><i class="var">T</i></code>, computing the empty
environment.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_pattern-else">pattern-else</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="#Name_patterns">patterns</a></span>
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_pattern-else">pattern-else</a></span>(<span id="Variable469_P1"><i class="var">P<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable478_P2"><i class="var">P<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>)
~> <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_else">else</a></span>(<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable469_P1"><i class="var">P<sub class="sub">1</sub></i></a>), <span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable478_P2"><i class="var">P<sub class="sub">2</sub></i></a>))))</code></pre></div>
<code><span class="name"><a href="#Name_pattern-else">pattern-else</a></span>(<i class="var">P<sub class="sub">1</sub></i>, <i class="var">P<sub class="sub">2</sub></i>)</code> matches all values matched by <code><i class="var">P<sub class="sub">1</sub></i></code> or by <code><i class="var">P<sub class="sub">2</sub></i></code>.
If a value matches <code><i class="var">P<sub class="sub">1</sub></i></code>, that match gives the computed environment;
if a value does not match <code><i class="var">P<sub class="sub">1</sub></i></code> but matches <code><i class="var">P<sub class="sub">2</sub></i></code>, that match gives
the computed environment; otherwise the match fails.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_pattern-unite">pattern-unite</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="#Name_patterns">patterns</a></span>
<i class="keyword">Rule</i>
<span class="name"><a href="#Name_pattern-unite">pattern-unite</a></span>(<span id="Variable685_P1"><i class="var">P<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable694_P2"><i class="var">P<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>)
~> <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_collateral">collateral</a></span>(<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable685_P1"><i class="var">P<sub class="sub">1</sub></i></a>), <span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable694_P2"><i class="var">P<sub class="sub">2</sub></i></a>))))</code></pre></div>
<code><span class="name"><a href="#Name_pattern-unite">pattern-unite</a></span>(<i class="var">P<sub class="sub">1</sub></i>, <i class="var">P<sub class="sub">2</sub></i>)</code> matches all values matched by both <code><i class="var">P<sub class="sub">1</sub></i></code> and <code><i class="var">P<sub class="sub">2</sub></i></code>,
then uniting the computed environments, which fails if the domains of the
environments overlap.
#### Pattern matching
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_match">match</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span></code></pre></div>
<code><span class="name"><a href="#Name_match">match</a></span>(<i class="var">V</i>, <i class="var">P</i>)</code> takes a (potentially structured) value <code><i class="var">V</i></code> and a
(potentially structured) pattern <code><i class="var">P</i></code>. Provided that the structure and all
components of <code><i class="var">P</i></code> exactly match the structure and corresponding components
of <code><i class="var">V</i></code>, the environments computed by the simple pattern matches are united.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_match">match</a></span>(<span id="Variable964_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable974_X"><i class="var">X</i></span>))) ~> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_give">give</a></span>(<a href="#Variable964_V"><i class="var">V</i></a>, <a href="#Variable974_X"><i class="var">X</i></a>)
<i class="keyword">Rule</i>
<a href="#Variable1064_I2"><i class="var">I<sub class="sub">2</sub></i></a> =/= "pattern"
--------------------------------------------
<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-value">datatype-value</a></span>(<span id="Variable1035_I1"><i class="var">I<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable1045_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>),
<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-value">datatype-value</a></span>(<span id="Variable1064_I2"><i class="var">I<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable1074_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>))
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_sequential">sequential</a></span>(
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_check-true">check-true</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<a href="#Variable1035_I1"><i class="var">I<sub class="sub">1</sub></i></a>, <a href="#Variable1064_I2"><i class="var">I<sub class="sub">2</sub></i></a>)),
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_check-true">check-true</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<span class="name"><a href="../../Composite/Sequences/index.html#Name_length">length</a></span> <a href="#Variable1045_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></a>, <span class="name"><a href="../../Composite/Sequences/index.html#Name_length">length</a></span> <a href="#Variable1074_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></a>)),
<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_collateral">collateral</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_interleave-map">interleave-map</a></span>(
<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-elements">tuple-elements</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>)),
<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-zip">tuple-zip</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple">tuple</a></span>(<a href="#Variable1045_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></a>), <span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple">tuple</a></span>(<a href="#Variable1074_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></a>)))))
<i class="keyword">Rule</i>
<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable1284_M2"><i class="var">M<sub class="sub">2</sub></i></a>) == {}
------------------------------------------------------
<span class="name"><a href="#Name_match">match</a></span>(<span id="Variable1261_M1"><i class="var">M<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_), <span id="Variable1284_M2"><i class="var">M<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_))
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable1261_M1"><i class="var">M<sub class="sub">1</sub></i></a>), {}), <span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>( ), <span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_fail">fail</a></span>)
<i class="keyword">Rule</i>
<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable1432_M2"><i class="var">M<sub class="sub">2</sub></i></a>) =/= {}
<span class="name"><a href="../../Composite/Sets/index.html#Name_some-element">some-element</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable1432_M2"><i class="var">M<sub class="sub">2</sub></i></a>)) ~> <span id="Variable1396_K"><i class="var">K</i></span>
-------------------------------------------------------
<span class="name"><a href="#Name_match">match</a></span>(<span id="Variable1409_M1"><i class="var">M<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_), <span id="Variable1432_M2"><i class="var">M<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_))
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(
<span class="name"><a href="../../Composite/Sets/index.html#Name_is-in-set">is-in-set</a></span>(<a href="#Variable1396_K"><i class="var">K</i></a>, <span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable1409_M1"><i class="var">M<sub class="sub">1</sub></i></a>)),
<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_collateral">collateral</a></span>(
<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_map-lookup">map-lookup</a></span>(<a href="#Variable1409_M1"><i class="var">M<sub class="sub">1</sub></i></a>, <a href="#Variable1396_K"><i class="var">K</i></a>), <span class="name"><a href="../../Composite/Maps/index.html#Name_map-lookup">map-lookup</a></span>(<a href="#Variable1432_M2"><i class="var">M<sub class="sub">2</sub></i></a>, <a href="#Variable1396_K"><i class="var">K</i></a>)),
<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_map-delete">map-delete</a></span>(<a href="#Variable1409_M1"><i class="var">M<sub class="sub">1</sub></i></a>, {<a href="#Variable1396_K"><i class="var">K</i></a>}), <span class="name"><a href="../../Composite/Maps/index.html#Name_map-delete">map-delete</a></span>(<a href="#Variable1432_M2"><i class="var">M<sub class="sub">2</sub></i></a>, {<a href="#Variable1396_K"><i class="var">K</i></a>}))),
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_fail">fail</a></span>)
<i class="keyword">Rule</i>
<a href="#Variable1657_P"><i class="var">P</i></a> : ~(<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-values">datatype-values</a></span>|<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_))
-----------------------------------------------
<span class="name"><a href="#Name_match">match</a></span>(<span id="Variable1649_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable1657_P"><i class="var">P</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>)
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<a href="#Variable1649_V"><i class="var">V</i></a>, <a href="#Variable1657_P"><i class="var">P</i></a>), <span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>( ), <span class="name"><a href="../../../Computations/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_match-loosely">match-loosely</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span></code></pre></div>
<code><span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<i class="var">V</i>, <i class="var">P</i>)</code> takes a (potentially structured) value <code><i class="var">V</i></code> and a
(potentially structured) pattern <code><i class="var">P</i></code>. Provided that the structure and all
components of <code><i class="var">P</i></code> loosely match the structure and corresponding components
of <code><i class="var">V</i></code>, the environments computed by the simple pattern matches are united.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span id="Variable1824_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span class="name"><a href="#Name_pattern">pattern</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable1834_X"><i class="var">X</i></span>))) ~> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_give">give</a></span>(<a href="#Variable1824_V"><i class="var">V</i></a>, <a href="#Variable1834_X"><i class="var">X</i></a>)
<i class="keyword">Rule</i>
<a href="#Variable1924_I2"><i class="var">I<sub class="sub">2</sub></i></a> =/= "pattern"
---------------------------------------------------
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-value">datatype-value</a></span>(<span id="Variable1895_I1"><i class="var">I<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable1905_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>),
<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-value">datatype-value</a></span>(<span id="Variable1924_I2"><i class="var">I<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable1934_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>))
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_sequential">sequential</a></span>(
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_check-true">check-true</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<a href="#Variable1895_I1"><i class="var">I<sub class="sub">1</sub></i></a>, <a href="#Variable1924_I2"><i class="var">I<sub class="sub">2</sub></i></a>)),
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_check-true">check-true</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<span class="name"><a href="../../Composite/Sequences/index.html#Name_length">length</a></span> <a href="#Variable1905_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></a>, <span class="name"><a href="../../Composite/Sequences/index.html#Name_length">length</a></span> <a href="#Variable1934_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></a>)),
<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_collateral">collateral</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_interleave-map">interleave-map</a></span>(
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-elements">tuple-elements</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>)),
<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple-zip">tuple-zip</a></span>(<span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple">tuple</a></span>(<a href="#Variable1905_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></a>), <span class="name"><a href="../../Composite/Tuples/index.html#Name_tuple">tuple</a></span>(<a href="#Variable1934_V2*"><i class="var">V<sub class="sub">2</sub><sup class="sup">*</sup></i></a>)))))
<i class="keyword">Rule</i>
<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable2144_M2"><i class="var">M<sub class="sub">2</sub></i></a>) == {}
-------------------------------------------------
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span id="Variable2121_M1"><i class="var">M<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_), <span id="Variable2144_M2"><i class="var">M<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_)) ~> <span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>()
<i class="keyword">Rule</i>
<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable2256_M2"><i class="var">M<sub class="sub">2</sub></i></a>) =/= {}
<span class="name"><a href="../../Composite/Sets/index.html#Name_some-element">some-element</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable2256_M2"><i class="var">M<sub class="sub">2</sub></i></a>)) ~> <span id="Variable2220_K"><i class="var">K</i></span>
--------------------------------------------------------------
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span id="Variable2233_M1"><i class="var">M<sub class="sub">1</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_), <span id="Variable2256_M2"><i class="var">M<sub class="sub">2</sub></i></span>:<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_))
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(
<span class="name"><a href="../../Composite/Sets/index.html#Name_is-in-set">is-in-set</a></span>(<a href="#Variable2220_K"><i class="var">K</i></a>, <span class="name"><a href="../../Composite/Maps/index.html#Name_dom">dom</a></span>(<a href="#Variable2233_M1"><i class="var">M<sub class="sub">1</sub></i></a>)),
<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_collateral">collateral</a></span>(
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_map-lookup">map-lookup</a></span>(<a href="#Variable2233_M1"><i class="var">M<sub class="sub">1</sub></i></a>, <a href="#Variable2220_K"><i class="var">K</i></a>), <span class="name"><a href="../../Composite/Maps/index.html#Name_map-lookup">map-lookup</a></span>(<a href="#Variable2256_M2"><i class="var">M<sub class="sub">2</sub></i></a>, <a href="#Variable2220_K"><i class="var">K</i></a>)),
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span class="name"><a href="../../Composite/Maps/index.html#Name_map-delete">map-delete</a></span>(<a href="#Variable2233_M1"><i class="var">M<sub class="sub">1</sub></i></a>, {<a href="#Variable2220_K"><i class="var">K</i></a>}), <span class="name"><a href="../../Composite/Maps/index.html#Name_map-delete">map-delete</a></span>(<a href="#Variable2256_M2"><i class="var">M<sub class="sub">2</sub></i></a>, {<a href="#Variable2220_K"><i class="var">K</i></a>}))),
<span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_fail">fail</a></span>)
<i class="keyword">Rule</i>
<a href="#Variable2481_P"><i class="var">P</i></a> : ~(<span class="name"><a href="../../Composite/Datatypes/index.html#Name_datatype-values">datatype-values</a></span>|<span class="name"><a href="../../Composite/Maps/index.html#Name_maps">maps</a></span>(_,_))
-------------------------------------------
<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span id="Variable2473_DV"><i class="var">DV</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable2481_P"><i class="var">P</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>)
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_if-true-else">if-true-else</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<a href="#Variable2473_DV"><i class="var">DV</i></a>, <a href="#Variable2481_P"><i class="var">P</i></a>), <span class="name"><a href="../../Composite/Maps/index.html#Name_map">map</a></span>( ), <span class="name"><a href="../../../Computations/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_case-match">case-match</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:=><span id="Variable2548_T'"><i class="var">T&prime;</i></span>) : =><span id="Variable2565_T'"><i class="var">T&prime;</i></span></code></pre></div>
<code><span class="name"><a href="#Name_case-match">case-match</a></span>(<i class="var">P</i>, <i class="var">X</i>)</code> matches <code><i class="var">P</i></code> exactly to the given value.
If the match succeeds, the computed bindings have scope <code><i class="var">X</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_case-match">case-match</a></span>(<span id="Variable2632_P"><i class="var">P</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable2640_X"><i class="var">X</i></span>) ~> <span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_scope">scope</a></span>(<span class="name"><a href="#Name_match">match</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable2632_P"><i class="var">P</i></a>), <a href="#Variable2640_X"><i class="var">X</i></a>)</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_case-match-loosely">case-match-loosely</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:=><span id="Variable2697_T'"><i class="var">T&prime;</i></span>) : =><span id="Variable2714_T'"><i class="var">T&prime;</i></span></code></pre></div>
<code><span class="name"><a href="#Name_case-match">case-match</a></span>(<i class="var">P</i>, <i class="var">X</i>)</code> matches <code><i class="var">P</i></code> loosely to the given value.
If the match succeeds, the computed bindings have scope <code><i class="var">X</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_case-match-loosely">case-match-loosely</a></span>(<span id="Variable2781_P"><i class="var">P</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable2789_X"><i class="var">X</i></span>) ~> <span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_scope">scope</a></span>(<span class="name"><a href="#Name_match-loosely">match-loosely</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>, <a href="#Variable2781_P"><i class="var">P</i></a>), <a href="#Variable2789_X"><i class="var">X</i></a>)</code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_case-variant-value">case-variant-value</span></span>(_:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span></code></pre></div>
<code><span class="name"><a href="#Name_case-variant-value">case-variant-value</a></span>(<i class="var">I</i>)</code> matches values of variant <code><i class="var">I</i></code>, then
giving the value contained in the variant.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_case-variant-value">case-variant-value</a></span>(<span id="Variable2892_I"><i class="var">I</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) ~>
<span class="name"><a href="#Name_case-match">case-match</a></span>(<span class="name"><a href="../../Composite/Variants/index.html#Name_variant">variant</a></span>(<a href="#Variable2892_I"><i class="var">I</i></a>, <span class="name"><a href="#Name_pattern-any">pattern-any</a></span>), <span class="name"><a href="../../Composite/Variants/index.html#Name_variant-value">variant-value</a></span>(<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>))</code></pre></div>
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Patterns.cbs]: Patterns.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%20Values/Abstraction/Patterns/Patterns.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"

View File

@@ -0,0 +1,14 @@
general {
funcon-term:
initialise-giving
initialise-binding
give({"a"|->false,"b"|->true},
case-match-loosely(
{"b"|->pattern-bind"d"},
bound-value"d"))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,14 @@
general {
funcon-term:
initialise-giving
initialise-binding
give({"a"|->false,"b"|->true},
case-match(
{"b"|->pattern-bind"d","a"|->pattern-bind"c"},
bound-value"d"))
;
}
tests {
result-term: true;
}

View File

@@ -0,0 +1,18 @@
general {
funcon-term:
initialise-giving
initialise-binding
give(
variant("a",true),
sequential (
print case-variant-value("a"),
else(
effect case-variant-value"b",
print"OK")))
;
}
tests {
result-term: null-value;
standard-out: [true, "OK"];
}

View File

@@ -0,0 +1,36 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(
match-loosely([],[]), map()),
check-true is-equal(
match-loosely([false],[pattern-bind"b"]),
{"b"|->false}),
check-true is-equal(
match-loosely([false,true],[pattern-bind"a",pattern-bind"b"]),
{"a"|->false,"b"|->true}),
check-true is-equal(
match-loosely({"a"|->false},map()), map()),
check-true is-equal(
match-loosely({"a"|->false,"b"|->true},{"b"|->pattern-bind"d"}),
{"d"|->true}),
check-true is-equal(
match-loosely(true,true), map()),
else(
effect match-loosely([],[false]),
effect match-loosely([false],[false,false]),
effect match-loosely([false,true],[pattern-bind"a",pattern-bind"a"]),
effect match-loosely(map(),{"a"|->true}),
effect match-loosely({"a"|->true},{"a"|->false}),
effect match-loosely({"b"|->true},{"b"|->pattern-any,"c"|->pattern-any}),
effect match-loosely(false,true),
print"OK"))
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,35 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(
match([],[]), map()),
check-true is-equal(
match([false],[pattern-bind"b"]),
{"b"|->false}),
check-true is-equal(
match([false,true],[pattern-bind"a",pattern-bind"b"]),
{"a"|->false,"b"|->true}),
check-true is-equal(
match(map(),map()), map()),
check-true is-equal(
match({"a"|->false,"b"|->true},{"b"|->pattern-bind"d","a"|->pattern-bind"c"}),
{"c"|->false,"d"|->true}),
check-true is-equal(
match(true,true), map()),
else(
effect match([],[false]),
effect match([false],[false,false]),
effect match([false,true],[pattern-bind"a",pattern-bind"a"]),
effect match(map(),{"a"|->true}),
effect match({"b"|->true},{"b"|->pattern-any,"c"|->pattern-any}),
effect match(false,true),
print"OK"))
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,18 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(match(not true,pattern-any), map()),
check-true is-equal(match([42],pattern-any), map()),
check-true is-equal(match(abstraction null-value,pattern-any), map()),
check-true is-equal(match(list(42),pattern-any), map()),
check-true is-equal(match(tuple(42),pattern-any), map()),
print"OK")
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,19 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(match(false,pattern-bind"it"), {"it"|->false}),
check-true is-equal(match([42],pattern-bind"it"), {"it"|->[42]}),
check-true is-equal(dom match(abstraction null-value,pattern-bind"it"), {"it"}),
check-true is-equal(match(abstraction 12,abstraction(pattern-bind "it")), {"it" |-> 12}),
check-true is-equal(match(vector(42),pattern-bind"it"), {"it"|->vector(42)}),
check-true is-equal(match(tuple(42),pattern-bind"it"), {"it"|->tuple(42)}),
print"OK")
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,19 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(
match(false,pattern-else(pattern-bind"a",pattern-bind"b")), {"a"|->false}),
check-true is-equal(
match(false,pattern-else(pattern-type integers,pattern-bind"b")), {"b"|->false}),
else(
effect match(false,pattern-else(pattern-type integers,pattern-type atoms)),
print"OK"))
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,24 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(match(false,pattern-type booleans), map()),
check-true is-equal(match([42],pattern-type lists(integers)), map()),
check-true is-equal(match(abstraction null-value,pattern-type abstractions(values=>values)), map()),
check-true is-equal(match(list(true),pattern-type lists(booleans)), map()),
check-true is-equal(match(tuple(42,true),pattern-type tuples(integers,booleans)), map()),
effect else(
match(true,pattern-type integers),
match([42],pattern-type lists(booleans)),
match(abstraction null-value,pattern-type atoms),
match(list(true),pattern-type lists(integers)),
match(tuple(42,true),pattern-type tuples(booleans,integers)),
print"OK"))
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,19 @@
general {
funcon-term:
initialise-giving
initialise-binding
sequential(
check-true is-equal(
match(false,pattern-unite(pattern-bind"a",pattern-bind"b")), {"a"|->false,"b"|->false}),
check-true is-equal(
match(false,pattern-unite(pattern-type booleans,pattern-bind"b")), {"b"|->false}),
else(
effect match(false,pattern-unite(pattern-bind"a",pattern-bind"a")),
print"OK"))
;
}
tests {
result-term: null-value;
standard-out: ["OK"];
}

View File

@@ -0,0 +1,30 @@
### Thunks
[
Datatype thunks
Funcon thunk
Funcon force
]
Meta-variables
T <: values
Datatype
thunks(T) ::= thunk(_:abstractions(()=>T))
/*
`thunks(T)` consists of abstractions whose bodies do not depend on
a given value, and whose executions normally compute values of type `T`.
`thunk(abstraction(X))` evaluates to a thunk with dynamic bindings,
`thunk(closure(X))` computes a thunk with static bindings.
*/
Funcon
force(_:thunks(T)) : =>T
/*
`force(H)` enacts the abstraction of the thunk `H`.
*/
Rule
force(thunk(abstraction(X))) ~> no-given(X)

View File

@@ -0,0 +1,68 @@
---
layout: default
title: "Thunks"
parent: Abstraction
ancestor: Funcons-beta
---
[Funcons-beta] : [Thunks.cbs]
-----------------------------
### Thunks
<div class="highlighter-rouge"><pre class="highlight"><code>[
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_thunks">thunks</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_thunk">thunk</a></span>
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_force">force</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="../../Value-Types/index.html#Name_values">values</a></span></code></pre></div>
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
<span class="name"><span id="Name_thunks">thunks</span></span>(<span id="Variable40_T"><i class="var">T</i></span>) ::= <span id="Name_thunk">thunk</span>(_:<span class="name"><a href="../Generic/index.html#Name_abstractions">abstractions</a></span>(()=><span id="Variable62_T"><i class="var">T</i></span>))</code></pre></div>
<code><span class="name"><a href="#Name_thunks">thunks</a></span>(<i class="var">T</i>)</code> consists of abstractions whose bodies do not depend on
a given value, and whose executions normally compute values of type <code><i class="var">T</i></code>.
<code><span class="name"><a href="#Name_thunk">thunk</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<i class="var">X</i>))</code> evaluates to a thunk with dynamic bindings,
<code><span class="name"><a href="#Name_thunk">thunk</a></span>(<span class="name"><a href="../Generic/index.html#Name_closure">closure</a></span>(<i class="var">X</i>))</code> computes a thunk with static bindings.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
<span class="name"><span id="Name_force">force</span></span>(_:<span class="name"><a href="#Name_thunks">thunks</a></span>(<span id="Variable187_T"><i class="var">T</i></span>)) : =><span id="Variable207_T"><i class="var">T</i></span></code></pre></div>
<code><span class="name"><a href="#Name_force">force</a></span>(<i class="var">H</i>)</code> enacts the abstraction of the thunk <code><i class="var">H</i></code>.
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
<span class="name"><a href="#Name_force">force</a></span>(<span class="name"><a href="#Name_thunk">thunk</a></span>(<span class="name"><a href="../Generic/index.html#Name_abstraction">abstraction</a></span>(<span id="Variable257_X"><i class="var">X</i></span>))) ~> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_no-given">no-given</a></span>(<a href="#Variable257_X"><i class="var">X</i></a>)</code></pre></div>
____
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
[Thunks.cbs]: Thunks.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%20Values/Abstraction/Thunks/Thunks.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
"GENERATE AN EMAIL TEMPLATE"

View File

@@ -0,0 +1,25 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",99),
give(
tuple(
99,
thunk abstraction(
sequential(
print bound-value"x",
print first tuple-elements bound-value"tup"))),
scope(
collateral(
bind-value("x",42),
bind-value("tup",tuple(42, second tuple-elements given))),
force second tuple-elements given)))
;
}
tests {
result-term: null-value;
standard-out: [42, 42];
}

View File

@@ -0,0 +1,27 @@
general {
funcon-term:
initialise-giving
initialise-binding
scope(
bind-value("x",99),
give(
tuple(
99,
thunk closure(
sequential(
print bound-value"x",
print first tuple-elements bound-value"tup"))),
scope(
collateral(
bind-value("x",42),
bind-value("tup",tuple(42, second tuple-elements given))),
else(
force second tuple-elements given,
print 77))))
;
}
tests {
result-term: null-value;
standard-out: [99, 77];
}