init commit again
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
135
IBAF-cbs/Funcons-beta/Values/Abstraction/Functions/index.md
Normal file
135
IBAF-cbs/Funcons-beta/Values/Abstraction/Functions/index.md
Normal 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′</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′</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′</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′</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′</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′</i></span>), _:<span id="Variable281_T"><i class="var">T</i></span>) : =><span id="Variable297_T'"><i class="var">T′</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′</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′</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′</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′</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′</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′</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′</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′</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′</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′</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"
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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)];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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)];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
49
IBAF-cbs/Funcons-beta/Values/Abstraction/Generic/Generic.cbs
Normal file
49
IBAF-cbs/Funcons-beta/Values/Abstraction/Generic/Generic.cbs
Normal 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
|
||||
85
IBAF-cbs/Funcons-beta/Values/Abstraction/Generic/index.md
Normal file
85
IBAF-cbs/Funcons-beta/Values/Abstraction/Generic/index.md
Normal 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"
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
224
IBAF-cbs/Funcons-beta/Values/Abstraction/Patterns/Patterns.cbs
Normal file
224
IBAF-cbs/Funcons-beta/Values/Abstraction/Patterns/Patterns.cbs
Normal 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))
|
||||
267
IBAF-cbs/Funcons-beta/Values/Abstraction/Patterns/index.md
Normal file
267
IBAF-cbs/Funcons-beta/Values/Abstraction/Patterns/index.md
Normal 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′</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′</i></span>) : =><span id="Variable2565_T'"><i class="var">T′</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′</i></span>) : =><span id="Variable2714_T'"><i class="var">T′</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"
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
@@ -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"];
|
||||
}
|
||||
30
IBAF-cbs/Funcons-beta/Values/Abstraction/Thunks/Thunks.cbs
Normal file
30
IBAF-cbs/Funcons-beta/Values/Abstraction/Thunks/Thunks.cbs
Normal 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)
|
||||
68
IBAF-cbs/Funcons-beta/Values/Abstraction/Thunks/index.md
Normal file
68
IBAF-cbs/Funcons-beta/Values/Abstraction/Thunks/index.md
Normal 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"
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
110
IBAF-cbs/Funcons-beta/Values/Composite/Bits/Bits.cbs
Normal file
110
IBAF-cbs/Funcons-beta/Values/Composite/Bits/Bits.cbs
Normal file
@@ -0,0 +1,110 @@
|
||||
### Bits and bit vectors
|
||||
|
||||
[
|
||||
Type bits
|
||||
Datatype bit-vectors
|
||||
Funcon bit-vector
|
||||
Type bytes Alias octets
|
||||
Funcon bit-vector-not
|
||||
Funcon bit-vector-and
|
||||
Funcon bit-vector-or
|
||||
Funcon bit-vector-xor
|
||||
Funcon bit-vector-shift-left
|
||||
Funcon bit-vector-logical-shift-right
|
||||
Funcon bit-vector-arithmetic-shift-right
|
||||
Funcon integer-to-bit-vector
|
||||
Funcon bit-vector-to-integer
|
||||
Funcon bit-vector-to-natural
|
||||
Funcon unsigned-bit-vector-maximum
|
||||
Funcon signed-bit-vector-maximum
|
||||
Funcon signed-bit-vector-minimum
|
||||
Funcon is-in-signed-bit-vector
|
||||
Funcon is-in-unsigned-bit-vector
|
||||
]
|
||||
|
||||
|
||||
#### Bits
|
||||
|
||||
Type
|
||||
bits ~> booleans
|
||||
/*
|
||||
`false` represents the absence of a bit, `true` its presence.
|
||||
*/
|
||||
|
||||
|
||||
#### Bit vectors
|
||||
|
||||
Datatype
|
||||
bit-vectors(N:natural-numbers) ::= bit-vector(_:bits^N)
|
||||
|
||||
Type
|
||||
bytes ~> bit-vectors(8)
|
||||
Alias
|
||||
octets = bytes
|
||||
|
||||
Meta-variables
|
||||
BT <: bit-vectors(_)
|
||||
|
||||
Built-in Funcon
|
||||
bit-vector-not(_:BT) : =>BT
|
||||
Built-in Funcon
|
||||
bit-vector-and(_:BT, _:BT) : =>BT
|
||||
Built-in Funcon
|
||||
bit-vector-or(_:BT, _:BT) : =>BT
|
||||
Built-in Funcon
|
||||
bit-vector-xor(_:BT, _:BT) : =>BT
|
||||
/*
|
||||
The above four funcons are the natural extensions of funcons from `booleans`
|
||||
to `bit-vectors(N)` of the same length.
|
||||
*/
|
||||
|
||||
Built-in Funcon
|
||||
bit-vector-shift-left(_:BT, _:natural-numbers) : BT
|
||||
Built-in Funcon
|
||||
bit-vector-logical-shift-right(_:BT, _:natural-numbers) : BT
|
||||
Built-in Funcon
|
||||
bit-vector-arithmetic-shift-right(_:BT, _:natural-numbers) : BT
|
||||
|
||||
Built-in Funcon
|
||||
integer-to-bit-vector(_:integers, N:natural-numbers) : bit-vectors(N)
|
||||
/*
|
||||
`integer-to-bit-vector(M, N)` converts an integer `M` to a bit-vector of
|
||||
length `N`, using Two's Complement representation. If the integer is out of
|
||||
range of the representation, it will wrap around (modulo 2^N).
|
||||
*/
|
||||
|
||||
Built-in Funcon
|
||||
bit-vector-to-integer(_:BT) : =>integers
|
||||
/*
|
||||
`bit-vector-to-integer(B)` interprets a bit-vector `BV` as an integer
|
||||
in Two's Complement representation.
|
||||
*/
|
||||
|
||||
Built-in Funcon
|
||||
bit-vector-to-natural(_:BT) : =>natural-numbers
|
||||
/*
|
||||
`bit-vector-to-natural(BV)` interprets a bit-vector `BV` as a natural number
|
||||
in unsigned representation.
|
||||
*/
|
||||
|
||||
Funcon
|
||||
unsigned-bit-vector-maximum(N:natural-numbers) : =>natural-numbers
|
||||
~> integer-subtract(integer-power(2, N), 1)
|
||||
|
||||
Funcon
|
||||
signed-bit-vector-maximum(N:natural-numbers) : =>integers
|
||||
~> integer-subtract(integer-power(2, integer-subtract(N, 1)), 1)
|
||||
|
||||
Funcon
|
||||
signed-bit-vector-minimum(N:natural-numbers) : =>integers
|
||||
~> integer-negate(integer-power(2, integer-subtract(N, 1)))
|
||||
|
||||
Funcon
|
||||
is-in-signed-bit-vector(M:integers, N:natural-numbers) : =>booleans
|
||||
~> and(integer-is-less-or-equal(M, signed-bit-vector-maximum(N)),
|
||||
integer-is-greater-or-equal(M, signed-bit-vector-minimum(N)))
|
||||
|
||||
Funcon
|
||||
is-in-unsigned-bit-vector(M:integers, N:natural-numbers) : =>booleans
|
||||
~> and(integer-is-less-or-equal(M, unsigned-bit-vector-maximum(N)),
|
||||
integer-is-greater-or-equal(M, 0))
|
||||
152
IBAF-cbs/Funcons-beta/Values/Composite/Bits/index.md
Normal file
152
IBAF-cbs/Funcons-beta/Values/Composite/Bits/index.md
Normal file
@@ -0,0 +1,152 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Bits"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Bits.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Bits and bit vectors
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_bits">bits</a></span>
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_bit-vectors">bit-vectors</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector">bit-vector</a></span>
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_bytes">bytes</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_octets">octets</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-not">bit-vector-not</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-and">bit-vector-and</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-or">bit-vector-or</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-xor">bit-vector-xor</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-shift-left">bit-vector-shift-left</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-logical-shift-right">bit-vector-logical-shift-right</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-arithmetic-shift-right">bit-vector-arithmetic-shift-right</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_integer-to-bit-vector">integer-to-bit-vector</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-to-integer">bit-vector-to-integer</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_bit-vector-to-natural">bit-vector-to-natural</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_unsigned-bit-vector-maximum">unsigned-bit-vector-maximum</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_signed-bit-vector-maximum">signed-bit-vector-maximum</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_signed-bit-vector-minimum">signed-bit-vector-minimum</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-in-signed-bit-vector">is-in-signed-bit-vector</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-in-unsigned-bit-vector">is-in-unsigned-bit-vector</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
#### Bits
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_bits">bits</span></span> ~> <span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="../../Primitive/Booleans/index.html#Name_false">false</a></span></code> represents the absence of a bit, <code><span class="name"><a href="../../Primitive/Booleans/index.html#Name_true">true</a></span></code> its presence.
|
||||
|
||||
|
||||
|
||||
#### Bit vectors
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
|
||||
<span class="name"><span id="Name_bit-vectors">bit-vectors</span></span>(<span id="Variable145_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) ::= <span id="Name_bit-vector">bit-vector</span>(_:<span class="name"><a href="#Name_bits">bits</a></span>^<span id="Variable166_N"><i class="var">N</i></span>)</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_bytes">bytes</span></span> ~> <span class="name"><a href="#Name_bit-vectors">bit-vectors</a></span>(8)
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_octets">octets</span></span> = <span class="name"><a href="#Name_bytes">bytes</a></span></code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
|
||||
<span id="PartVariable_BT"><i class="var">BT</i></span> <: <span class="name"><a href="#Name_bit-vectors">bit-vectors</a></span>(_)</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-not">bit-vector-not</span></span>(_:<span id="Variable234_BT"><i class="var">BT</i></span>) : =><span id="Variable248_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-and">bit-vector-and</span></span>(_:<span id="Variable261_BT"><i class="var">BT</i></span>, _:<span id="Variable272_BT"><i class="var">BT</i></span>) : =><span id="Variable287_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-or">bit-vector-or</span></span>(_:<span id="Variable300_BT"><i class="var">BT</i></span>, _:<span id="Variable311_BT"><i class="var">BT</i></span>) : =><span id="Variable326_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-xor">bit-vector-xor</span></span>(_:<span id="Variable339_BT"><i class="var">BT</i></span>, _:<span id="Variable350_BT"><i class="var">BT</i></span>) : =><span id="Variable365_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
|
||||
The above four funcons are the natural extensions of funcons from <code><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code>
|
||||
to <code><span class="name"><a href="#Name_bit-vectors">bit-vectors</a></span>(<i class="var">N</i>)</code> of the same length.
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-shift-left">bit-vector-shift-left</span></span>(_:<span id="Variable414_BT"><i class="var">BT</i></span>, _:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : <span id="Variable436_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-logical-shift-right">bit-vector-logical-shift-right</span></span>(_:<span id="Variable448_BT"><i class="var">BT</i></span>, _:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : <span id="Variable470_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-arithmetic-shift-right">bit-vector-arithmetic-shift-right</span></span>(_:<span id="Variable482_BT"><i class="var">BT</i></span>, _:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : <span id="Variable504_BT"><i class="var">BT</i></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_integer-to-bit-vector">integer-to-bit-vector</span></span>(_:<span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span>, <span id="Variable521_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : <span class="name"><a href="#Name_bit-vectors">bit-vectors</a></span>(<span id="Variable537_N"><i class="var">N</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_integer-to-bit-vector">integer-to-bit-vector</a></span>(<i class="var">M</i>, <i class="var">N</i>)</code> converts an integer <code><i class="var">M</i></code> to a bit-vector of
|
||||
length <code><i class="var">N</i></code>, using Two's Complement representation. If the integer is out of
|
||||
range of the representation, it will wrap around (modulo 2^N).
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-to-integer">bit-vector-to-integer</span></span>(_:<span id="Variable613_BT"><i class="var">BT</i></span>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_bit-vector-to-integer">bit-vector-to-integer</a></span>(<i class="var">B</i>)</code> interprets a bit-vector <code><i class="var">BV</i></code> as an integer
|
||||
in Two's Complement representation.
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_bit-vector-to-natural">bit-vector-to-natural</span></span>(_:<span id="Variable676_BT"><i class="var">BT</i></span>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_bit-vector-to-natural">bit-vector-to-natural</a></span>(<i class="var">BV</i>)</code> interprets a bit-vector <code><i class="var">BV</i></code> as a natural number
|
||||
in unsigned representation.
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_unsigned-bit-vector-maximum">unsigned-bit-vector-maximum</span></span>(<span id="Variable736_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>
|
||||
~> <span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-subtract">integer-subtract</a></span>(<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-power">integer-power</a></span>(2, <a href="#Variable736_N"><i class="var">N</i></a>), 1)</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_signed-bit-vector-maximum">signed-bit-vector-maximum</span></span>(<span id="Variable783_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span>
|
||||
~> <span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-subtract">integer-subtract</a></span>(<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-power">integer-power</a></span>(2, <span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-subtract">integer-subtract</a></span>(<a href="#Variable783_N"><i class="var">N</i></a>, 1)), 1)</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_signed-bit-vector-minimum">signed-bit-vector-minimum</span></span>(<span id="Variable840_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span>
|
||||
~> <span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-negate">integer-negate</a></span>(<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-power">integer-power</a></span>(2, <span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-subtract">integer-subtract</a></span>(<a href="#Variable840_N"><i class="var">N</i></a>, 1)))</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-in-signed-bit-vector">is-in-signed-bit-vector</span></span>(<span id="Variable894_M"><i class="var">M</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span>, <span id="Variable903_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span>
|
||||
~> <span class="name"><a href="../../Primitive/Booleans/index.html#Name_and">and</a></span>(<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-is-less-or-equal">integer-is-less-or-equal</a></span>(<a href="#Variable894_M"><i class="var">M</i></a>, <span class="name"><a href="#Name_signed-bit-vector-maximum">signed-bit-vector-maximum</a></span>(<a href="#Variable903_N"><i class="var">N</i></a>)),
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-is-greater-or-equal">integer-is-greater-or-equal</a></span>(<a href="#Variable894_M"><i class="var">M</i></a>, <span class="name"><a href="#Name_signed-bit-vector-minimum">signed-bit-vector-minimum</a></span>(<a href="#Variable903_N"><i class="var">N</i></a>)))</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-in-unsigned-bit-vector">is-in-unsigned-bit-vector</span></span>(<span id="Variable984_M"><i class="var">M</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_integers">integers</a></span>, <span id="Variable993_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span>
|
||||
~> <span class="name"><a href="../../Primitive/Booleans/index.html#Name_and">and</a></span>(<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-is-less-or-equal">integer-is-less-or-equal</a></span>(<a href="#Variable984_M"><i class="var">M</i></a>, <span class="name"><a href="#Name_unsigned-bit-vector-maximum">unsigned-bit-vector-maximum</a></span>(<a href="#Variable993_N"><i class="var">N</i></a>)),
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_integer-is-greater-or-equal">integer-is-greater-or-equal</a></span>(<a href="#Variable984_M"><i class="var">M</i></a>, 0))</code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Bits.cbs]: Bits.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/Composite/Bits/Bits.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
86
IBAF-cbs/Funcons-beta/Values/Composite/Classes/Classes.cbs
Normal file
86
IBAF-cbs/Funcons-beta/Values/Composite/Classes/Classes.cbs
Normal file
@@ -0,0 +1,86 @@
|
||||
### Classes
|
||||
|
||||
[
|
||||
Datatype classes
|
||||
Funcon class
|
||||
Funcon class-instantiator
|
||||
Funcon class-feature-map
|
||||
Funcon class-superclass-name-sequence
|
||||
Funcon class-name-tree
|
||||
Funcon is-subclass-name
|
||||
Funcon class-name-single-inheritance-feature-map
|
||||
]
|
||||
|
||||
|
||||
Datatype
|
||||
classes ::=
|
||||
class(_:thunks(references(objects)), _:environments, _:identifiers*)
|
||||
/*
|
||||
`class(Thunk, Env, C*)` is a class with:
|
||||
* a thunk `Thunk` for instantiating the class,
|
||||
* an environment `Env` with the features declared by the class, and
|
||||
* a sequence `C*` of names of direct superclasses.
|
||||
`class(Thunk, Env)` is a base class, having no superclasses.
|
||||
`class(Thunk, Env, C)` is a class with a single superclass.
|
||||
|
||||
Class instantiation forces its thunk to compute a reference to an object.
|
||||
|
||||
Features are inherited from superclasses. When features with the same name
|
||||
are declared in simultaneously inherited classes, the order of the superclass
|
||||
identifiers in `C*` may affect resolution of references to features.
|
||||
Overloading of feature names is supported by using type maps as features.
|
||||
|
||||
The class table is represented by binding class names to classes.
|
||||
The class superclass hierarchy is assumed to be acyclic.
|
||||
*/
|
||||
|
||||
Funcon
|
||||
class-instantiator(_:classes) : =>thunks(references(objects))
|
||||
Rule
|
||||
class-instantiator
|
||||
class(Thunk:thunks(_), Envs:environments, C*:identifiers*) ~> Thunk
|
||||
|
||||
Funcon
|
||||
class-feature-map(_:classes) : =>environments
|
||||
Rule
|
||||
class-feature-map
|
||||
class(Thunk:thunks(_), Env:environments, C*:identifiers*) ~> Env
|
||||
|
||||
Funcon
|
||||
class-superclass-name-sequence(_:classes) : =>identifiers*
|
||||
Rule
|
||||
class-superclass-name-sequence
|
||||
class(Thunk:thunks(_), Env:environments, C*:identifiers*) ~> C*
|
||||
|
||||
Funcon
|
||||
class-name-tree(_:identifiers) : =>trees(identifiers)
|
||||
/*
|
||||
`class-name-tree C` forms a tree where the branches are the class name
|
||||
trees for the superclasses of `C`.
|
||||
*/
|
||||
Rule
|
||||
class-name-tree(C : identifiers)
|
||||
~> tree(C,
|
||||
interleave-map(
|
||||
class-name-tree given,
|
||||
class-superclass-name-sequence bound-value C))
|
||||
|
||||
|
||||
Funcon
|
||||
is-subclass-name(C:identifiers, C':identifiers) : =>booleans
|
||||
~> is-in-set(C, { forest-value-sequence class-name-tree C' })
|
||||
/*
|
||||
The result of `is-subclass-name(C, C')` does not depend on the order of
|
||||
the names in `forest-value-sequence class-name-tree C'`.
|
||||
*/
|
||||
|
||||
|
||||
Funcon
|
||||
class-name-single-inheritance-feature-map(C:identifiers) : =>environments
|
||||
~> map-override interleave-map(
|
||||
class-feature-map bound-value given,
|
||||
single-branching-sequence class-name-tree C)
|
||||
/*
|
||||
For multiple inheritance, different resolution orders can be specified
|
||||
by using different linearisations of the class name tree.
|
||||
*/
|
||||
125
IBAF-cbs/Funcons-beta/Values/Composite/Classes/index.md
Normal file
125
IBAF-cbs/Funcons-beta/Values/Composite/Classes/index.md
Normal file
@@ -0,0 +1,125 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Classes"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Classes.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Classes
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_classes">classes</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class">class</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class-instantiator">class-instantiator</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class-feature-map">class-feature-map</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class-superclass-name-sequence">class-superclass-name-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-subclass-name">is-subclass-name</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_class-name-single-inheritance-feature-map">class-name-single-inheritance-feature-map</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
|
||||
<span class="name"><span id="Name_classes">classes</span></span> ::=
|
||||
<span id="Name_class">class</span>(_:<span class="name"><a href="../../Abstraction/Thunks/index.html#Name_thunks">thunks</a></span>(<span class="name"><a href="../References/index.html#Name_references">references</a></span>(<span class="name"><a href="../Objects/index.html#Name_objects">objects</a></span>)), _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span><sup class="sup">*</sup>)</code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_class">class</a></span>(<i class="var">Thunk</i>, <i class="var">Env</i>, <i class="var">C<sup class="sup">*</sup></i>)</code> is a class with:
|
||||
* a thunk <code><i class="var">Thunk</i></code> for instantiating the class,
|
||||
* an environment <code><i class="var">Env</i></code> with the features declared by the class, and
|
||||
* a sequence <code><i class="var">C<sup class="sup">*</sup></i></code> of names of direct superclasses.
|
||||
<code><span class="name"><a href="#Name_class">class</a></span>(<i class="var">Thunk</i>, <i class="var">Env</i>)</code> is a base class, having no superclasses.
|
||||
<code><span class="name"><a href="#Name_class">class</a></span>(<i class="var">Thunk</i>, <i class="var">Env</i>, <i class="var">C</i>)</code> is a class with a single superclass.
|
||||
|
||||
Class instantiation forces its thunk to compute a reference to an object.
|
||||
|
||||
Features are inherited from superclasses. When features with the same name
|
||||
are declared in simultaneously inherited classes, the order of the superclass
|
||||
identifiers in <code><i class="var">C<sup class="sup">*</sup></i></code> may affect resolution of references to features.
|
||||
Overloading of feature names is supported by using type maps as features.
|
||||
|
||||
The class table is represented by binding class names to classes.
|
||||
The class superclass hierarchy is assumed to be acyclic.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_class-instantiator">class-instantiator</span></span>(_:<span class="name"><a href="#Name_classes">classes</a></span>) : =><span class="name"><a href="../../Abstraction/Thunks/index.html#Name_thunks">thunks</a></span>(<span class="name"><a href="../References/index.html#Name_references">references</a></span>(<span class="name"><a href="../Objects/index.html#Name_objects">objects</a></span>))
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_class-instantiator">class-instantiator</a></span>
|
||||
<span class="name"><a href="#Name_class">class</a></span>(<span id="Variable308_Thunk"><i class="var">Thunk</i></span>:<span class="name"><a href="../../Abstraction/Thunks/index.html#Name_thunks">thunks</a></span>(_), <span id="Variable325_Envs"><i class="var">Envs</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, <span id="Variable334_C*"><i class="var">C<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span><sup class="sup">*</sup>) ~> <a href="#Variable308_Thunk"><i class="var">Thunk</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_class-feature-map">class-feature-map</span></span>(_:<span class="name"><a href="#Name_classes">classes</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_class-feature-map">class-feature-map</a></span>
|
||||
<span class="name"><a href="#Name_class">class</a></span>(<span id="Variable383_Thunk"><i class="var">Thunk</i></span>:<span class="name"><a href="../../Abstraction/Thunks/index.html#Name_thunks">thunks</a></span>(_), <span id="Variable400_Env"><i class="var">Env</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, <span id="Variable409_C*"><i class="var">C<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span><sup class="sup">*</sup>) ~> <a href="#Variable400_Env"><i class="var">Env</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_class-superclass-name-sequence">class-superclass-name-sequence</span></span>(_:<span class="name"><a href="#Name_classes">classes</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span><sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_class-superclass-name-sequence">class-superclass-name-sequence</a></span>
|
||||
<span class="name"><a href="#Name_class">class</a></span>(<span id="Variable460_Thunk"><i class="var">Thunk</i></span>:<span class="name"><a href="../../Abstraction/Thunks/index.html#Name_thunks">thunks</a></span>(_), <span id="Variable477_Env"><i class="var">Env</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, <span id="Variable486_C*"><i class="var">C<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span><sup class="sup">*</sup>) ~> <a href="#Variable486_C*"><i class="var">C<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_class-name-tree">class-name-tree</span></span>(_:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../Trees/index.html#Name_trees">trees</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span> <i class="var">C</i></code> forms a tree where the branches are the class name
|
||||
trees for the superclasses of <code><i class="var">C</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span>(<span id="Variable576_C"><i class="var">C</i></span> : <span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>)
|
||||
~> <span class="name"><a href="../Trees/index.html#Name_tree">tree</a></span>(<a href="#Variable576_C"><i class="var">C</i></a>,
|
||||
<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_interleave-map">interleave-map</a></span>(
|
||||
<span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>,
|
||||
<span class="name"><a href="#Name_class-superclass-name-sequence">class-superclass-name-sequence</a></span> <span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_bound-value">bound-value</a></span> <a href="#Variable576_C"><i class="var">C</i></a>))</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-subclass-name">is-subclass-name</span></span>(<span id="Variable628_C"><i class="var">C</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable638_C'"><i class="var">C′</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span>
|
||||
~> <span class="name"><a href="../Sets/index.html#Name_is-in-set">is-in-set</a></span>(<a href="#Variable628_C"><i class="var">C</i></a>, { <span class="name"><a href="../Trees/index.html#Name_forest-value-sequence">forest-value-sequence</a></span> <span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span> <a href="#Variable638_C'"><i class="var">C′</i></a> })</code></pre></div>
|
||||
|
||||
|
||||
The result of <code><span class="name"><a href="#Name_is-subclass-name">is-subclass-name</a></span>(<i class="var">C</i>, <i class="var">C′</i>)</code> does not depend on the order of
|
||||
the names in <code><span class="name"><a href="../Trees/index.html#Name_forest-value-sequence">forest-value-sequence</a></span> <span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span> <i class="var">C′</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_class-name-single-inheritance-feature-map">class-name-single-inheritance-feature-map</span></span>(<span id="Variable740_C"><i class="var">C</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>
|
||||
~> <span class="name"><a href="../Maps/index.html#Name_map-override">map-override</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_class-feature-map">class-feature-map</a></span> <span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_bound-value">bound-value</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>,
|
||||
<span class="name"><a href="../Trees/index.html#Name_single-branching-sequence">single-branching-sequence</a></span> <span class="name"><a href="#Name_class-name-tree">class-name-tree</a></span> <a href="#Variable740_C"><i class="var">C</i></a>)</code></pre></div>
|
||||
|
||||
|
||||
For multiple inheritance, different resolution orders can be specified
|
||||
by using different linearisations of the class name tree.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Classes.cbs]: Classes.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/Composite/Classes/Classes.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,120 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
{"a" |-> 1}, "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
{"k1" |-> 1, "a" |-> 2} , "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print class-feature-map bound-value "O",
|
||||
print class-feature-map bound-value "A",
|
||||
print class-feature-map bound-value "K1"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
map()
|
||||
,
|
||||
{"a" |-> 1 }
|
||||
,
|
||||
{"k1" |-> 1, "a" |-> 2}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print class-instantiator bound-value "O",
|
||||
print class-instantiator bound-value "A",
|
||||
print class-instantiator bound-value "K1"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map())
|
||||
,
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map()))
|
||||
,
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map())))
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
{"a" |-> 1}, "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
{"k1" |-> 1, "a" |-> 2} , "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"K4" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
{"k4" |-> 1, "a" |-> 2}, "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print class-name-single-inheritance-feature-map "O",
|
||||
print class-name-single-inheritance-feature-map "A",
|
||||
print class-name-single-inheritance-feature-map "K4"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
map()
|
||||
,
|
||||
{"a" |-> 1 }
|
||||
,
|
||||
{"k4" |-> 1, "a" |-> 2}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print class-name-tree "O",
|
||||
print class-name-tree "A",
|
||||
print class-name-tree "K1",
|
||||
print class-name-tree "Z"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
tree("O")
|
||||
,
|
||||
tree("A", tree("O"))
|
||||
,
|
||||
tree("K1", tree("A", tree("O")), tree("B", tree("O")), tree("C", tree("O")))
|
||||
,
|
||||
tree("Z",
|
||||
tree("K1", tree("A", tree("O")), tree("B", tree("O")), tree("C", tree("O")))
|
||||
,
|
||||
tree("K2", tree("D", tree("O")), tree("B", tree("O")), tree("E", tree("O")))
|
||||
,
|
||||
tree("K3", tree("D", tree("O")), tree("A", tree("O")))
|
||||
)
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print [class-superclass-name-sequence bound-value "O"],
|
||||
print [class-superclass-name-sequence bound-value "A"],
|
||||
print [class-superclass-name-sequence bound-value "K1"]
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[]
|
||||
,
|
||||
["O"]
|
||||
,
|
||||
["A", "B", "C"]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print bound-value "O",
|
||||
print bound-value "A",
|
||||
print bound-value "K1",
|
||||
print bound-value "Z"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
class(thunk abstraction reference object(fresh-atom,"O",map()), map())
|
||||
,
|
||||
class(thunk abstraction reference
|
||||
object(fresh-atom,"A",map(), object(fresh-atom,"O",map())), map(), "O")
|
||||
,
|
||||
class(thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")
|
||||
,
|
||||
class(thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
//[https://en.wikipedia.org/wiki/C3_linearization]:
|
||||
//class O
|
||||
//class A extends O
|
||||
//class B extends O
|
||||
//class C extends O
|
||||
//class D extends O
|
||||
//class E extends O
|
||||
//class K1 extends A, B, C
|
||||
//class K2 extends D, B, E
|
||||
//class K3 extends D, A
|
||||
//class Z extends K1, K2, K3
|
||||
|
||||
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating initialise-binding finalise-failing
|
||||
scope(collateral(
|
||||
{"O" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"O",map()),
|
||||
map())}
|
||||
,
|
||||
{"A" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"A",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"B" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"C" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"C",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"D" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"E" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"O",map())),
|
||||
map(), "O")}
|
||||
,
|
||||
{"K1" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "A", "B", "C")}
|
||||
,
|
||||
{"K2" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "B", "E")}
|
||||
,
|
||||
{"K3" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map()))),
|
||||
map(), "D", "A")}
|
||||
,
|
||||
{"Z" |->
|
||||
class(
|
||||
thunk abstraction reference
|
||||
object(fresh-atom,"Z",map(),
|
||||
object(fresh-atom,"K1",map(),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"C",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K2",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"B",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"E",map(),object(fresh-atom,"O",map()))),
|
||||
object(fresh-atom,"K3",map(),
|
||||
object(fresh-atom,"D",map(),object(fresh-atom,"O",map())),
|
||||
object(fresh-atom,"A",map(),object(fresh-atom,"O",map())))),
|
||||
map(), "K1", "K2", "K3")}
|
||||
),
|
||||
sequential(
|
||||
print {forest-value-sequence class-name-tree "O"},
|
||||
print {forest-value-sequence class-name-tree "A"},
|
||||
print {forest-value-sequence class-name-tree "K1"},
|
||||
print {forest-value-sequence class-name-tree "K2"},
|
||||
print {forest-value-sequence class-name-tree "K3"},
|
||||
print {forest-value-sequence class-name-tree "Z"}
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{"O"},
|
||||
{"A","O"},
|
||||
{"A","B","C","K1","O"},
|
||||
{"B","D","E","K2","O"},
|
||||
{"A","D","K3","O"},
|
||||
{"A","B","C","D","E","K1","K2","K3","O","Z"}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
### Datatypes
|
||||
|
||||
[
|
||||
Type datatype-values
|
||||
Funcon datatype-value
|
||||
Funcon datatype-value-id
|
||||
Funcon datatype-value-elements
|
||||
]
|
||||
|
||||
/*
|
||||
A datatype value consists of an identifier and a sequence of values.
|
||||
|
||||
'Datatype T ::= ...' declares the type `T` to refer to a fresh value
|
||||
constructor in `types`, and asserts ``T <: datatype-values``.
|
||||
|
||||
Each constructor funcon 'F(_:T1,...,_:Tn)' of the datatype declaration
|
||||
generates values in `T` of the form `datatype-value("F", V1, ..., Vn)` from
|
||||
`V1:T1`, ..., `Vn:Tn`.
|
||||
|
||||
Note that a computation `X` cannot be directly included in datatype values:
|
||||
it is necessary to encapsulate it in `abstraction(X)`.
|
||||
|
||||
'Datatype T', followed by declarations of constructor funcons for 'T',
|
||||
allows specification of GADTs.
|
||||
*/
|
||||
|
||||
Built-in Type
|
||||
datatype-values
|
||||
|
||||
Built-in Funcon
|
||||
datatype-value(_:identifiers, _:values*) : datatype-values
|
||||
|
||||
Funcon
|
||||
datatype-value-id(_:datatype-values) : =>identifiers
|
||||
Rule
|
||||
datatype-value-id(datatype-value(I:identifiers, _*:values*)) ~> I
|
||||
|
||||
Funcon
|
||||
datatype-value-elements(_:datatype-values) : =>values*
|
||||
Rule
|
||||
datatype-value-elements(datatype-value(_:identifiers, V*:values*)) ~> V*
|
||||
76
IBAF-cbs/Funcons-beta/Values/Composite/Datatypes/index.md
Normal file
76
IBAF-cbs/Funcons-beta/Values/Composite/Datatypes/index.md
Normal file
@@ -0,0 +1,76 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Datatypes"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Datatypes.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Datatypes
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_datatype-values">datatype-values</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_datatype-value">datatype-value</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_datatype-value-id">datatype-value-id</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_datatype-value-elements">datatype-value-elements</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
A datatype value consists of an identifier and a sequence of values.
|
||||
|
||||
'Datatype T ::= ...' declares the type <code><i class="var">T</i></code> to refer to a fresh value
|
||||
constructor in <code><span class="name"><a href="../../Value-Types/index.html#Name_types">types</a></span></code>, and asserts <code><i class="var">T</i> <: <span class="name"><a href="#Name_datatype-values">datatype-values</a></span></code>.
|
||||
|
||||
Each constructor funcon 'F(_:T1,...,_:Tn)' of the datatype declaration
|
||||
generates values in <code><i class="var">T</i></code> of the form <code><span class="name"><a href="#Name_datatype-value">datatype-value</a></span>("F", <i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>)</code> from
|
||||
<code><i class="var">V<sub class="sub">1</sub></i>:<i class="var">T<sub class="sub">1</sub></i></code>, ..., <code><i class="var">Vn</i>:<i class="var">Tn</i></code>.
|
||||
|
||||
Note that a computation <code><i class="var">X</i></code> cannot be directly included in datatype values:
|
||||
it is necessary to encapsulate it in <code><span class="name"><a href="../../Abstraction/Generic/index.html#Name_abstraction">abstraction</a></span>(<i class="var">X</i>)</code>.
|
||||
|
||||
'Datatype T', followed by declarations of constructor funcons for 'T',
|
||||
allows specification of GADTs.
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_datatype-values">datatype-values</span></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_datatype-value">datatype-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><sup class="sup">*</sup>) : <span class="name"><a href="#Name_datatype-values">datatype-values</a></span></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_datatype-value-id">datatype-value-id</span></span>(_:<span class="name"><a href="#Name_datatype-values">datatype-values</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_datatype-value-id">datatype-value-id</a></span>(<span class="name"><a href="#Name_datatype-value">datatype-value</a></span>(<span id="Variable250_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="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>)) ~> <a href="#Variable250_I"><i class="var">I</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_datatype-value-elements">datatype-value-elements</span></span>(_:<span class="name"><a href="#Name_datatype-values">datatype-values</a></span>) : =><span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_datatype-value-elements">datatype-value-elements</a></span>(<span class="name"><a href="#Name_datatype-value">datatype-value</a></span>(_:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable321_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>)) ~> <a href="#Variable321_V*"><i class="var">V<sup class="sup">*</sup></i></a></code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Datatypes.cbs]: Datatypes.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/Composite/Datatypes/Datatypes.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
33
IBAF-cbs/Funcons-beta/Values/Composite/Graphs/Graphs.cbs
Normal file
33
IBAF-cbs/Funcons-beta/Values/Composite/Graphs/Graphs.cbs
Normal file
@@ -0,0 +1,33 @@
|
||||
### Graphs
|
||||
|
||||
[
|
||||
Type directed-graphs
|
||||
Funcon is-cyclic
|
||||
Funcon topological-sort
|
||||
]
|
||||
|
||||
Meta-variables
|
||||
GT <: ground-values
|
||||
|
||||
Type
|
||||
directed-graphs(GT) ~> maps(GT, sets(GT))
|
||||
/*
|
||||
`directed-graphs(GT)` models directed graphs with vertices of type `GT`,
|
||||
represented as maps from vertices to the set of vertices to which the
|
||||
vertex has an edge. E.g., the graph
|
||||
|
||||
(1)--->(2)
|
||||
|
||||
would be represented as `{ 1 |-> {2}, 2 |-> {} }`
|
||||
*/
|
||||
|
||||
Built-in Funcon
|
||||
is-cyclic(_:directed-graphs(GT)) : =>booleans
|
||||
|
||||
Built-in Funcon
|
||||
topological-sort(_:directed-graphs(GT)) : =>(GT)*
|
||||
/*
|
||||
`topological-sort(DG)` returns a topological ordering of the vertices
|
||||
of the graph `DG`, as a sequence of vertices, provided that `DG` is not
|
||||
cyclic.
|
||||
*/
|
||||
69
IBAF-cbs/Funcons-beta/Values/Composite/Graphs/index.md
Normal file
69
IBAF-cbs/Funcons-beta/Values/Composite/Graphs/index.md
Normal file
@@ -0,0 +1,69 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Graphs"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Graphs.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Graphs
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_directed-graphs">directed-graphs</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-cyclic">is-cyclic</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_topological-sort">topological-sort</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
|
||||
<span id="PartVariable_GT"><i class="var">GT</i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-values</a></span></code></pre></div>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_directed-graphs">directed-graphs</span></span>(<span id="Variable40_GT"><i class="var">GT</i></span>) ~> <span class="name"><a href="../Maps/index.html#Name_maps">maps</a></span>(<a href="#Variable40_GT"><i class="var">GT</i></a>, <span class="name"><a href="../Sets/index.html#Name_sets">sets</a></span>(<a href="#Variable40_GT"><i class="var">GT</i></a>))</code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_directed-graphs">directed-graphs</a></span>(<i class="var">GT</i>)</code> models directed graphs with vertices of type <code><i class="var">GT</i></code>,
|
||||
represented as maps from vertices to the set of vertices to which the
|
||||
vertex has an edge. E.g., the graph
|
||||
|
||||
(1)--->(2)
|
||||
|
||||
would be represented as <code>{ 1 |-> {2}, 2 |-> {} }</code>
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-cyclic">is-cyclic</span></span>(_:<span class="name"><a href="#Name_directed-graphs">directed-graphs</a></span>(<span id="Variable155_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_topological-sort">topological-sort</span></span>(_:<span class="name"><a href="#Name_directed-graphs">directed-graphs</a></span>(<span id="Variable186_GT"><i class="var">GT</i></span>)) : =>(<span id="Variable206_GT"><i class="var">GT</i></span>)<sup class="sup">*</sup></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_topological-sort">topological-sort</a></span>(<i class="var">DG</i>)</code> returns a topological ordering of the vertices
|
||||
of the graph <code><i class="var">DG</i></code>, as a sequence of vertices, provided that <code><i class="var">DG</i></code> is not
|
||||
cyclic.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Graphs.cbs]: Graphs.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/Composite/Graphs/Graphs.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
98
IBAF-cbs/Funcons-beta/Values/Composite/Lists/Lists.cbs
Normal file
98
IBAF-cbs/Funcons-beta/Values/Composite/Lists/Lists.cbs
Normal file
@@ -0,0 +1,98 @@
|
||||
### Lists
|
||||
|
||||
[
|
||||
Datatype lists
|
||||
Funcon list
|
||||
Funcon list-elements
|
||||
Funcon list-nil Alias nil
|
||||
Funcon list-cons Alias cons
|
||||
Funcon list-head Alias head
|
||||
Funcon list-tail Alias tail
|
||||
Funcon list-length
|
||||
Funcon list-append
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
T <: values
|
||||
|
||||
|
||||
Datatype
|
||||
lists(T) ::= list(_:(T)*)
|
||||
/*
|
||||
`lists(T)` is the type of possibly-empty finite lists `[V1,...,Vn]`
|
||||
where `V1:T`, ..., `Vn:T`.
|
||||
|
||||
N.B. `[T]` is always a single list value, and *not* interpreted as the
|
||||
type `lists(T)`.
|
||||
|
||||
The notation `[V1, ..., Vn]` for `list(V1, ..., Vn)` is built-in.
|
||||
*/
|
||||
Assert
|
||||
[V*:values*] == list(V*)
|
||||
|
||||
|
||||
Funcon
|
||||
list-elements(_:lists(T)) : =>(T)*
|
||||
Rule
|
||||
list-elements(list(V*:values*)) ~> V*
|
||||
|
||||
|
||||
Funcon
|
||||
list-nil : =>lists(_)
|
||||
~> [ ]
|
||||
Alias
|
||||
nil = list-nil
|
||||
|
||||
|
||||
Funcon
|
||||
list-cons(_:T, _:lists(T)) : =>lists(T)
|
||||
Alias
|
||||
cons = list-cons
|
||||
Rule
|
||||
list-cons(V:values, [V*:values*]) ~> [V, V*]
|
||||
|
||||
|
||||
Funcon
|
||||
list-head(_:lists(T)) : =>(T)?
|
||||
Alias
|
||||
head = list-head
|
||||
Rule
|
||||
list-head[V:values, _*:values*] ~> V
|
||||
Rule
|
||||
list-head[ ] ~> ( )
|
||||
|
||||
|
||||
Funcon
|
||||
list-tail(_:lists(T)) : =>(lists(T))?
|
||||
Alias
|
||||
tail = list-tail
|
||||
Rule
|
||||
list-tail[_:values, V*:values*] ~> [V*]
|
||||
Rule
|
||||
list-tail[ ] ~> ( )
|
||||
|
||||
|
||||
Funcon
|
||||
list-length(_:lists(T)) : =>natural-numbers
|
||||
Rule
|
||||
list-length[V*:values*] ~> length(V*)
|
||||
|
||||
|
||||
Funcon
|
||||
list-append(_:(lists(T))*) : =>lists(T)
|
||||
Rule
|
||||
list-append([V1*:values*], [V2*:values*]) ~> [V1*, V2*]
|
||||
Rule
|
||||
list-append(L1:lists(_), L2:lists(_), L3:lists(_), L*:(lists(_))*)
|
||||
~> list-append(L1, list-append(L2, L3, L*))
|
||||
Rule
|
||||
list-append( ) ~> [ ]
|
||||
Rule
|
||||
list-append(L:lists(_)) ~> L
|
||||
|
||||
|
||||
/*
|
||||
Datatypes of infinite and possibly-infinite lists can be specified as
|
||||
algebraic datatypes using abstractions.
|
||||
*/
|
||||
132
IBAF-cbs/Funcons-beta/Values/Composite/Lists/index.md
Normal file
132
IBAF-cbs/Funcons-beta/Values/Composite/Lists/index.md
Normal file
@@ -0,0 +1,132 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Lists"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Lists.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Lists
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_lists">lists</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list">list</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-elements">list-elements</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-nil">list-nil</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_nil">nil</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-cons">list-cons</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_cons">cons</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-head">list-head</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_head">head</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-tail">list-tail</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_tail">tail</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-length">list-length</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_list-append">list-append</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_lists">lists</span></span>(<span id="Variable80_T"><i class="var">T</i></span>) ::= <span id="Name_list">list</span>(_:(<span id="Variable96_T"><i class="var">T</i></span>)<sup class="sup">*</sup>)</code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_lists">lists</a></span>(<i class="var">T</i>)</code> is the type of possibly-empty finite lists <code>[<i class="var">V<sub class="sub">1</sub></i>,...,<i class="var">Vn</i>]</code>
|
||||
where <code><i class="var">V<sub class="sub">1</sub></i>:<i class="var">T</i></code>, ..., <code><i class="var">Vn</i>:<i class="var">T</i></code>.
|
||||
|
||||
N.B. <code>[<i class="var">T</i>]</code> is always a single list value, and *not* interpreted as the
|
||||
type <code><span class="name"><a href="#Name_lists">lists</a></span>(<i class="var">T</i>)</code>.
|
||||
|
||||
The notation <code>[<i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>]</code> for <code><span class="name"><a href="#Name_list">list</a></span>(<i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>)</code> is built-in.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
[<i class="var">V<sup class="sup">*</sup></i>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>] == <span class="name"><a href="#Name_list">list</a></span>(<i class="var">V<sup class="sup">*</sup></i>)</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_list-elements">list-elements</span></span>(_:<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable363_T"><i class="var">T</i></span>)) : =>(<span id="Variable383_T"><i class="var">T</i></span>)<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-elements">list-elements</a></span>(<span class="name"><a href="#Name_list">list</a></span>(<span id="Variable401_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>)) ~> <a href="#Variable401_V*"><i class="var">V<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_list-nil">list-nil</span></span> : =><span class="name"><a href="#Name_lists">lists</a></span>(_)
|
||||
~> [ ]
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_nil">nil</span></span> = <span class="name"><a href="#Name_list-nil">list-nil</a></span></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_list-cons">list-cons</span></span>(_:<span id="Variable461_T"><i class="var">T</i></span>, _:<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable473_T"><i class="var">T</i></span>)) : =><span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable495_T"><i class="var">T</i></span>)
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_cons">cons</span></span> = <span class="name"><a href="#Name_list-cons">list-cons</a></span></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-cons">list-cons</a></span>(<span id="Variable513_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, [<span id="Variable522_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>]) ~> [<a href="#Variable513_V"><i class="var">V</i></a>, <a href="#Variable522_V*"><i class="var">V<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_list-head">list-head</span></span>(_:<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable569_T"><i class="var">T</i></span>)) : =>(<span id="Variable589_T"><i class="var">T</i></span>)<sup class="sup">?</sup>
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_head">head</span></span> = <span class="name"><a href="#Name_list-head">list-head</a></span></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-head">list-head</a></span>[<span id="Variable608_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="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>] ~> <a href="#Variable608_V"><i class="var">V</i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-head">list-head</a></span>[ ] ~> ( )</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_list-tail">list-tail</span></span>(_:<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable659_T"><i class="var">T</i></span>)) : =>(<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable680_T"><i class="var">T</i></span>))<sup class="sup">?</sup>
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_tail">tail</span></span> = <span class="name"><a href="#Name_list-tail">list-tail</a></span></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-tail">list-tail</a></span>[_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable713_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>] ~> [<a href="#Variable713_V*"><i class="var">V<sup class="sup">*</sup></i></a>]
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-tail">list-tail</a></span>[ ] ~> ( )</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_list-length">list-length</span></span>(_:<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable762_T"><i class="var">T</i></span>)) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-length">list-length</a></span>[<span id="Variable789_V*"><i class="var">V<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="../Sequences/index.html#Name_length">length</a></span>(<a href="#Variable789_V*"><i class="var">V<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_list-append">list-append</span></span>(_:(<span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable826_T"><i class="var">T</i></span>))<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_lists">lists</a></span>(<span id="Variable854_T"><i class="var">T</i></span>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-append">list-append</a></span>([<span id="Variable871_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 id="Variable888_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>]) ~> [<a href="#Variable871_V1*"><i class="var">V<sub class="sub">1</sub><sup class="sup">*</sup></i></a>, <a href="#Variable888_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="#Name_list-append">list-append</a></span>(<span id="Variable935_L1"><i class="var">L<sub class="sub">1</sub></i></span>:<span class="name"><a href="#Name_lists">lists</a></span>(_), <span id="Variable953_L2"><i class="var">L<sub class="sub">2</sub></i></span>:<span class="name"><a href="#Name_lists">lists</a></span>(_), <span id="Variable971_L3"><i class="var">L<sub class="sub">3</sub></i></span>:<span class="name"><a href="#Name_lists">lists</a></span>(_), <span id="Variable989_L*"><i class="var">L<sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_lists">lists</a></span>(_))<sup class="sup">*</sup>)
|
||||
~> <span class="name"><a href="#Name_list-append">list-append</a></span>(<a href="#Variable935_L1"><i class="var">L<sub class="sub">1</sub></i></a>, <span class="name"><a href="#Name_list-append">list-append</a></span>(<a href="#Variable953_L2"><i class="var">L<sub class="sub">2</sub></i></a>, <a href="#Variable971_L3"><i class="var">L<sub class="sub">3</sub></i></a>, <a href="#Variable989_L*"><i class="var">L<sup class="sup">*</sup></i></a>))
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-append">list-append</a></span>( ) ~> [ ]
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_list-append">list-append</a></span>(<span id="Variable1080_L"><i class="var">L</i></span>:<span class="name"><a href="#Name_lists">lists</a></span>(_)) ~> <a href="#Variable1080_L"><i class="var">L</i></a></code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
Datatypes of infinite and possibly-infinite lists can be specified as
|
||||
algebraic datatypes using abstractions.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Lists.cbs]: Lists.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/Composite/Lists/Lists.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,30 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple list-elements list( ), tuple( )))
|
||||
, check-true(is-equal(tuple list-elements list(1), tuple(1)))
|
||||
, check-true(is-equal(tuple list-elements list(1,2,1,3), tuple(1,2,1,3)))
|
||||
, check-true(is-equal(list-nil, list( )))
|
||||
, check-true(is-equal(list-cons(1,list( )), list(1)))
|
||||
, check-true(is-equal(list-cons(1,list(2,3)), list(1,2,3)))
|
||||
, check-true(is-equal(list-head(list(1)), 1))
|
||||
, check-true(is-equal(list-head(list(1,2,3)), 1))
|
||||
, check-true(not is-value list-head(list( )))
|
||||
, check-true(is-equal(list-tail(list(1)), list( )))
|
||||
, check-true(is-equal(list-tail(list(1,2,3)), list(2,3)))
|
||||
, check-true(not is-value list-tail(list( )))
|
||||
, check-true(is-equal(list-append( ), list( )))
|
||||
, check-true(is-equal(list-append(list( )), list( )))
|
||||
, check-true(is-equal(list-append(list(1,2,3,4)), list(1,2,3,4)))
|
||||
, check-true(is-equal(list-append(list(1,2), list(3,4)), list(1,2,3,4)))
|
||||
, check-true(is-equal(list-append(list(1), list(2,3,4)), list(1,2,3,4)))
|
||||
, check-true(is-equal(list-append(list( ), list(1,2,3,4)), list(1,2,3,4)))
|
||||
, check-true(is-equal(list-append(list(1,2,3,4),list( )), list(1,2,3,4)))
|
||||
, check-true(is-equal(list-append(list(1),list(2),list(3,4)), list(1,2,3,4)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
111
IBAF-cbs/Funcons-beta/Values/Composite/Maps/Maps.cbs
Normal file
111
IBAF-cbs/Funcons-beta/Values/Composite/Maps/Maps.cbs
Normal file
@@ -0,0 +1,111 @@
|
||||
### Maps
|
||||
|
||||
[
|
||||
Type maps
|
||||
Funcon map
|
||||
Funcon map-elements
|
||||
Funcon map-lookup Alias lookup
|
||||
Funcon map-domain Alias dom
|
||||
Funcon map-override
|
||||
Funcon map-unite
|
||||
Funcon map-delete
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
GT <: ground-values
|
||||
T? <: values?
|
||||
|
||||
|
||||
Built-in Type
|
||||
maps(GT, T?)
|
||||
/*
|
||||
`maps(GT, T?)` is the type of possibly-empty finite maps from values of
|
||||
type `GT` to optional values of type `T?`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map(_:(tuples(GT, T?))*) : =>(maps(GT, T?))?
|
||||
/*
|
||||
`map(tuple(K1, V1?), ..., tuple(Kn, Vn?))` constructs a map from
|
||||
`K1` to `V1?`, ..., `Kn` to `Vn?`, provided that `K1`, ..., `Kn`
|
||||
are distinct, otherwise the result is `( )`.
|
||||
|
||||
Note that `map(...)` is not a constructor operation.
|
||||
|
||||
The built-in notation `{K1|->V1?, ..., Kn|->Vn?}` is equivalent to
|
||||
`map(tuple(K1, V1?), ..., tuple(Kn, Vn?))`. Note however that in general,
|
||||
maps cannot be identified with sets of tuples, since the values `Vi?` are
|
||||
not restricted to `ground-values`.
|
||||
|
||||
When ``T? <: types``, ``maps(GT, T?) <: types``. The type `MT:maps(GT, T?)`
|
||||
represents the set of value-maps `MV:maps(GT, values?)` such that
|
||||
`dom(MV)` is a subset of `dom(MT)` and for all `K` in `dom(MV)`,
|
||||
``map-lookup(MV, K) : map-lookup(MT, K)``.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-elements(_:maps(GT, T?)) : =>(tuples(GT, T?))*
|
||||
/*
|
||||
The sequence of tuples `(tuple(K1, V1?), ..., tuple(Kn, Vn?))` given by
|
||||
`map-elements(M)` contains each mapped value `Ki` just once. The order of
|
||||
the elements is unspecified, and may vary between maps.
|
||||
*/
|
||||
Assert
|
||||
map(map-elements(M)) == M
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-lookup(_:maps(GT, T?), K:GT) : =>(T?)?
|
||||
Alias
|
||||
lookup = map-lookup
|
||||
/*
|
||||
`map-lookup(M,K)` gives the optional value to which `K` is mapped by `M`,
|
||||
if any, and otherwise `( )`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-domain(_:maps(GT, T?)) : =>sets(GT)
|
||||
Alias
|
||||
dom = map-domain
|
||||
/*
|
||||
`map-domain(M)` gives the set of values mapped by `M`.
|
||||
|
||||
`map-lookup(M, K)` is always `( )` when `K` is not in `map-domain(M)`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-override(_:(maps(GT, T?))*) : =>maps(GT,T?)
|
||||
/*
|
||||
`map-override(...)` takes a sequence of maps. It returns the map whose
|
||||
domain is the union of their domains, and which maps each of those values
|
||||
to the same optional value as the first map in the sequence in whose domain
|
||||
it occurs
|
||||
.
|
||||
When the domains of the `M*` are disjoint, `map-override(M*)` is equivalent
|
||||
to `map-unite(M*)`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-unite(_:(maps(GT, T?))*) : =>(maps(GT, T?))?
|
||||
/*
|
||||
`map-unite(...)` takes a sequence of maps. It returns the map whose
|
||||
domain is the union of their domains, and which maps each of those values
|
||||
to the same optional value as the map in the sequence in whose domain it occurs,
|
||||
provided that those domains are disjoint - otherwise the result is `( )`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
map-delete(_:maps(GT, T?), _:sets(GT)) : =>maps(GT, T?)
|
||||
/*
|
||||
`map-delete(M, S)` takes a map `M` and a set of values `S`, and returns the
|
||||
map obtained from `M` by removing `S` from its domain.
|
||||
*/
|
||||
Assert
|
||||
map-domain(map-delete(M, S)) == set-difference(map-domain(M), S)
|
||||
147
IBAF-cbs/Funcons-beta/Values/Composite/Maps/index.md
Normal file
147
IBAF-cbs/Funcons-beta/Values/Composite/Maps/index.md
Normal file
@@ -0,0 +1,147 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Maps"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Maps.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Maps
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_maps">maps</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map">map</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-elements">map-elements</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-lookup">map-lookup</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_lookup">lookup</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-domain">map-domain</a></span> <i class="keyword">Alias</i> <span class="name"><a href="#Name_dom">dom</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-override">map-override</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-unite">map-unite</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_map-delete">map-delete</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
|
||||
<span id="PartVariable_GT"><i class="var">GT</i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-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">Built-in</i> <i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_maps">maps</span></span>(<span id="Variable82_GT"><i class="var">GT</i></span>, <span id="Variable89_T?"><i class="var">T<sup class="sup">?</sup></i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_maps">maps</a></span>(<i class="var">GT</i>, <i class="var">T<sup class="sup">?</sup></i>)</code> is the type of possibly-empty finite maps from values of
|
||||
type <code><i class="var">GT</i></code> to optional values of type <code><i class="var">T<sup class="sup">?</sup></i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map">map</span></span>(_:(<span class="name"><a href="../Tuples/index.html#Name_tuples">tuples</a></span>(<span id="Variable171_GT"><i class="var">GT</i></span>, <span id="Variable177_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">*</sup>) : =>(<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable206_GT"><i class="var">GT</i></span>, <span id="Variable212_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">?</sup></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_map">map</a></span>(<span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">K<sub class="sub">1</sub></i>, <i class="var">V<sub class="sub">1</sub><sup class="sup">?</sup></i>), ..., <span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">Kn</i>, <i class="var">Vn<sup class="sup">?</sup></i>))</code> constructs a map from
|
||||
<code><i class="var">K<sub class="sub">1</sub></i></code> to <code><i class="var">V<sub class="sub">1</sub><sup class="sup">?</sup></i></code>, ..., <code><i class="var">Kn</i></code> to <code><i class="var">Vn<sup class="sup">?</sup></i></code>, provided that <code><i class="var">K<sub class="sub">1</sub></i></code>, ..., <code><i class="var">Kn</i></code>
|
||||
are distinct, otherwise the result is <code>( )</code>.
|
||||
|
||||
Note that <code><span class="name"><a href="#Name_map">map</a></span>(...)</code> is not a constructor operation.
|
||||
|
||||
The built-in notation <code>{<i class="var">K<sub class="sub">1</sub></i>|-><i class="var">V<sub class="sub">1</sub><sup class="sup">?</sup></i>, ..., <i class="var">Kn</i>|-><i class="var">Vn<sup class="sup">?</sup></i>}</code> is equivalent to
|
||||
<code><span class="name"><a href="#Name_map">map</a></span>(<span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">K<sub class="sub">1</sub></i>, <i class="var">V<sub class="sub">1</sub><sup class="sup">?</sup></i>), ..., <span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">Kn</i>, <i class="var">Vn<sup class="sup">?</sup></i>))</code>. Note however that in general,
|
||||
maps cannot be identified with sets of tuples, since the values <code><i class="var">Vi<sup class="sup">?</sup></i></code> are
|
||||
not restricted to <code><span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-values</a></span></code>.
|
||||
|
||||
When <code><i class="var">T<sup class="sup">?</sup></i> <: <span class="name"><a href="../../Value-Types/index.html#Name_types">types</a></span></code>, <code><span class="name"><a href="#Name_maps">maps</a></span>(<i class="var">GT</i>, <i class="var">T<sup class="sup">?</sup></i>) <: <span class="name"><a href="../../Value-Types/index.html#Name_types">types</a></span></code>. The type <code><i class="var">MT</i>:<span class="name"><a href="#Name_maps">maps</a></span>(<i class="var">GT</i>, <i class="var">T<sup class="sup">?</sup></i>)</code>
|
||||
represents the set of value-maps <code><i class="var">MV</i>:<span class="name"><a href="#Name_maps">maps</a></span>(<i class="var">GT</i>, <span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">?</sup>)</code> such that
|
||||
<code><span class="name"><a href="#Name_dom">dom</a></span>(<i class="var">MV</i>)</code> is a subset of <code><span class="name"><a href="#Name_dom">dom</a></span>(<i class="var">MT</i>)</code> and for all <code><i class="var">K</i></code> in <code><span class="name"><a href="#Name_dom">dom</a></span>(<i class="var">MV</i>)</code>,
|
||||
<code><span class="name"><a href="#Name_map-lookup">map-lookup</a></span>(<i class="var">MV</i>, <i class="var">K</i>) : <span class="name"><a href="#Name_map-lookup">map-lookup</a></span>(<i class="var">MT</i>, <i class="var">K</i>)</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-elements">map-elements</span></span>(_:<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable766_GT"><i class="var">GT</i></span>, <span id="Variable772_T?"><i class="var">T<sup class="sup">?</sup></i></span>)) : =>(<span class="name"><a href="../Tuples/index.html#Name_tuples">tuples</a></span>(<span id="Variable794_GT"><i class="var">GT</i></span>, <span id="Variable800_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">*</sup></code></pre></div>
|
||||
|
||||
The sequence of tuples <code>(<span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">K<sub class="sub">1</sub></i>, <i class="var">V<sub class="sub">1</sub><sup class="sup">?</sup></i>), ..., <span class="name"><a href="../Tuples/index.html#Name_tuple">tuple</a></span>(<i class="var">Kn</i>, <i class="var">Vn<sup class="sup">?</sup></i>))</code> given by
|
||||
<code><span class="name"><a href="#Name_map-elements">map-elements</a></span>(<i class="var">M</i>)</code> contains each mapped value <code><i class="var">Ki</i></code> just once. The order of
|
||||
the elements is unspecified, and may vary between maps.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_map">map</a></span>(<span class="name"><a href="#Name_map-elements">map-elements</a></span>(<i class="var">M</i>)) == <i class="var">M</i></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-lookup">map-lookup</span></span>(_:<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable951_GT"><i class="var">GT</i></span>, <span id="Variable957_T?"><i class="var">T<sup class="sup">?</sup></i></span>), <span id="Variable972_K"><i class="var">K</i></span>:<span id="Variable976_GT"><i class="var">GT</i></span>) : =>(<span id="Variable992_T?"><i class="var">T<sup class="sup">?</sup></i></span>)<sup class="sup">?</sup>
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_lookup">lookup</span></span> = <span class="name"><a href="#Name_map-lookup">map-lookup</a></span></code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_map-lookup">map-lookup</a></span>(<i class="var">M</i>,<i class="var">K</i>)</code> gives the optional value to which <code><i class="var">K</i></code> is mapped by <code><i class="var">M</i></code>,
|
||||
if any, and otherwise <code>( )</code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-domain">map-domain</span></span>(_:<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1086_GT"><i class="var">GT</i></span>, <span id="Variable1092_T?"><i class="var">T<sup class="sup">?</sup></i></span>)) : =><span class="name"><a href="../Sets/index.html#Name_sets">sets</a></span>(<span id="Variable1114_GT"><i class="var">GT</i></span>)
|
||||
<i class="keyword">Alias</i>
|
||||
<span class="name"><span id="Name_dom">dom</span></span> = <span class="name"><a href="#Name_map-domain">map-domain</a></span></code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_map-domain">map-domain</a></span>(<i class="var">M</i>)</code> gives the set of values mapped by <code><i class="var">M</i></code>.
|
||||
|
||||
<code><span class="name"><a href="#Name_map-lookup">map-lookup</a></span>(<i class="var">M</i>, <i class="var">K</i>)</code> is always <code>( )</code> when <code><i class="var">K</i></code> is not in <code><span class="name"><a href="#Name_map-domain">map-domain</a></span>(<i class="var">M</i>)</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-override">map-override</span></span>(_:(<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1247_GT"><i class="var">GT</i></span>, <span id="Variable1253_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1282_GT"><i class="var">GT</i></span>,<span id="Variable1288_T?"><i class="var">T<sup class="sup">?</sup></i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_map-override">map-override</a></span>(...)</code> takes a sequence of maps. It returns the map whose
|
||||
domain is the union of their domains, and which maps each of those values
|
||||
to the same optional value as the first map in the sequence in whose domain
|
||||
it occurs
|
||||
.
|
||||
When the domains of the <code><i class="var">M<sup class="sup">*</sup></i></code> are disjoint, <code><span class="name"><a href="#Name_map-override">map-override</a></span>(<i class="var">M<sup class="sup">*</sup></i>)</code> is equivalent
|
||||
to <code><span class="name"><a href="#Name_map-unite">map-unite</a></span>(<i class="var">M<sup class="sup">*</sup></i>)</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-unite">map-unite</span></span>(_:(<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1389_GT"><i class="var">GT</i></span>, <span id="Variable1395_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">*</sup>) : =>(<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1424_GT"><i class="var">GT</i></span>, <span id="Variable1430_T?"><i class="var">T<sup class="sup">?</sup></i></span>))<sup class="sup">?</sup></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_map-unite">map-unite</a></span>(...)</code> takes a sequence of maps. It returns the map whose
|
||||
domain is the union of their domains, and which maps each of those values
|
||||
to the same optional value as the map in the sequence in whose domain it occurs,
|
||||
provided that those domains are disjoint - otherwise the result is <code>( )</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_map-delete">map-delete</span></span>(_:<span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1494_GT"><i class="var">GT</i></span>, <span id="Variable1500_T?"><i class="var">T<sup class="sup">?</sup></i></span>), _:<span class="name"><a href="../Sets/index.html#Name_sets">sets</a></span>(<span id="Variable1519_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="#Name_maps">maps</a></span>(<span id="Variable1541_GT"><i class="var">GT</i></span>, <span id="Variable1547_T?"><i class="var">T<sup class="sup">?</sup></i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_map-delete">map-delete</a></span>(<i class="var">M</i>, <i class="var">S</i>)</code> takes a map <code><i class="var">M</i></code> and a set of values <code><i class="var">S</i></code>, and returns the
|
||||
map obtained from <code><i class="var">M</i></code> by removing <code><i class="var">S</i></code> from its domain.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_map-domain">map-domain</a></span>(<span class="name"><a href="#Name_map-delete">map-delete</a></span>(<i class="var">M</i>, <i class="var">S</i>)) == <span class="name"><a href="../Sets/index.html#Name_set-difference">set-difference</a></span>(<span class="name"><a href="#Name_map-domain">map-domain</a></span>(<i class="var">M</i>), <i class="var">S</i>)</code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Maps.cbs]: Maps.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/Composite/Maps/Maps.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,29 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-delete({1 |-> 2},{}),
|
||||
print map-delete({1 |-> 2, 3 |-> 4},{}),
|
||||
print map-delete(map(),{1}),
|
||||
print map-delete({1 |-> 2},{1}),
|
||||
print map-delete({1 |-> 2, 3 |-> 4},{1}),
|
||||
print map-delete({1 |-> 2, 3 |-> 4},{3}),
|
||||
print map-delete({1 |-> 2, 3 |-> 4},{1,3}),
|
||||
print "OK"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{1 |-> 2},
|
||||
{1 |-> 2, 3 |-> 4},
|
||||
map(),
|
||||
map(),
|
||||
{3 |-> 4},
|
||||
{1 |-> 2},
|
||||
map(),
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-domain map(),
|
||||
print map-domain{1|->2},
|
||||
print map-domain{1|->2,3|->4},
|
||||
print map-domain{1|->2,3|->( )}
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null;
|
||||
standard-out: [{}, {1}, {1,3}, {1,3}];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-elements map( ),
|
||||
print map-elements {1|->2},
|
||||
print map-elements {3|->4,5|->6}
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [tuple(1, 2), tuple(3, 4), tuple(5, 6) ];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-lookup({1|->2}, 1),
|
||||
print map-lookup({1|->2,3|->4}, 1),
|
||||
print map-lookup({1|->2,3|->4}, 3),
|
||||
else(
|
||||
effect checked map-lookup(map(), 1),
|
||||
effect checked map-lookup({1|->2}, 2),
|
||||
effect checked map-lookup({1|->2,3|->4}, 2),
|
||||
effect checked map-lookup({1|->2,3|->4}, 5),
|
||||
print "OK"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [2, 2, 4, "OK"];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-override({1 |-> 2},map()),
|
||||
print map-override(map(),{1 |-> 2}),
|
||||
print map-override({1 |-> 2},{1 |-> 2}),
|
||||
print map-override({1 |-> 2},{3 |-> 4}),
|
||||
print map-override({1 |-> 2},{1 |-> 4}),
|
||||
print map-override({1 |-> 2},{1 |-> 4},{1 |-> 2}),
|
||||
print map-override({1 |-> 2}),
|
||||
print map-override(map()),
|
||||
print map-override()
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{1 |-> 2},
|
||||
{1 |-> 2},
|
||||
{1 |-> 2},
|
||||
{1 |-> 2, 3 |-> 4},
|
||||
{1 |-> 2},
|
||||
{1 |-> 2},
|
||||
{1 |-> 2},
|
||||
map(),
|
||||
map()
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map-unite({1 |-> 2},map()),
|
||||
print map-unite(map(),{1 |-> 2}),
|
||||
print map-unite({1 |-> 2},{3 |-> 4}),
|
||||
print map-unite({1 |-> 2}),
|
||||
print map-unite(map()),
|
||||
print map-unite(),
|
||||
else(
|
||||
effect checked map-unite({1 |-> 2},{1 |-> 4}),
|
||||
effect checked map-unite({1 |-> 2, 3 |-> 4},{5 |-> 6, 1 |-> 7}),
|
||||
print "OK"
|
||||
)
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{1 |-> 2},
|
||||
{1 |-> 2},
|
||||
{1 |-> 2, 3 |-> 4},
|
||||
{1 |-> 2},
|
||||
map(),
|
||||
map(),
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
23
IBAF-cbs/Funcons-beta/Values/Composite/Maps/tests/map.config
Normal file
23
IBAF-cbs/Funcons-beta/Values/Composite/Maps/tests/map.config
Normal file
@@ -0,0 +1,23 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print map(),
|
||||
print {1 |-> 2},
|
||||
print {1 |-> 2, 3 |-> 4},
|
||||
print {1 |-> 2, 3 |-> ()},
|
||||
print cast({1 |-> 2}, maps(integers,integers))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
map(),
|
||||
{1 |-> 2},
|
||||
{1 |-> 2, 3 |-> 4},
|
||||
{1 |-> 2, 3 |-> ()},
|
||||
{1 |-> 2}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
### Multisets (bags)
|
||||
|
||||
[
|
||||
Type multisets
|
||||
Funcon multiset
|
||||
Funcon multiset-elements
|
||||
Funcon multiset-occurrences
|
||||
Funcon multiset-insert
|
||||
Funcon multiset-delete
|
||||
Funcon is-submultiset
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
GT <: ground-values
|
||||
|
||||
|
||||
Built-in Type
|
||||
multisets(GT)
|
||||
/*
|
||||
`multisets(GT)` is the type of possibly-empty finite multisets of elements
|
||||
of `GT`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
multiset(_:(GT)*) : =>multisets(GT)
|
||||
/*
|
||||
Note that `multiset(...)` is not a constructor operation. The order of
|
||||
argument values is ignored, but duplicates are significant, e.g.,
|
||||
`multiset(1, 2, 2)` is equivalent to `multiset(2, 1, 2)`, but not to
|
||||
`multiset(1, 2)` or `multiset(2, 1)`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
multiset-elements(_:multisets(GT)) : =>(GT)*
|
||||
/*
|
||||
For each multiset `MS`, the sequence of values `V*` returned by
|
||||
`multiset-elements(MS)` contains each element of `MS` the same number of times
|
||||
as `MS` does.
|
||||
The order of the values in `V*` is unspecified, and may vary between multisets.
|
||||
*/
|
||||
Assert
|
||||
multiset(multiset-elements(S)) == S
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
multiset-occurrences(_:GT, _:multisets(GT)) : =>natural-numbers
|
||||
/*
|
||||
`multiset-occurrences(GV, MS)` returns the number of occurrences of `GV`
|
||||
in `MS`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
multiset-insert(_:GT, _:natural-numbers, _:multisets(GT)) : =>multisets(GT)
|
||||
/*
|
||||
`multiset-insert(GV, N, MS)` returns the multiset that differs from `MS`
|
||||
by containing `N` more copies of `GV`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
multiset-delete(_:multisets(GT), _:GT, _:natural-numbers) : =>multisets(GT)
|
||||
/*
|
||||
`multiset-delete(MS, GV, N)` removes `N` copies of `V` from the multiset `MS`,
|
||||
or all copies of `GV` if there are fewer than `N` in `MS`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
is-submultiset(_:multisets(GT), _:multisets(GT)) : =>booleans
|
||||
/*
|
||||
`is-submultiset(MS1, MS2)` tests whether every element of `MS1` has equal or
|
||||
fewer occurrences in `MS1` than in `MS2`.
|
||||
*/
|
||||
114
IBAF-cbs/Funcons-beta/Values/Composite/Multisets/index.md
Normal file
114
IBAF-cbs/Funcons-beta/Values/Composite/Multisets/index.md
Normal file
@@ -0,0 +1,114 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Multisets"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Multisets.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Multisets (bags)
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_multisets">multisets</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_multiset">multiset</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_multiset-elements">multiset-elements</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_multiset-occurrences">multiset-occurrences</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_multiset-insert">multiset-insert</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_multiset-delete">multiset-delete</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-submultiset">is-submultiset</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
|
||||
<span id="PartVariable_GT"><i class="var">GT</i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-values</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_multisets">multisets</span></span>(<span id="Variable56_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_multisets">multisets</a></span>(<i class="var">GT</i>)</code> is the type of possibly-empty finite multisets of elements
|
||||
of <code><i class="var">GT</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_multiset">multiset</span></span>(_:(<span id="Variable115_GT"><i class="var">GT</i></span>)<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable137_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
Note that <code><span class="name"><a href="#Name_multiset">multiset</a></span>(...)</code> is not a constructor operation. The order of
|
||||
argument values is ignored, but duplicates are significant, e.g.,
|
||||
<code><span class="name"><a href="#Name_multiset">multiset</a></span>(1, 2, 2)</code> is equivalent to <code><span class="name"><a href="#Name_multiset">multiset</a></span>(2, 1, 2)</code>, but not to
|
||||
<code><span class="name"><a href="#Name_multiset">multiset</a></span>(1, 2)</code> or <code><span class="name"><a href="#Name_multiset">multiset</a></span>(2, 1)</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_multiset-elements">multiset-elements</span></span>(_:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable267_GT"><i class="var">GT</i></span>)) : =>(<span id="Variable287_GT"><i class="var">GT</i></span>)<sup class="sup">*</sup></code></pre></div>
|
||||
|
||||
For each multiset <code><i class="var">MS</i></code>, the sequence of values <code><i class="var">V<sup class="sup">*</sup></i></code> returned by
|
||||
<code><span class="name"><a href="#Name_multiset-elements">multiset-elements</a></span>(<i class="var">MS</i>)</code> contains each element of <code><i class="var">MS</i></code> the same number of times
|
||||
as <code><i class="var">MS</i></code> does.
|
||||
The order of the values in <code><i class="var">V<sup class="sup">*</sup></i></code> is unspecified, and may vary between multisets.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_multiset">multiset</a></span>(<span class="name"><a href="#Name_multiset-elements">multiset-elements</a></span>(<i class="var">S</i>)) == <i class="var">S</i></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_multiset-occurrences">multiset-occurrences</span></span>(_:<span id="Variable426_GT"><i class="var">GT</i></span>, _:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable438_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_multiset-occurrences">multiset-occurrences</a></span>(<i class="var">GV</i>, <i class="var">MS</i>)</code> returns the number of occurrences of <code><i class="var">GV</i></code>
|
||||
in <code><i class="var">MS</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_multiset-insert">multiset-insert</span></span>(_:<span id="Variable527_GT"><i class="var">GT</i></span>, _:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>, _:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable547_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable570_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_multiset-insert">multiset-insert</a></span>(<i class="var">GV</i>, <i class="var">N</i>, <i class="var">MS</i>)</code> returns the multiset that differs from <code><i class="var">MS</i></code>
|
||||
by containing <code><i class="var">N</i></code> more copies of <code><i class="var">GV</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_multiset-delete">multiset-delete</span></span>(_:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable667_GT"><i class="var">GT</i></span>), _:<span id="Variable684_GT"><i class="var">GT</i></span>, _:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>) : =><span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable709_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_multiset-delete">multiset-delete</a></span>(<i class="var">MS</i>, <i class="var">GV</i>, <i class="var">N</i>)</code> removes <code><i class="var">N</i></code> copies of <code><i class="var">V</i></code> from the multiset <code><i class="var">MS</i></code>,
|
||||
or all copies of <code><i class="var">GV</i></code> if there are fewer than <code><i class="var">N</i></code> in <code><i class="var">MS</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-submultiset">is-submultiset</span></span>(_:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable845_GT"><i class="var">GT</i></span>), _:<span class="name"><a href="#Name_multisets">multisets</a></span>(<span id="Variable863_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_is-submultiset">is-submultiset</a></span>(<i class="var">MS<sub class="sub">1</sub></i>, <i class="var">MS<sub class="sub">2</sub></i>)</code> tests whether every element of <code><i class="var">MS<sub class="sub">1</sub></i></code> has equal or
|
||||
fewer occurrences in <code><i class="var">MS<sub class="sub">1</sub></i></code> than in <code><i class="var">MS<sub class="sub">2</sub></i></code>.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Multisets.cbs]: Multisets.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/Composite/Multisets/Multisets.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
81
IBAF-cbs/Funcons-beta/Values/Composite/Objects/Objects.cbs
Normal file
81
IBAF-cbs/Funcons-beta/Values/Composite/Objects/Objects.cbs
Normal file
@@ -0,0 +1,81 @@
|
||||
### Objects
|
||||
|
||||
[
|
||||
Datatype objects
|
||||
Funcon object
|
||||
Funcon object-identity
|
||||
Funcon object-class-name
|
||||
Funcon object-feature-map
|
||||
Funcon object-subobject-sequence
|
||||
Funcon object-tree
|
||||
Funcon object-single-inheritance-feature-map
|
||||
]
|
||||
|
||||
|
||||
Datatype
|
||||
objects ::= object(_:atoms, _:identifiers, _:environments, _:objects*)
|
||||
/*
|
||||
`object( A, C, Env, O*)` is an object:
|
||||
* distinguished by an atom `A`,
|
||||
* of a class named `C`,
|
||||
* with an environment `Env` with the features of the object, and
|
||||
* a sequence `O*` of subobjects of the direct superclasses of `C`.
|
||||
`object( A, C, Env)` is an object of a base class.
|
||||
`object( A, C, Env, O')` is an object of a class with a single superclass.
|
||||
With multiple inheritance, subobjects due to repeated inheritance of the
|
||||
same class may be shared.
|
||||
|
||||
Implementations of objects generally represent an object as a vector of
|
||||
fields, and use pointers and offsets for efficient access to individual
|
||||
fields. The representation of objects used in this specification is
|
||||
independent of such implementation concerns.
|
||||
*/
|
||||
|
||||
Funcon
|
||||
object-identity(_:objects) : =>atoms
|
||||
Rule
|
||||
object-identity
|
||||
object(A:atoms, _:identifiers, _:environments, _*:objects*) ~> A
|
||||
|
||||
Funcon
|
||||
object-class-name(_:objects) : =>identifiers
|
||||
Rule
|
||||
object-class-name
|
||||
object(_:atoms, C:identifiers, _:environments, _*:objects*) ~> C
|
||||
|
||||
Funcon
|
||||
object-feature-map(_:objects) : =>environments
|
||||
Rule
|
||||
object-feature-map
|
||||
object(_:atoms, _:identifiers, Env:environments, _*:objects*) ~> Env
|
||||
|
||||
Funcon
|
||||
object-subobject-sequence(_:objects) : =>objects*
|
||||
Rule
|
||||
object-subobject-sequence
|
||||
object(_:atoms, _:identifiers, _:environments, O*:objects*) ~> O*
|
||||
|
||||
|
||||
Funcon
|
||||
object-tree(_:objects) : =>trees(objects)
|
||||
/*
|
||||
`object-tree O` forms a tree where the branches are the object trees for
|
||||
the direct subobjects of `O`.
|
||||
*/
|
||||
Rule
|
||||
object-tree(O:objects)
|
||||
~> tree(O,
|
||||
interleave-map (
|
||||
object-tree given,
|
||||
object-subobject-sequence O))
|
||||
|
||||
|
||||
Funcon
|
||||
object-single-inheritance-feature-map(O:objects) : =>environments
|
||||
~> map-override left-to-right-map(
|
||||
object-feature-map given,
|
||||
single-branching-sequence object-tree O)
|
||||
/*
|
||||
For multiple inheritance, different resolution orders can be specified
|
||||
by using difference linearisations of the object tree.
|
||||
*/
|
||||
119
IBAF-cbs/Funcons-beta/Values/Composite/Objects/index.md
Normal file
119
IBAF-cbs/Funcons-beta/Values/Composite/Objects/index.md
Normal file
@@ -0,0 +1,119 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Objects"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Objects.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Objects
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_objects">objects</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object">object</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-identity">object-identity</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-class-name">object-class-name</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-feature-map">object-feature-map</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-subobject-sequence">object-subobject-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-tree">object-tree</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_object-single-inheritance-feature-map">object-single-inheritance-feature-map</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
|
||||
<span class="name"><span id="Name_objects">objects</span></span> ::= <span id="Name_object">object</span>(_:<span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, _:<span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>)</code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_object">object</a></span>( <i class="var">A</i>, <i class="var">C</i>, <i class="var">Env</i>, <i class="var">O<sup class="sup">*</sup></i>)</code> is an object:
|
||||
* distinguished by an atom <code><i class="var">A</i></code>,
|
||||
* of a class named <code><i class="var">C</i></code>,
|
||||
* with an environment <code><i class="var">Env</i></code> with the features of the object, and
|
||||
* a sequence <code><i class="var">O<sup class="sup">*</sup></i></code> of subobjects of the direct superclasses of <code><i class="var">C</i></code>.
|
||||
<code><span class="name"><a href="#Name_object">object</a></span>( <i class="var">A</i>, <i class="var">C</i>, <i class="var">Env</i>)</code> is an object of a base class.
|
||||
<code><span class="name"><a href="#Name_object">object</a></span>( <i class="var">A</i>, <i class="var">C</i>, <i class="var">Env</i>, <i class="var">O′</i>)</code> is an object of a class with a single superclass.
|
||||
With multiple inheritance, subobjects due to repeated inheritance of the
|
||||
same class may be shared.
|
||||
|
||||
Implementations of objects generally represent an object as a vector of
|
||||
fields, and use pointers and offsets for efficient access to individual
|
||||
fields. The representation of objects used in this specification is
|
||||
independent of such implementation concerns.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_object-identity">object-identity</span></span>(_:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_object-identity">object-identity</a></span>
|
||||
<span class="name"><a href="#Name_object">object</a></span>(<span id="Variable326_A"><i class="var">A</i></span>:<span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, _*:<span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>) ~> <a href="#Variable326_A"><i class="var">A</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_object-class-name">object-class-name</span></span>(_:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_object-class-name">object-class-name</a></span>
|
||||
<span class="name"><a href="#Name_object">object</a></span>(_:<span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>, <span id="Variable405_C"><i class="var">C</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, _*:<span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>) ~> <a href="#Variable405_C"><i class="var">C</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_object-feature-map">object-feature-map</span></span>(_:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_object-feature-map">object-feature-map</a></span>
|
||||
<span class="name"><a href="#Name_object">object</a></span>(_:<span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, <span id="Variable484_Env"><i class="var">Env</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, _*:<span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>) ~> <a href="#Variable484_Env"><i class="var">Env</i></a></code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_object-subobject-sequence">object-subobject-sequence</span></span>(_:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_object-subobject-sequence">object-subobject-sequence</a></span>
|
||||
<span class="name"><a href="#Name_object">object</a></span>(_:<span class="name"><a href="../../../Computations/Normal/Generating/index.html#Name_atoms">atoms</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>, _:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>, <span id="Variable566_O*"><i class="var">O<sup class="sup">*</sup></i></span>:<span class="name"><a href="#Name_objects">objects</a></span><sup class="sup">*</sup>) ~> <a href="#Variable566_O*"><i class="var">O<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_object-tree">object-tree</span></span>(_:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="../Trees/index.html#Name_trees">trees</a></span>(<span class="name"><a href="#Name_objects">objects</a></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_object-tree">object-tree</a></span> <i class="var">O</i></code> forms a tree where the branches are the object trees for
|
||||
the direct subobjects of <code><i class="var">O</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_object-tree">object-tree</a></span>(<span id="Variable657_O"><i class="var">O</i></span>:<span class="name"><a href="#Name_objects">objects</a></span>)
|
||||
~> <span class="name"><a href="../Trees/index.html#Name_tree">tree</a></span>(<a href="#Variable657_O"><i class="var">O</i></a>,
|
||||
<span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_interleave-map">interleave-map</a></span> (
|
||||
<span class="name"><a href="#Name_object-tree">object-tree</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>,
|
||||
<span class="name"><a href="#Name_object-subobject-sequence">object-subobject-sequence</a></span> <a href="#Variable657_O"><i class="var">O</i></a>))</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_object-single-inheritance-feature-map">object-single-inheritance-feature-map</span></span>(<span id="Variable707_O"><i class="var">O</i></span>:<span class="name"><a href="#Name_objects">objects</a></span>) : =><span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_environments">environments</a></span>
|
||||
~> <span class="name"><a href="../Maps/index.html#Name_map-override">map-override</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_left-to-right-map">left-to-right-map</a></span>(
|
||||
<span class="name"><a href="#Name_object-feature-map">object-feature-map</a></span> <span class="name"><a href="../../../Computations/Normal/Giving/index.html#Name_given">given</a></span>,
|
||||
<span class="name"><a href="../Trees/index.html#Name_single-branching-sequence">single-branching-sequence</a></span> <span class="name"><a href="#Name_object-tree">object-tree</a></span> <a href="#Variable707_O"><i class="var">O</i></a>)</code></pre></div>
|
||||
|
||||
|
||||
For multiple inheritance, different resolution orders can be specified
|
||||
by using difference linearisations of the object tree.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Objects.cbs]: Objects.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/Composite/Objects/Objects.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,17 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print object-feature-map object(fresh-atom,"A",map()),
|
||||
print object-feature-map object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"C",map()))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
map(), map()
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print object-identity object(fresh-atom,"A",map()),
|
||||
print object-identity object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"C",map()))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
atom("@1"), atom("@2")
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print object-single-inheritance-feature-map
|
||||
object(fresh-atom,"A",{"a"|->"A"}),
|
||||
print object-single-inheritance-feature-map
|
||||
object(fresh-atom,"B",{"a"|->"B"},
|
||||
object(fresh-atom,"C",{"a"|->"C"})),
|
||||
else(
|
||||
is-value object-single-inheritance-feature-map
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"F",map())),
|
||||
object(fresh-atom,"G",map())),
|
||||
print "OK")
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{"a"|->"A"},
|
||||
{"a"|->"B"},
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print [object-subobject-sequence
|
||||
object(fresh-atom,"A",map())],
|
||||
print [object-subobject-sequence
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"C",map()))],
|
||||
print [object-subobject-sequence
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"F",map())),
|
||||
object(fresh-atom,"G",map()))]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[],
|
||||
[object(atom("@3"),"C",map-empty)],
|
||||
[object(atom("@5"),"E",map-empty,object(atom("@6"),"F",map-empty)),
|
||||
object(atom("@7"),"G",map-empty)]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print object-tree
|
||||
object(fresh-atom,"A",map()),
|
||||
print object-tree
|
||||
object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"C",map())),
|
||||
print object-tree
|
||||
object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"F",map())),
|
||||
object(fresh-atom,"G",map()))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
tree (object(atom("@1"),"A",map-empty)),
|
||||
tree (object(atom("@2"),"B",map-empty,object(atom("@3"),"C",map-empty)),
|
||||
tree (object(atom("@3"),"C",map-empty))),
|
||||
tree (object(atom("@4"),"D",map-empty,
|
||||
object(atom("@5"),"E",map-empty,object(atom("@6"),"F",map-empty)),
|
||||
object(atom("@7"),"G",map-empty)),
|
||||
tree (object(atom("@5"),"E",map-empty,object(atom("@6"),"F",map-empty)),
|
||||
tree (object(atom("@6"),"F",map-empty))),
|
||||
tree (object(atom("@7"),"G",map-empty)))
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving initialise-generating finalise-failing
|
||||
sequential (
|
||||
print object(fresh-atom,"A",map()),
|
||||
print object(fresh-atom,"B",map(),
|
||||
object(fresh-atom,"C",map())),
|
||||
print object(fresh-atom,"D",map(),
|
||||
object(fresh-atom,"E",map(),
|
||||
object(fresh-atom,"F",map())),
|
||||
object(fresh-atom,"G",map()))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
object(atom("@1"),"A",map-empty),
|
||||
object(atom("@2"),"B",map-empty,object(atom("@3"),"C",map-empty)),
|
||||
object(atom("@4"),"D",map-empty,
|
||||
object(atom("@5"),"E",map-empty,object(atom("@6"),"F",map-empty)),
|
||||
object(atom("@7"),"G",map-empty))
|
||||
];
|
||||
}
|
||||
32
IBAF-cbs/Funcons-beta/Values/Composite/Records/Records.cbs
Normal file
32
IBAF-cbs/Funcons-beta/Values/Composite/Records/Records.cbs
Normal file
@@ -0,0 +1,32 @@
|
||||
### Records
|
||||
|
||||
[
|
||||
Datatype records
|
||||
Funcon record
|
||||
Funcon record-map
|
||||
Funcon record-select
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
T <: values
|
||||
|
||||
|
||||
Datatype
|
||||
records(T) ::= record(_:maps(identifiers,T))
|
||||
/*
|
||||
A value of type `records(T)` contains a map from identifiers to values of
|
||||
type `T`.
|
||||
*/
|
||||
|
||||
|
||||
Funcon
|
||||
record-map(_:records(T)) : =>maps(identifiers,T)
|
||||
Rule
|
||||
record-map(record(M:maps(_,_))) ~> M
|
||||
|
||||
|
||||
Funcon
|
||||
record-select(R:records(T), I:identifiers) : =>T?
|
||||
~> map-lookup(record-map(R), I)
|
||||
|
||||
68
IBAF-cbs/Funcons-beta/Values/Composite/Records/index.md
Normal file
68
IBAF-cbs/Funcons-beta/Values/Composite/Records/index.md
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Records"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Records.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Records
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_records">records</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_record">record</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_record-map">record-map</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_record-select">record-select</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_records">records</span></span>(<span id="Variable44_T"><i class="var">T</i></span>) ::= <span id="Name_record">record</span>(_:<span class="name"><a href="../Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>,<span id="Variable63_T"><i class="var">T</i></span>))</code></pre></div>
|
||||
|
||||
|
||||
A value of type <code><span class="name"><a href="#Name_records">records</a></span>(<i class="var">T</i>)</code> contains a map from identifiers to values of
|
||||
type <code><i class="var">T</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_record-map">record-map</span></span>(_:<span class="name"><a href="#Name_records">records</a></span>(<span id="Variable134_T"><i class="var">T</i></span>)) : =><span class="name"><a href="../Maps/index.html#Name_maps">maps</a></span>(<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>,<span id="Variable157_T"><i class="var">T</i></span>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_record-map">record-map</a></span>(<span class="name"><a href="#Name_record">record</a></span>(<span id="Variable174_M"><i class="var">M</i></span>:<span class="name"><a href="../Maps/index.html#Name_maps">maps</a></span>(_,_))) ~> <a href="#Variable174_M"><i class="var">M</i></a></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_record-select">record-select</span></span>(<span id="Variable217_R"><i class="var">R</i></span>:<span class="name"><a href="#Name_records">records</a></span>(<span id="Variable222_T"><i class="var">T</i></span>), <span id="Variable236_I"><i class="var">I</i></span>:<span class="name"><a href="../../../Computations/Normal/Binding/index.html#Name_identifiers">identifiers</a></span>) : =><span id="Variable253_T?"><i class="var">T<sup class="sup">?</sup></i></span>
|
||||
~> <span class="name"><a href="../Maps/index.html#Name_map-lookup">map-lookup</a></span>(<span class="name"><a href="#Name_record-map">record-map</a></span>(<a href="#Variable217_R"><i class="var">R</i></a>), <a href="#Variable236_I"><i class="var">I</i></a>)</code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Records.cbs]: Records.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/Composite/Records/Records.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,29 @@
|
||||
### References and pointers
|
||||
|
||||
[
|
||||
Datatype references
|
||||
Funcon reference
|
||||
Type pointers
|
||||
Funcon pointer-null
|
||||
Funcon dereference
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
T <: values
|
||||
|
||||
|
||||
Datatype
|
||||
references(T) ::= reference(_:T)
|
||||
|
||||
|
||||
Datatype
|
||||
pointers(T) ::= pointer-null | { _:references(T) }
|
||||
|
||||
|
||||
Funcon
|
||||
dereference(_:pointers(T)) : =>(T)?
|
||||
Rule
|
||||
dereference(reference(V:T)) ~> V
|
||||
Rule
|
||||
dereference(pointer-null) ~> ( )
|
||||
66
IBAF-cbs/Funcons-beta/Values/Composite/References/index.md
Normal file
66
IBAF-cbs/Funcons-beta/Values/Composite/References/index.md
Normal file
@@ -0,0 +1,66 @@
|
||||
---
|
||||
layout: default
|
||||
title: "References"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [References.cbs]
|
||||
-----------------------------
|
||||
|
||||
### References and pointers
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_references">references</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_reference">reference</a></span>
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_pointers">pointers</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_pointer-null">pointer-null</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_dereference">dereference</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_references">references</span></span>(<span id="Variable48_T"><i class="var">T</i></span>) ::= <span id="Name_reference">reference</span>(_:<span id="Variable64_T"><i class="var">T</i></span>)</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Datatype</i>
|
||||
<span class="name"><span id="Name_pointers">pointers</span></span>(<span id="Variable86_T"><i class="var">T</i></span>) ::= <span id="Name_pointer-null">pointer-null</span> | { _:<span class="name"><a href="#Name_references">references</a></span>(<a href="#Variable86_T"><i class="var">T</i></a>) }</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_dereference">dereference</span></span>(_:<span class="name"><a href="#Name_pointers">pointers</a></span>(<span id="Variable129_T"><i class="var">T</i></span>)) : =>(<span id="Variable149_T"><i class="var">T</i></span>)<sup class="sup">?</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_dereference">dereference</a></span>(<span class="name"><a href="#Name_reference">reference</a></span>(<span id="Variable166_V"><i class="var">V</i></span>:<i class="var">T</i>)) ~> <a href="#Variable166_V"><i class="var">V</i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_dereference">dereference</a></span>(<span class="name"><a href="#Name_pointer-null">pointer-null</a></span>) ~> ( )</code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[References.cbs]: References.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/Composite/References/References.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
157
IBAF-cbs/Funcons-beta/Values/Composite/Sequences/Sequences.cbs
Normal file
157
IBAF-cbs/Funcons-beta/Values/Composite/Sequences/Sequences.cbs
Normal file
@@ -0,0 +1,157 @@
|
||||
### Sequences of values
|
||||
|
||||
[
|
||||
Funcon length
|
||||
Funcon index
|
||||
Funcon is-in
|
||||
Funcon first
|
||||
Funcon second
|
||||
Funcon third
|
||||
Funcon first-n
|
||||
Funcon drop-first-n
|
||||
Funcon reverse
|
||||
Funcon n-of
|
||||
Funcon intersperse
|
||||
]
|
||||
|
||||
/*
|
||||
Sequences of two or more values are not themselves values, nor is the empty
|
||||
sequence a value. However, sequences can be provided to funcons as arguments,
|
||||
and returned as results. Many operations on composite values can be expressed
|
||||
by extracting their components as sequences, operating on the sequences, then
|
||||
forming the required composite values from the resulting sequences.
|
||||
|
||||
A sequence with elements `X1`, ..., `Xn` is written `X1,...,Xn`.
|
||||
A sequence with a single element `X` is identified with (and written) `X`.
|
||||
An empty sequence is indicated by the absence of a term.
|
||||
Any sequence `X*` can be enclosed in parentheses `(X*)`, e.g.:
|
||||
`( )`, `(1)`, `(1,2,3)`. Superfluous commas are ignored.
|
||||
|
||||
The elements of a type sequence `T1,...,Tn` are the value sequences `V1,...,Vn`
|
||||
where `V1:T1`, ..., `Vn:Tn`. The only element of the empty type sequence `( )`
|
||||
is the empty value sequence `( )`.
|
||||
|
||||
`(T)^N` is equivalent to `T,...,T` with `N` occurrences of `T`.
|
||||
`(T)*` is equivalent to the union of all `(T)^N` for `N`>=0,
|
||||
`(T)+` is equivalent to the union of all `(T)^N` for `N`>=1, and
|
||||
`(T)?` is equivalent to `T | ( )`.
|
||||
The parentheses around `T` above can be omitted when they are not needed for
|
||||
disambiguation.
|
||||
|
||||
(Non-trivial) sequence types are not values, so not included in `types`.
|
||||
*/
|
||||
|
||||
|
||||
Meta-variables
|
||||
T, T' <: values
|
||||
|
||||
|
||||
Funcon
|
||||
length(_:values*) : =>natural-numbers
|
||||
/*
|
||||
`length(V*)` gives the number of elements in `V*`.
|
||||
*/
|
||||
Rule
|
||||
length( ) ~> 0
|
||||
Rule
|
||||
length(V:values, V*:values*) ~> natural-successor(length(V*))
|
||||
|
||||
|
||||
Funcon
|
||||
is-in(_:values, _:values*) : =>booleans
|
||||
Rule
|
||||
is-in(V:values ,V':values, V*:values*) ~> or(is-equal(V, V'), is-in(V, V*))
|
||||
Rule
|
||||
is-in(V:values, ( )) ~> false
|
||||
|
||||
|
||||
#### Sequence indexing
|
||||
|
||||
Funcon
|
||||
index(_:natural-numbers, _:values*) : =>values?
|
||||
/*
|
||||
`index(N, V*)` gives the `N`th element of `V*`, if it exists, otherwise `( )`.
|
||||
*/
|
||||
Rule
|
||||
index(1, V:values, V*:values*) ~> V
|
||||
Rule
|
||||
natural-predecessor(N) ~> N'
|
||||
-----------------------------------------------------------------
|
||||
index(N:positive-integers, _:values, V*:values*) ~> index(N', V*)
|
||||
Rule
|
||||
index(0, V*:values*) ~> ( )
|
||||
Rule
|
||||
index(_:positive-integers, ( )) ~> ( )
|
||||
|
||||
|
||||
/* Total indexing funcons: */
|
||||
|
||||
Funcon
|
||||
first(_:T, _:values*) : =>T
|
||||
Rule
|
||||
first(V:T, V*:values*) ~> V
|
||||
|
||||
Funcon
|
||||
second(_:values, _:T, _:values*) : =>T
|
||||
Rule
|
||||
second(_:values, V:T, V*:values*) ~> V
|
||||
|
||||
Funcon
|
||||
third(_:values, _:values, _:T, _:values*) : =>T
|
||||
Rule
|
||||
third(_:values, _:values, V:T, V*:values*) ~> V
|
||||
|
||||
|
||||
#### Homogeneous sequences
|
||||
|
||||
|
||||
Funcon
|
||||
first-n(_:natural-numbers, _:(T)*) : =>(T)*
|
||||
Rule
|
||||
first-n(0, V*:(T)*) ~> ( )
|
||||
Rule
|
||||
natural-predecessor(N) ~> N'
|
||||
-----------------------------------------------------------------
|
||||
first-n(N:positive-integers, V:T, V*:(T)*) ~> (V,first-n(N', V*))
|
||||
Rule
|
||||
first-n(N:positive-integers, ( )) ~> ( )
|
||||
|
||||
|
||||
Funcon
|
||||
drop-first-n(_:natural-numbers, _:(T)*) : =>(T)*
|
||||
Rule
|
||||
drop-first-n(0, V*:(T)*) ~> V*
|
||||
Rule
|
||||
natural-predecessor(N) ~> N'
|
||||
-----------------------------------------------------------------------
|
||||
drop-first-n(N:positive-integers, _:T, V*:(T)*) ~> drop-first-n(N', V*)
|
||||
Rule
|
||||
drop-first-n(N:positive-integers, ( )) ~> ( )
|
||||
|
||||
|
||||
Funcon
|
||||
reverse(_:(T)*) : =>(T)*
|
||||
Rule
|
||||
reverse( ) ~> ( )
|
||||
Rule
|
||||
reverse(V:T, V*:(T)*) ~> (reverse(V*), V)
|
||||
|
||||
|
||||
Funcon
|
||||
n-of(N:natural-numbers, V:T) : =>(T)*
|
||||
Rule
|
||||
n-of(0, _:T) ~> ( )
|
||||
Rule
|
||||
natural-predecessor(N) ~> N'
|
||||
--------------------------------------------------
|
||||
n-of(N:positive-integers, V:T) ~> (V, n-of(N', V))
|
||||
|
||||
|
||||
Funcon
|
||||
intersperse(_:T', _:(T)*) : =>(T, (T', T)*)?
|
||||
Rule
|
||||
intersperse(_:T', ( )) ~> ( )
|
||||
Rule
|
||||
intersperse(_:T', V) ~> V
|
||||
Rule
|
||||
intersperse(V':T', V1:T, V2:T, V*:(T)*) ~> (V1, V', intersperse(V', V2, V*))
|
||||
192
IBAF-cbs/Funcons-beta/Values/Composite/Sequences/index.md
Normal file
192
IBAF-cbs/Funcons-beta/Values/Composite/Sequences/index.md
Normal file
@@ -0,0 +1,192 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Sequences"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Sequences.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Sequences of values
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_length">length</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_index">index</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-in">is-in</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_first">first</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_second">second</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_third">third</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_first-n">first-n</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_drop-first-n">drop-first-n</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_reverse">reverse</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_n-of">n-of</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_intersperse">intersperse</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
Sequences of two or more values are not themselves values, nor is the empty
|
||||
sequence a value. However, sequences can be provided to funcons as arguments,
|
||||
and returned as results. Many operations on composite values can be expressed
|
||||
by extracting their components as sequences, operating on the sequences, then
|
||||
forming the required composite values from the resulting sequences.
|
||||
|
||||
A sequence with elements <code><i class="var">X<sub class="sub">1</sub></i></code>, ..., <code><i class="var">Xn</i></code> is written <code><i class="var">X<sub class="sub">1</sub></i>,...,<i class="var">Xn</i></code>.
|
||||
A sequence with a single element <code><i class="var">X</i></code> is identified with (and written) <code><i class="var">X</i></code>.
|
||||
An empty sequence is indicated by the absence of a term.
|
||||
Any sequence <code><i class="var">X<sup class="sup">*</sup></i></code> can be enclosed in parentheses <code>(<i class="var">X<sup class="sup">*</sup></i>)</code>, e.g.:
|
||||
<code>( )</code>, <code>(1)</code>, <code>(1,2,3)</code>. Superfluous commas are ignored.
|
||||
|
||||
The elements of a type sequence <code><i class="var">T<sub class="sub">1</sub></i>,...,<i class="var">Tn</i></code> are the value sequences <code><i class="var">V<sub class="sub">1</sub></i>,...,<i class="var">Vn</i></code>
|
||||
where <code><i class="var">V<sub class="sub">1</sub></i>:<i class="var">T<sub class="sub">1</sub></i></code>, ..., <code><i class="var">Vn</i>:<i class="var">Tn</i></code>. The only element of the empty type sequence <code>( )</code>
|
||||
is the empty value sequence <code>( )</code>.
|
||||
|
||||
<code>(<i class="var">T</i>)^<i class="var">N</i></code> is equivalent to <code><i class="var">T</i>,...,<i class="var">T</i></code> with <code><i class="var">N</i></code> occurrences of <code><i class="var">T</i></code>.
|
||||
<code>(<i class="var">T</i>)<sup class="sup">*</sup></code> is equivalent to the union of all <code>(<i class="var">T</i>)^<i class="var">N</i></code> for <code><i class="var">N</i></code>>=0,
|
||||
<code>(<i class="var">T</i>)<sup class="sup">+</sup></code> is equivalent to the union of all <code>(<i class="var">T</i>)^<i class="var">N</i></code> for <code><i class="var">N</i></code>>=1, and
|
||||
<code>(<i class="var">T</i>)<sup class="sup">?</sup></code> is equivalent to <code><i class="var">T</i> | ( )</code>.
|
||||
The parentheses around <code><i class="var">T</i></code> above can be omitted when they are not needed for
|
||||
disambiguation.
|
||||
|
||||
(Non-trivial) sequence types are not values, so not included in <code><span class="name"><a href="../../Value-Types/index.html#Name_types">types</a></span></code>.
|
||||
|
||||
|
||||
|
||||
<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′</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">Funcon</i>
|
||||
<span class="name"><span id="Name_length">length</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_length">length</a></span>(<i class="var">V<sup class="sup">*</sup></i>)</code> gives the number of elements in <code><i class="var">V<sup class="sup">*</sup></i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_length">length</a></span>( ) ~> 0
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_length">length</a></span>(<span id="Variable675_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable684_V*"><i class="var">V<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="../../Primitive/Integers/index.html#Name_natural-successor">natural-successor</a></span>(<span class="name"><a href="#Name_length">length</a></span>(<a href="#Variable684_V*"><i class="var">V<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_is-in">is-in</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><sup class="sup">*</sup>) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_is-in">is-in</a></span>(<span id="Variable756_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span> ,<span id="Variable765_V'"><i class="var">V′</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable774_V*"><i class="var">V<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="../../Primitive/Booleans/index.html#Name_or">or</a></span>(<span class="name"><a href="../../Value-Types/index.html#Name_is-equal">is-equal</a></span>(<a href="#Variable756_V"><i class="var">V</i></a>, <a href="#Variable765_V'"><i class="var">V′</i></a>), <span class="name"><a href="#Name_is-in">is-in</a></span>(<a href="#Variable756_V"><i class="var">V</i></a>, <a href="#Variable774_V*"><i class="var">V<sup class="sup">*</sup></i></a>))
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_is-in">is-in</a></span>(<span id="Variable842_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="../../Primitive/Booleans/index.html#Name_false">false</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
#### Sequence indexing
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_index">index</span></span>(_:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) : =><span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">?</sup></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_index">index</a></span>(<i class="var">N</i>, <i class="var">V<sup class="sup">*</sup></i>)</code> gives the <code><i class="var">N</i></code>th element of <code><i class="var">V<sup class="sup">*</sup></i></code>, if it exists, otherwise <code>( )</code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_index">index</a></span>(1, <span id="Variable988_V"><i class="var">V</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable997_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) ~> <a href="#Variable988_V"><i class="var">V</i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-predecessor">natural-predecessor</a></span>(<a href="#Variable1047_N"><i class="var">N</i></a>) ~> <span id="Variable1036_N'"><i class="var">N′</i></span>
|
||||
-----------------------------------------------------------------
|
||||
<span class="name"><a href="#Name_index">index</a></span>(<span id="Variable1047_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable1063_V*"><i class="var">V<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="#Name_index">index</a></span>(<a href="#Variable1036_N'"><i class="var">N′</i></a>, <a href="#Variable1063_V*"><i class="var">V<sup class="sup">*</sup></i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_index">index</a></span>(0, <span id="Variable1108_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) ~> ( )
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_index">index</a></span>(_:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, ( )) ~> ( )</code></pre></div>
|
||||
|
||||
|
||||
|
||||
Total indexing funcons:
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_first">first</span></span>(_:<span id="Variable1168_T"><i class="var">T</i></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) : =><span id="Variable1193_T"><i class="var">T</i></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_first">first</a></span>(<span id="Variable1202_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1214_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) ~> <a href="#Variable1202_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_second">second</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, _:<span id="Variable1251_T"><i class="var">T</i></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) : =><span id="Variable1277_T"><i class="var">T</i></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_second">second</a></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span>, <span id="Variable1293_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1305_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) ~> <a href="#Variable1293_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_third">third</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 id="Variable1351_T"><i class="var">T</i></span>, _:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) : =><span id="Variable1378_T"><i class="var">T</i></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_third">third</a></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 id="Variable1401_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1413_V*"><i class="var">V<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_values">values</a></span><sup class="sup">*</sup>) ~> <a href="#Variable1401_V"><i class="var">V</i></a></code></pre></div>
|
||||
|
||||
|
||||
|
||||
#### Homogeneous sequences
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_first-n">first-n</span></span>(_:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>, _:(<span id="Variable1473_T"><i class="var">T</i></span>)<sup class="sup">*</sup>) : =>(<span id="Variable1495_T"><i class="var">T</i></span>)<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_first-n">first-n</a></span>(0, <span id="Variable1514_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> ( )
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-predecessor">natural-predecessor</a></span>(<a href="#Variable1570_N"><i class="var">N</i></a>) ~> <span id="Variable1559_N'"><i class="var">N′</i></span>
|
||||
-----------------------------------------------------------------
|
||||
<span class="name"><a href="#Name_first-n">first-n</a></span>(<span id="Variable1570_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, <span id="Variable1578_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1590_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> (<a href="#Variable1578_V"><i class="var">V</i></a>,<span class="name"><a href="#Name_first-n">first-n</a></span>(<a href="#Variable1559_N'"><i class="var">N′</i></a>, <a href="#Variable1590_V*"><i class="var">V<sup class="sup">*</sup></i></a>))
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_first-n">first-n</a></span>(<span id="Variable1651_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, ( )) ~> ( )</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_drop-first-n">drop-first-n</span></span>(_:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>, _:(<span id="Variable1689_T"><i class="var">T</i></span>)<sup class="sup">*</sup>) : =>(<span id="Variable1711_T"><i class="var">T</i></span>)<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_drop-first-n">drop-first-n</a></span>(0, <span id="Variable1730_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> <a href="#Variable1730_V*"><i class="var">V<sup class="sup">*</sup></i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-predecessor">natural-predecessor</a></span>(<a href="#Variable1788_N"><i class="var">N</i></a>) ~> <span id="Variable1777_N'"><i class="var">N′</i></span>
|
||||
-----------------------------------------------------------------------
|
||||
<span class="name"><a href="#Name_drop-first-n">drop-first-n</a></span>(<span id="Variable1788_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, _:<i class="var">T</i>, <span id="Variable1807_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> <span class="name"><a href="#Name_drop-first-n">drop-first-n</a></span>(<a href="#Variable1777_N'"><i class="var">N′</i></a>, <a href="#Variable1807_V*"><i class="var">V<sup class="sup">*</sup></i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_drop-first-n">drop-first-n</a></span>(<span id="Variable1857_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, ( )) ~> ( )</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_reverse">reverse</span></span>(_:(<span id="Variable1887_T"><i class="var">T</i></span>)<sup class="sup">*</sup>) : =>(<span id="Variable1908_T"><i class="var">T</i></span>)<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_reverse">reverse</a></span>( ) ~> ( )
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_reverse">reverse</a></span>(<span id="Variable1937_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1949_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> (<span class="name"><a href="#Name_reverse">reverse</a></span>(<a href="#Variable1949_V*"><i class="var">V<sup class="sup">*</sup></i></a>), <a href="#Variable1937_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_n-of">n-of</span></span>(<span id="Variable2002_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span>, <span id="Variable2011_V"><i class="var">V</i></span>:<span id="Variable2015_T"><i class="var">T</i></span>) : =>(<span id="Variable2030_T"><i class="var">T</i></span>)<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_n-of">n-of</a></span>(0, _:<i class="var">T</i>) ~> ( )
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-predecessor">natural-predecessor</a></span>(<a href="#Variable2096_N"><i class="var">N</i></a>) ~> <span id="Variable2085_N'"><i class="var">N′</i></span>
|
||||
--------------------------------------------------
|
||||
<span class="name"><a href="#Name_n-of">n-of</a></span>(<span id="Variable2096_N"><i class="var">N</i></span>:<span class="name"><a href="../../Primitive/Integers/index.html#Name_positive-integers">positive-integers</a></span>, <span id="Variable2104_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> (<a href="#Variable2104_V"><i class="var">V</i></a>, <span class="name"><a href="#Name_n-of">n-of</a></span>(<a href="#Variable2085_N'"><i class="var">N′</i></a>, <a href="#Variable2104_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_intersperse">intersperse</span></span>(_:<span id="Variable2160_T'"><i class="var">T′</i></span>, _:(<span id="Variable2171_T"><i class="var">T</i></span>)<sup class="sup">*</sup>) : =>(<span id="Variable2193_T"><i class="var">T</i></span>, (<span id="Variable2199_T'"><i class="var">T′</i></span>, <span id="Variable2204_T"><i class="var">T</i></span>)<sup class="sup">*</sup>)<sup class="sup">?</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_intersperse">intersperse</a></span>(_:<i class="var">T′</i>, ( )) ~> ( )
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_intersperse">intersperse</a></span>(_:<i class="var">T′</i>, <span id="Variable2270_V"><i class="var">V</i></span>) ~> <a href="#Variable2270_V"><i class="var">V</i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_intersperse">intersperse</a></span>(<span id="Variable2292_V'"><i class="var">V′</i></span>:<i class="var">T′</i>, <span id="Variable2305_V1"><i class="var">V<sub class="sub">1</sub></i></span>:<i class="var">T</i>, <span id="Variable2317_V2"><i class="var">V<sub class="sub">2</sub></i></span>:<i class="var">T</i>, <span id="Variable2329_V*"><i class="var">V<sup class="sup">*</sup></i></span>:(<i class="var">T</i>)<sup class="sup">*</sup>) ~> (<a href="#Variable2305_V1"><i class="var">V<sub class="sub">1</sub></i></a>, <a href="#Variable2292_V'"><i class="var">V′</i></a>, <span class="name"><a href="#Name_intersperse">intersperse</a></span>(<a href="#Variable2292_V'"><i class="var">V′</i></a>, <a href="#Variable2317_V2"><i class="var">V<sub class="sub">2</sub></i></a>, <a href="#Variable2329_V*"><i class="var">V<sup class="sup">*</sup></i></a>))</code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Sequences.cbs]: Sequences.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/Composite/Sequences/Sequences.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,14 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple(1,2,3,4,5), tuple drop-first-n(0,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(2,3,4,5), tuple drop-first-n(1,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(3,4,5), tuple drop-first-n(2,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(4,5), tuple drop-first-n(3,1,2,3,4,5)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple(), tuple first-n(0,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(1), tuple first-n(1,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(1,2), tuple first-n(2,1,2,3,4,5)))
|
||||
, check-true(is-equal(tuple(1,2,3), tuple first-n(3,1,2,3,4,5)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(first(1), 1))
|
||||
, check-true(is-equal(first(1,2,3), 1))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(index(1,1), 1))
|
||||
, check-true(is-equal(index(1,1,2), 1))
|
||||
, check-true(is-equal(index(2,1,2), 2))
|
||||
, check-true(is-equal(index(2,1,2,3), 2))
|
||||
, check-true(not is-value(index(0)))
|
||||
, check-true(not is-value(index(0,1)))
|
||||
, check-true(not is-value(index(0,1,2)))
|
||||
, check-true(not is-value(index(1)))
|
||||
, check-true(not is-value(index(2)))
|
||||
, check-true(not is-value(index(2,1)))
|
||||
, check-true(not is-value(index(3,1,2)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple intersperse(42), tuple( )))
|
||||
, check-true(is-equal(tuple intersperse(42,1), tuple(1)))
|
||||
, check-true(is-equal(tuple intersperse(0,1,2), tuple(1,0,2)))
|
||||
, check-true(is-equal(tuple intersperse(0,1,2,3), tuple(1,0,2,0,3)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-in(1,1))
|
||||
, check-true(is-in(1,1,2))
|
||||
, check-true(is-in(2,1,2))
|
||||
, check-true(is-in(3,1,2,3,4,5))
|
||||
, check-true(not is-in(0))
|
||||
, check-true(not is-in(1))
|
||||
, check-true(not is-in(0,1))
|
||||
, check-true(not is-in(3,1,2))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(length( ), 0))
|
||||
, check-true(is-equal(length(1), 1))
|
||||
, check-true(is-equal(length(1,2,3), 3))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple n-of(0,42), tuple( )))
|
||||
, check-true(is-equal(tuple n-of(1,2), tuple(2)))
|
||||
, check-true(is-equal(tuple n-of(2,3), tuple(3,3)))
|
||||
, check-true(is-equal(tuple n-of(3,4), tuple(4,4,4)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(tuple reverse( ), tuple( )))
|
||||
, check-true(is-equal(tuple reverse(1), tuple(1)))
|
||||
, check-true(is-equal(tuple reverse(1,2), tuple(2,1)))
|
||||
, check-true(is-equal(tuple reverse(1,2,3), tuple(3,2,1)))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(second(1,2), 2))
|
||||
, check-true(is-equal(second(1,2,3), 2))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
general {
|
||||
funcon-term: sequential (
|
||||
check-true(is-equal(third(1,2,3), 3))
|
||||
, check-true(is-equal(third(1,2,3,4), 3))
|
||||
, print "OK"
|
||||
);
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term : null-value;
|
||||
standard-out : ["OK"];
|
||||
}
|
||||
155
IBAF-cbs/Funcons-beta/Values/Composite/Sets/Sets.cbs
Normal file
155
IBAF-cbs/Funcons-beta/Values/Composite/Sets/Sets.cbs
Normal file
@@ -0,0 +1,155 @@
|
||||
### Sets
|
||||
|
||||
[
|
||||
Type sets
|
||||
Funcon set
|
||||
Funcon set-elements
|
||||
Funcon is-in-set
|
||||
Funcon is-subset
|
||||
Funcon set-insert
|
||||
Funcon set-unite
|
||||
Funcon set-intersect
|
||||
Funcon set-difference
|
||||
Funcon set-size
|
||||
Funcon some-element
|
||||
Funcon element-not-in
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
GT <: ground-values
|
||||
|
||||
|
||||
Built-in Type
|
||||
sets(GT)
|
||||
/*
|
||||
`sets(GT)` is the type of possibly-empty finite sets `{V1, ..., Vn}`
|
||||
where `V1:GT`, ..., `Vn:GT`.
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set(_:(GT)*) : =>sets(GT)
|
||||
/*
|
||||
The notation `{V1, ..., Vn}` for `set(V1, ..., Vn)` is built-in.
|
||||
*/
|
||||
Assert
|
||||
{V*:(GT)*} == set(V*)
|
||||
/*
|
||||
Note that `set(...)` is not a constructor operation. The order and duplicates
|
||||
of argument values are ignored (e.g., `{1,2,1}` denotes the same set as `{1,2}`
|
||||
and `{2,1}`).
|
||||
*/
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set-elements(_:sets(GT)) : =>(GT)*
|
||||
/*
|
||||
For each set `S`, the sequence of values `V*` returned by `set-elements(S)`
|
||||
contains each element of `S` just once. The order of the values in `V*` is
|
||||
unspecified, and may vary between sets (e.g., `set-elements{1,2}` could be
|
||||
`(1,2)` and `set-elements{1,2,3}` could be `(3,2,1)`).
|
||||
*/
|
||||
Assert
|
||||
set(set-elements(S)) == S
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
is-in-set(_:GT, _:sets(GT)) : =>booleans
|
||||
/*
|
||||
`is-in-set(GV,S)` tests whether `GV` is in the set `S`.
|
||||
*/
|
||||
Assert
|
||||
is-in-set(GV:GT, { }) == false
|
||||
Assert
|
||||
is-in-set(GV:GT, {GV}:sets(GT)) == true
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
is-subset(_:sets(GT), _:sets(GT)) : =>booleans
|
||||
/*
|
||||
`is-subset(S1,S2)` tests whether `S1` is a subset of `S2`.
|
||||
*/
|
||||
Assert
|
||||
is-subset({ }, S:sets(GT)) == true
|
||||
Assert
|
||||
is-subset(S:sets(GT), S) == true
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set-insert(_:GT, _:sets(GT)) : =>sets(GT)
|
||||
/*
|
||||
`set-insert(GV, S)` returns the set union of `{GV}` and `S`.
|
||||
*/
|
||||
Assert
|
||||
is-in-set(GV:GT, set-insert(GV:GT, S:sets(GT))) == true
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set-unite(_:(sets(GT))*) : =>sets(GT)
|
||||
/*
|
||||
`set-unite(...)` unites a sequence of sets.
|
||||
*/
|
||||
Assert
|
||||
set-unite(S:sets(GT), S) == S
|
||||
Assert
|
||||
set-unite(S1:sets(GT), S2:sets(GT)) == set-unite(S2, S1)
|
||||
Assert
|
||||
set-unite(S1:sets(GT), set-unite(S2:sets(GT), S3:sets(GT))) ==
|
||||
set-unite(set-unite(S1, S2), S3)
|
||||
Assert
|
||||
set-unite(S1:sets(GT), S2:sets(GT), S3:sets(GT)) ==
|
||||
set-unite(S1, set-unite(S2, S3))
|
||||
Assert
|
||||
set-unite(S:sets(GT)) == S
|
||||
Assert
|
||||
set-unite( ) == { }
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set-intersect(_:(sets(GT))+) : =>sets(GT)
|
||||
/*
|
||||
`set-intersect(GT,...)` intersects a non-empty sequence of sets.
|
||||
*/
|
||||
Assert
|
||||
set-intersect(S:sets(GT), S) == S
|
||||
Assert
|
||||
set-intersect(S1:sets(GT), S2:sets(GT)) == set-intersect(S2, S1)
|
||||
Assert
|
||||
set-intersect(S1:sets(GT), set-intersect(S2:sets(GT), S3:sets(GT))) ==
|
||||
set-intersect(set-intersect(S1, S2), S3)
|
||||
Assert
|
||||
set-intersect(S1:sets(GT), S2:sets(GT), S3:sets(GT)) ==
|
||||
set-intersect(S1, set-intersect(S2, S3))
|
||||
Assert
|
||||
set-intersect(S:sets(GT)) == S
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
set-difference(_:sets(GT), _:sets(GT)) : =>sets(GT)
|
||||
/*
|
||||
`set-difference(S1, S2)` returns the set containing those elements of `S1`
|
||||
that are not in `S2`.
|
||||
*/
|
||||
|
||||
Built-in Funcon
|
||||
set-size(_:sets(GT)) : =>natural-numbers
|
||||
Assert
|
||||
set-size(S:sets(GT)) == length(set-elements(S))
|
||||
|
||||
|
||||
Funcon
|
||||
some-element(_:sets(GT)) : =>GT?
|
||||
Assert
|
||||
some-element(S:sets(GT)) == index(1, set-elements(S))
|
||||
Assert
|
||||
some-element{ } == ( )
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
element-not-in(GT:types, _:set(GT)) : =>GT?
|
||||
/*
|
||||
`element-not-in(GT, S)` gives an element of the type `GT` not in the set
|
||||
`S`, or `( )` when `S` is empty. When the set of elements of `GT` is infinite,
|
||||
`element-not-in(GT, S)` never gives `( )`.
|
||||
*/
|
||||
198
IBAF-cbs/Funcons-beta/Values/Composite/Sets/index.md
Normal file
198
IBAF-cbs/Funcons-beta/Values/Composite/Sets/index.md
Normal file
@@ -0,0 +1,198 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Sets"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Sets.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Sets
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_sets">sets</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set">set</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-elements">set-elements</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-in-set">is-in-set</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_is-subset">is-subset</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-insert">set-insert</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-unite">set-unite</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-intersect">set-intersect</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-difference">set-difference</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_set-size">set-size</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_some-element">some-element</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_element-not-in">element-not-in</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Meta-variables</i>
|
||||
<span id="PartVariable_GT"><i class="var">GT</i></span> <: <span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-values</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_sets">sets</span></span>(<span id="Variable76_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)</code> is the type of possibly-empty finite sets <code>{<i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>}</code>
|
||||
where <code><i class="var">V<sub class="sub">1</sub></i>:<i class="var">GT</i></code>, ..., <code><i class="var">Vn</i>:<i class="var">GT</i></code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set">set</span></span>(_:(<span id="Variable190_GT"><i class="var">GT</i></span>)<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable212_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
The notation <code>{<i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>}</code> for <code><span class="name"><a href="#Name_set">set</a></span>(<i class="var">V<sub class="sub">1</sub></i>, ..., <i class="var">Vn</i>)</code> is built-in.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
{<i class="var">V<sup class="sup">*</sup></i>:(<i class="var">GT</i>)<sup class="sup">*</sup>} == <span class="name"><a href="#Name_set">set</a></span>(<i class="var">V<sup class="sup">*</sup></i>)</code></pre></div>
|
||||
|
||||
|
||||
Note that <code><span class="name"><a href="#Name_set">set</a></span>(...)</code> is not a constructor operation. The order and duplicates
|
||||
of argument values are ignored (e.g., <code>{1,2,1}</code> denotes the same set as <code>{1,2}</code>
|
||||
and <code>{2,1}</code>).
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-elements">set-elements</span></span>(_:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable418_GT"><i class="var">GT</i></span>)) : =>(<span id="Variable438_GT"><i class="var">GT</i></span>)<sup class="sup">*</sup></code></pre></div>
|
||||
|
||||
For each set <code><i class="var">S</i></code>, the sequence of values <code><i class="var">V<sup class="sup">*</sup></i></code> returned by <code><span class="name"><a href="#Name_set-elements">set-elements</a></span>(<i class="var">S</i>)</code>
|
||||
contains each element of <code><i class="var">S</i></code> just once. The order of the values in <code><i class="var">V<sup class="sup">*</sup></i></code> is
|
||||
unspecified, and may vary between sets (e.g., <code><span class="name"><a href="#Name_set-elements">set-elements</a></span>{1,2}</code> could be
|
||||
<code>(1,2)</code> and <code><span class="name"><a href="#Name_set-elements">set-elements</a></span>{1,2,3}</code> could be <code>(3,2,1)</code>).
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set">set</a></span>(<span class="name"><a href="#Name_set-elements">set-elements</a></span>(<i class="var">S</i>)) == <i class="var">S</i></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-in-set">is-in-set</span></span>(_:<span id="Variable646_GT"><i class="var">GT</i></span>, _:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable658_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_is-in-set">is-in-set</a></span>(<i class="var">GV</i>,<i class="var">S</i>)</code> tests whether <code><i class="var">GV</i></code> is in the set <code><i class="var">S</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_is-in-set">is-in-set</a></span>(<i class="var">GV</i>:<i class="var">GT</i>, { }) == <span class="name"><a href="../../Primitive/Booleans/index.html#Name_false">false</a></span>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_is-in-set">is-in-set</a></span>(<i class="var">GV</i>:<i class="var">GT</i>, {<i class="var">GV</i>}:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="../../Primitive/Booleans/index.html#Name_true">true</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_is-subset">is-subset</span></span>(_:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable821_GT"><i class="var">GT</i></span>), _:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable839_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Booleans/index.html#Name_booleans">booleans</a></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_is-subset">is-subset</a></span>(<i class="var">S<sub class="sub">1</sub></i>,<i class="var">S<sub class="sub">2</sub></i>)</code> tests whether <code><i class="var">S<sub class="sub">1</sub></i></code> is a subset of <code><i class="var">S<sub class="sub">2</sub></i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_is-subset">is-subset</a></span>({ }, <i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="../../Primitive/Booleans/index.html#Name_true">true</a></span>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_is-subset">is-subset</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S</i>) == <span class="name"><a href="../../Primitive/Booleans/index.html#Name_true">true</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-insert">set-insert</span></span>(_:<span id="Variable1001_GT"><i class="var">GT</i></span>, _:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1013_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1035_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_set-insert">set-insert</a></span>(<i class="var">GV</i>, <i class="var">S</i>)</code> returns the set union of <code>{<i class="var">GV</i>}</code> and <code><i class="var">S</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_is-in-set">is-in-set</a></span>(<i class="var">GV</i>:<i class="var">GT</i>, <span class="name"><a href="#Name_set-insert">set-insert</a></span>(<i class="var">GV</i>:<i class="var">GT</i>, <i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>))) == <span class="name"><a href="../../Primitive/Booleans/index.html#Name_true">true</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-unite">set-unite</span></span>(_:(<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1178_GT"><i class="var">GT</i></span>))<sup class="sup">*</sup>) : =><span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1206_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_set-unite">set-unite</a></span>(...)</code> unites a sequence of sets.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S</i>) == <i class="var">S</i>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">2</sub></i>, <i class="var">S<sub class="sub">1</sub></i>)
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">3</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>))) ==
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">1</sub></i>, <i class="var">S<sub class="sub">2</sub></i>), <i class="var">S<sub class="sub">3</sub></i>)
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">3</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) ==
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">1</sub></i>, <span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S<sub class="sub">2</sub></i>, <i class="var">S<sub class="sub">3</sub></i>))
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <i class="var">S</i>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-unite">set-unite</a></span>( ) == { }</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-intersect">set-intersect</span></span>(_:(<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1611_GT"><i class="var">GT</i></span>))<sup class="sup">+</sup>) : =><span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable1639_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">GT</i>,...)</code> intersects a non-empty sequence of sets.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S</i>) == <i class="var">S</i>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">2</sub></i>, <i class="var">S<sub class="sub">1</sub></i>)
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">3</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>))) ==
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">1</sub></i>, <i class="var">S<sub class="sub">2</sub></i>), <i class="var">S<sub class="sub">3</sub></i>)
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">1</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">2</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>), <i class="var">S<sub class="sub">3</sub></i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) ==
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">1</sub></i>, <span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S<sub class="sub">2</sub></i>, <i class="var">S<sub class="sub">3</sub></i>))
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-intersect">set-intersect</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <i class="var">S</i></code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-difference">set-difference</span></span>(_:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable2038_GT"><i class="var">GT</i></span>), _:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable2056_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable2078_GT"><i class="var">GT</i></span>)</code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_set-difference">set-difference</a></span>(<i class="var">S<sub class="sub">1</sub></i>, <i class="var">S<sub class="sub">2</sub></i>)</code> returns the set containing those elements of <code><i class="var">S<sub class="sub">1</sub></i></code>
|
||||
that are not in <code><i class="var">S<sub class="sub">2</sub></i></code>.
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_set-size">set-size</span></span>(_:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable2160_GT"><i class="var">GT</i></span>)) : =><span class="name"><a href="../../Primitive/Integers/index.html#Name_natural-numbers">natural-numbers</a></span></code></pre></div>
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_set-size">set-size</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="../Sequences/index.html#Name_length">length</a></span>(<span class="name"><a href="#Name_set-elements">set-elements</a></span>(<i class="var">S</i>))</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_some-element">some-element</span></span>(_:<span class="name"><a href="#Name_sets">sets</a></span>(<span id="Variable2237_GT"><i class="var">GT</i></span>)) : =><span id="Variable2258_GT?"><i class="var">GT<sup class="sup">?</sup></i></span>
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_some-element">some-element</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_sets">sets</a></span>(<i class="var">GT</i>)) == <span class="name"><a href="../Sequences/index.html#Name_index">index</a></span>(1, <span class="name"><a href="#Name_set-elements">set-elements</a></span>(<i class="var">S</i>))
|
||||
<i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_some-element">some-element</a></span>{ } == ( )</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_element-not-in">element-not-in</span></span>(<span id="Variable2328_GT"><i class="var">GT</i></span>:<span class="name"><a href="../../Value-Types/index.html#Name_types">types</a></span>, _:<span class="name"><a href="#Name_set">set</a></span>(<span id="Variable2341_GT"><i class="var">GT</i></span>)) : =><span id="Variable2363_GT?"><i class="var">GT<sup class="sup">?</sup></i></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_element-not-in">element-not-in</a></span>(<i class="var">GT</i>, <i class="var">S</i>)</code> gives an element of the type <code><i class="var">GT</i></code> not in the set
|
||||
<code><i class="var">S</i></code>, or <code>( )</code> when <code><i class="var">S</i></code> is empty. When the set of elements of <code><i class="var">GT</i></code> is infinite,
|
||||
<code><span class="name"><a href="#Name_element-not-in">element-not-in</a></span>(<i class="var">GT</i>, <i class="var">S</i>)</code> never gives <code>( )</code>.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Sets.cbs]: Sets.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/Composite/Sets/Sets.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,27 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print set-difference({1},set()),
|
||||
print set-difference(set(),{2}),
|
||||
print set-difference({1},{2}),
|
||||
print set-difference({1,2},{1,2}),
|
||||
print set-difference({1,2},{1}),
|
||||
print set-difference({1,2},set()),
|
||||
print "OK"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{1},
|
||||
{},
|
||||
{1},
|
||||
{},
|
||||
{2},
|
||||
{1,2},
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print tuple(set-elements set( )),
|
||||
print tuple(set-elements {1}),
|
||||
print tuple(set-elements {2,3})
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [tuple(), tuple(1), tuple(2, 3) ];
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print set-unite({1},set()),
|
||||
print set-unite(set(),{2}),
|
||||
print set-unite({1},{2}),
|
||||
print set-unite({1}),
|
||||
print set-unite(set()),
|
||||
print set-unite(),
|
||||
print "OK"
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
{1},
|
||||
{2},
|
||||
{1,2},
|
||||
{1},
|
||||
set(),
|
||||
set(),
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
21
IBAF-cbs/Funcons-beta/Values/Composite/Sets/tests/set.config
Normal file
21
IBAF-cbs/Funcons-beta/Values/Composite/Sets/tests/set.config
Normal file
@@ -0,0 +1,21 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print set(),
|
||||
print {1},
|
||||
print {1,2,3},
|
||||
print cast({1,2}, sets(integers))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
set(),
|
||||
{1},
|
||||
{1, 2, 3},
|
||||
{1, 2}
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print some-element {1},
|
||||
print some-element {1,2},
|
||||
print some-element {1,2,3}
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [1, 1, 1];
|
||||
}
|
||||
36
IBAF-cbs/Funcons-beta/Values/Composite/Strings/Strings.cbs
Normal file
36
IBAF-cbs/Funcons-beta/Values/Composite/Strings/Strings.cbs
Normal file
@@ -0,0 +1,36 @@
|
||||
### Strings
|
||||
|
||||
[
|
||||
Type strings
|
||||
Funcon string
|
||||
Funcon string-append
|
||||
Funcon to-string
|
||||
]
|
||||
|
||||
|
||||
Type
|
||||
strings ~> lists(characters)
|
||||
|
||||
|
||||
Funcon
|
||||
string(C*:characters*) : =>strings
|
||||
~> [C*]
|
||||
/*
|
||||
Literal strings are written `"C1...Cn"`.
|
||||
A double-quote or backslash needs to be escaped: `"...\"..."`, `"...\\..."`.
|
||||
*/
|
||||
|
||||
|
||||
Funcon
|
||||
string-append(S*:strings*) : =>strings
|
||||
~> list-append(S*)
|
||||
|
||||
|
||||
Built-in Funcon
|
||||
to-string(_:ground-values) : =>strings
|
||||
/*
|
||||
The strings returned by `to-string(GV)` are unspecified, except that when
|
||||
`GV` is already a string, it is returned unchanged.
|
||||
*/
|
||||
Assert
|
||||
to-string(S:strings) == S
|
||||
75
IBAF-cbs/Funcons-beta/Values/Composite/Strings/index.md
Normal file
75
IBAF-cbs/Funcons-beta/Values/Composite/Strings/index.md
Normal file
@@ -0,0 +1,75 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Strings"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Strings.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Strings
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Type</i> <span class="name"><a href="#Name_strings">strings</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_string">string</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_string-append">string-append</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_to-string">to-string</a></span>
|
||||
]</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Type</i>
|
||||
<span class="name"><span id="Name_strings">strings</span></span> ~> <span class="name"><a href="../Lists/index.html#Name_lists">lists</a></span>(<span class="name"><a href="../../Primitive/Characters/index.html#Name_characters">characters</a></span>)</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_string">string</span></span>(<span id="Variable47_C*"><i class="var">C<sup class="sup">*</sup></i></span>:<span class="name"><a href="../../Primitive/Characters/index.html#Name_characters">characters</a></span><sup class="sup">*</sup>) : =><span class="name"><a href="#Name_strings">strings</a></span>
|
||||
~> [<a href="#Variable47_C*"><i class="var">C<sup class="sup">*</sup></i></a>]</code></pre></div>
|
||||
|
||||
|
||||
Literal strings are written <code>"C1...Cn"</code>.
|
||||
A double-quote or backslash needs to be escaped: <code>"...\"..."</code>, <code>"...\\..."</code>.
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_string-append">string-append</span></span>(<span id="Variable119_S*"><i class="var">S<sup class="sup">*</sup></i></span>:<span class="name"><a href="#Name_strings">strings</a></span><sup class="sup">*</sup>) : =><span class="name"><a href="#Name_strings">strings</a></span>
|
||||
~> <span class="name"><a href="../Lists/index.html#Name_list-append">list-append</a></span>(<a href="#Variable119_S*"><i class="var">S<sup class="sup">*</sup></i></a>)</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Built-in</i> <i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_to-string">to-string</span></span>(_:<span class="name"><a href="../../Value-Types/index.html#Name_ground-values">ground-values</a></span>) : =><span class="name"><a href="#Name_strings">strings</a></span></code></pre></div>
|
||||
|
||||
The strings returned by <code><span class="name"><a href="#Name_to-string">to-string</a></span>(<i class="var">GV</i>)</code> are unspecified, except that when
|
||||
<code><i class="var">GV</i></code> is already a string, it is returned unchanged.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Assert</i>
|
||||
<span class="name"><a href="#Name_to-string">to-string</a></span>(<i class="var">S</i>:<span class="name"><a href="#Name_strings">strings</a></span>) == <i class="var">S</i></code></pre></div>
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Strings.cbs]: Strings.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/Composite/Strings/Strings.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
94
IBAF-cbs/Funcons-beta/Values/Composite/Trees/Trees.cbs
Normal file
94
IBAF-cbs/Funcons-beta/Values/Composite/Trees/Trees.cbs
Normal file
@@ -0,0 +1,94 @@
|
||||
### Trees
|
||||
|
||||
[
|
||||
Datatype trees
|
||||
Funcon tree
|
||||
Funcon tree-root-value
|
||||
Funcon tree-branch-sequence
|
||||
Funcon single-branching-sequence
|
||||
Funcon forest-root-value-sequence
|
||||
Funcon forest-branch-sequence
|
||||
Funcon forest-value-sequence
|
||||
]
|
||||
|
||||
|
||||
Meta-variables
|
||||
T <: values
|
||||
|
||||
|
||||
Datatype
|
||||
trees(T) ::= tree( _:T, _:(trees(T))*)
|
||||
/*
|
||||
`trees(T)` consists of finitely-branching trees with elements of type `T`.
|
||||
When `V:T`, `tree(V)` is a leaf, and `tree(V,B1,...,Bn)` is a tree with
|
||||
branches `B1`, ..., `Bn`.
|
||||
*/
|
||||
|
||||
|
||||
Funcon
|
||||
tree-root-value(_:trees(T)) : =>(T)?
|
||||
Rule
|
||||
tree-root-value tree(V:T, _*:(trees(T))*) ~> V
|
||||
|
||||
|
||||
Funcon
|
||||
tree-branch-sequence(_:trees(T)) : =>(trees(T))*
|
||||
Rule
|
||||
tree-branch-sequence tree(_:T, B*:(trees(T))*) ~> B*
|
||||
|
||||
|
||||
Funcon
|
||||
single-branching-sequence(_:trees(T)) : =>T+
|
||||
/*
|
||||
`single-branching-sequence B ` extracts the values in `B` starting from
|
||||
the root, provided that `B` is at most single-branching; otherwise it fails.
|
||||
*/
|
||||
Rule
|
||||
single-branching-sequence tree(V:T) ~> V
|
||||
Rule
|
||||
single-branching-sequence tree(V:T, B:trees(T))
|
||||
~> left-to-right( V, single-branching-sequence B)
|
||||
Rule
|
||||
single-branching-sequence tree(_:T, _:trees(T), _+:(trees(T))+) ~> fail
|
||||
|
||||
|
||||
/*
|
||||
A sequence of trees corresponds to a forest, and the selector funcons
|
||||
on trees `B` extend to forests `B*`:
|
||||
*/
|
||||
|
||||
Funcon
|
||||
forest-root-value-sequence(_:(trees(T))*) : =>T*
|
||||
Rule
|
||||
forest-root-value-sequence(B:trees(T), B*:(trees(T))*)
|
||||
~>(tree-root-value B , forest-root-value-sequence B*)
|
||||
Rule
|
||||
forest-root-value-sequence( ) ~>( )
|
||||
|
||||
|
||||
Funcon
|
||||
forest-branch-sequence(_:(trees(T))*) : =>T*
|
||||
Rule
|
||||
forest-branch-sequence(B:trees(T), B*:(trees(T))*)
|
||||
~>(tree-branch-sequence B , forest-branch-sequence B*)
|
||||
Rule
|
||||
forest-branch-sequence( ) ~>( )
|
||||
|
||||
|
||||
Funcon
|
||||
forest-value-sequence(_:(trees(T))*) : =>T*
|
||||
/*
|
||||
`forest-value-sequence B*` provides the values from a left-to-right pre-order
|
||||
depth-first traversal.
|
||||
*/
|
||||
Rule
|
||||
forest-value-sequence(tree(V:T, B1*:(trees(T))*), B2*:(trees(T))*)
|
||||
~>(V , forest-value-sequence B1*, forest-value-sequence B2*)
|
||||
Rule
|
||||
forest-value-sequence( ) ~>( )
|
||||
|
||||
|
||||
/*
|
||||
Other linearizations of trees can be added: breadth-first, right-to-left,
|
||||
C3, etc.
|
||||
*/
|
||||
130
IBAF-cbs/Funcons-beta/Values/Composite/Trees/index.md
Normal file
130
IBAF-cbs/Funcons-beta/Values/Composite/Trees/index.md
Normal file
@@ -0,0 +1,130 @@
|
||||
---
|
||||
layout: default
|
||||
title: "Trees"
|
||||
parent: Composite
|
||||
ancestor: Funcons-beta
|
||||
|
||||
---
|
||||
|
||||
[Funcons-beta] : [Trees.cbs]
|
||||
-----------------------------
|
||||
|
||||
### Trees
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code>[
|
||||
<i class="keyword">Datatype</i> <span class="name"><a href="#Name_trees">trees</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_tree">tree</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_tree-root-value">tree-root-value</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_tree-branch-sequence">tree-branch-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_forest-root-value-sequence">forest-root-value-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_forest-branch-sequence">forest-branch-sequence</a></span>
|
||||
<i class="keyword">Funcon</i> <span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</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_trees">trees</span></span>(<span id="Variable60_T"><i class="var">T</i></span>) ::= <span id="Name_tree">tree</span>( _:<span id="Variable76_T"><i class="var">T</i></span>, _:(<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable88_T"><i class="var">T</i></span>))<sup class="sup">*</sup>)</code></pre></div>
|
||||
|
||||
|
||||
<code><span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>)</code> consists of finitely-branching trees with elements of type <code><i class="var">T</i></code>.
|
||||
When <code><i class="var">V</i>:<i class="var">T</i></code>, <code><span class="name"><a href="#Name_tree">tree</a></span>(<i class="var">V</i>)</code> is a leaf, and <code><span class="name"><a href="#Name_tree">tree</a></span>(<i class="var">V</i>,<i class="var">B<sub class="sub">1</sub></i>,...,<i class="var">Bn</i>)</code> is a tree with
|
||||
branches <code><i class="var">B<sub class="sub">1</sub></i></code>, ..., <code><i class="var">Bn</i></code>.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_tree-root-value">tree-root-value</span></span>(_:<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable269_T"><i class="var">T</i></span>)) : =>(<span id="Variable289_T"><i class="var">T</i></span>)<sup class="sup">?</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_tree-root-value">tree-root-value</a></span> <span class="name"><a href="#Name_tree">tree</a></span>(<span id="Variable306_V"><i class="var">V</i></span>:<i class="var">T</i>, _*:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>) ~> <a href="#Variable306_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_tree-branch-sequence">tree-branch-sequence</span></span>(_:<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable363_T"><i class="var">T</i></span>)) : =>(<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable384_T"><i class="var">T</i></span>))<sup class="sup">*</sup>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_tree-branch-sequence">tree-branch-sequence</a></span> <span class="name"><a href="#Name_tree">tree</a></span>(_:<i class="var">T</i>, <span id="Variable418_B*"><i class="var">B<sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>) ~> <a href="#Variable418_B*"><i class="var">B<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_single-branching-sequence">single-branching-sequence</span></span>(_:<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable465_T"><i class="var">T</i></span>)) : =><span id="Variable486_T+"><i class="var">T<sup class="sup">+</sup></i></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span> <i class="var">B</i></code> extracts the values in <code><i class="var">B</i></code> starting from
|
||||
the root, provided that <code><i class="var">B</i></code> is at most single-branching; otherwise it fails.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span> <span class="name"><a href="#Name_tree">tree</a></span>(<span id="Variable543_V"><i class="var">V</i></span>:<i class="var">T</i>) ~> <a href="#Variable543_V"><i class="var">V</i></a>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span> <span class="name"><a href="#Name_tree">tree</a></span>(<span id="Variable571_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable582_B"><i class="var">B</i></span>:<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))
|
||||
~> <span class="name"><a href="../../../Computations/Normal/Flowing/index.html#Name_left-to-right">left-to-right</a></span>( <a href="#Variable571_V"><i class="var">V</i></a>, <span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span> <a href="#Variable582_B"><i class="var">B</i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_single-branching-sequence">single-branching-sequence</a></span> <span class="name"><a href="#Name_tree">tree</a></span>(_:<i class="var">T</i>, _:<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>), _+:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">+</sup>) ~> <span class="name"><a href="../../../Computations/Abnormal/Failing/index.html#Name_fail">fail</a></span></code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
A sequence of trees corresponds to a forest, and the selector funcons
|
||||
on trees <code><i class="var">B</i></code> extend to forests <code><i class="var">B<sup class="sup">*</sup></i></code>:
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_forest-root-value-sequence">forest-root-value-sequence</span></span>(_:(<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable737_T"><i class="var">T</i></span>))<sup class="sup">*</sup>) : =><span id="Variable765_T*"><i class="var">T<sup class="sup">*</sup></i></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-root-value-sequence">forest-root-value-sequence</a></span>(<span id="Variable774_B"><i class="var">B</i></span>:<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>), <span id="Variable793_B*"><i class="var">B<sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>)
|
||||
~>(<span class="name"><a href="#Name_tree-root-value">tree-root-value</a></span> <a href="#Variable774_B"><i class="var">B</i></a> , <span class="name"><a href="#Name_forest-root-value-sequence">forest-root-value-sequence</a></span> <a href="#Variable793_B*"><i class="var">B<sup class="sup">*</sup></i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-root-value-sequence">forest-root-value-sequence</a></span>( ) ~>( )</code></pre></div>
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_forest-branch-sequence">forest-branch-sequence</span></span>(_:(<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable867_T"><i class="var">T</i></span>))<sup class="sup">*</sup>) : =><span id="Variable895_T*"><i class="var">T<sup class="sup">*</sup></i></span>
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-branch-sequence">forest-branch-sequence</a></span>(<span id="Variable904_B"><i class="var">B</i></span>:<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>), <span id="Variable923_B*"><i class="var">B<sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>)
|
||||
~>(<span class="name"><a href="#Name_tree-branch-sequence">tree-branch-sequence</a></span> <a href="#Variable904_B"><i class="var">B</i></a> , <span class="name"><a href="#Name_forest-branch-sequence">forest-branch-sequence</a></span> <a href="#Variable923_B*"><i class="var">B<sup class="sup">*</sup></i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-branch-sequence">forest-branch-sequence</a></span>( ) ~>( )</code></pre></div>
|
||||
|
||||
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Funcon</i>
|
||||
<span class="name"><span id="Name_forest-value-sequence">forest-value-sequence</span></span>(_:(<span class="name"><a href="#Name_trees">trees</a></span>(<span id="Variable997_T"><i class="var">T</i></span>))<sup class="sup">*</sup>) : =><span id="Variable1025_T*"><i class="var">T<sup class="sup">*</sup></i></span></code></pre></div>
|
||||
|
||||
<code><span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</a></span> <i class="var">B<sup class="sup">*</sup></i></code> provides the values from a left-to-right pre-order
|
||||
depth-first traversal.
|
||||
|
||||
<div class="highlighter-rouge"><pre class="highlight"><code><i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</a></span>(<span class="name"><a href="#Name_tree">tree</a></span>(<span id="Variable1057_V"><i class="var">V</i></span>:<i class="var">T</i>, <span id="Variable1070_B1*"><i class="var">B<sub class="sub">1</sub><sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>), <span id="Variable1104_B2*"><i class="var">B<sub class="sub">2</sub><sup class="sup">*</sup></i></span>:(<span class="name"><a href="#Name_trees">trees</a></span>(<i class="var">T</i>))<sup class="sup">*</sup>)
|
||||
~>(<a href="#Variable1057_V"><i class="var">V</i></a> , <span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</a></span> <a href="#Variable1070_B1*"><i class="var">B<sub class="sub">1</sub><sup class="sup">*</sup></i></a>, <span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</a></span> <a href="#Variable1104_B2*"><i class="var">B<sub class="sub">2</sub><sup class="sup">*</sup></i></a>)
|
||||
<i class="keyword">Rule</i>
|
||||
<span class="name"><a href="#Name_forest-value-sequence">forest-value-sequence</a></span>( ) ~>( )</code></pre></div>
|
||||
|
||||
|
||||
|
||||
|
||||
Other linearizations of trees can be added: breadth-first, right-to-left,
|
||||
C3, etc.
|
||||
|
||||
|
||||
|
||||
____
|
||||
|
||||
From the [PLanCompS Project] | [CBS-beta issues...] | [Suggest an improvement...]
|
||||
|
||||
[Trees.cbs]: Trees.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/Composite/Trees/Trees.cbs%0A%0AComment/Query/Issue/Suggestion%3A%0A%0A%0ASignature%3A%0A
|
||||
"GENERATE AN EMAIL TEMPLATE"
|
||||
@@ -0,0 +1,20 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print [forest-branch-sequence
|
||||
(tree(1),
|
||||
tree(2,tree(3)),
|
||||
tree(4),
|
||||
tree(5,tree(6),tree(7)))
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[tree(3),tree(6),tree(7)]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print [forest-root-value-sequence
|
||||
(tree(1),
|
||||
tree(2,tree(3)),
|
||||
tree(4),
|
||||
tree(5,tree(6),tree(7)))
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[1,2,4,5]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print [forest-value-sequence
|
||||
(tree(1),
|
||||
tree(2,tree(3)),
|
||||
tree(4),
|
||||
tree(5,tree(6),tree(7)))
|
||||
]
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[1,2,3,4,5,6,7]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print [single-branching-sequence tree(1)],
|
||||
print [single-branching-sequence tree(1,tree(2,tree(3)))],
|
||||
else(
|
||||
print [single-branching-sequence tree(1,tree(2),tree(3))],
|
||||
print [single-branching-sequence tree(1,tree(2,tree(3,tree(4),tree(5))))],
|
||||
print "OK")
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
[1],
|
||||
[1,2,3],
|
||||
"OK"
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
general {
|
||||
funcon-term:
|
||||
initialise-giving finalise-failing
|
||||
sequential (
|
||||
print tree-branch-sequence
|
||||
tree(1,tree(2,tree(3)),tree(4),tree(5,tree(6),tree(7)))
|
||||
)
|
||||
;
|
||||
}
|
||||
|
||||
tests {
|
||||
result-term: null-value;
|
||||
standard-out: [
|
||||
tree(2,tree(3)), tree(4), tree(5,tree(6),tree(7))
|
||||
];
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user