Constructor
new Declaration(symbols, bodyopt)
Construct a declaration. The first argument must be either the Symbol to be declared or an array of one or more Symbols to be declared. The optional final argument is the body of the declaration.
In mathematics, we often declare symbols with certain conditions, such as "Let $x$ be any real number greater than $N$." In that sentence, we are declaring a variable $x$ and imposing on it a two-part condition (a conjunction), that $x$ is a real number and it is greater than $N$. Thus the body of the declaration would be that mathematical expression, $x\in\mathbb{R}\wedge x>N$. Or it could be formulated as an Environment with two claims, which are $x\in\mathbb{R}$ and $x>N$.
However, it is also possible to declare symbols with no conditions attached, as in the mathematical statement "Let $x$ be arbitrary." So the body of a declaration is optional.
The resulting Declaration instance will have as its children list the list of symbols it declares followed by the body, if a body is present.
Parameters
-
symbols
Symbol
|Array.<Symbol>
Either a single Symbol instance or an array of Symbol instances. Note that this must be a Symbol in the sense of the class defined in this repository, rather than the standard JavaScript Symbol type. If a single symbol is passed, it will be treated as an array of just one symbol.
-
body
LogicConcept
<optional>
An optional body of the declaration, as described above. The body may be any LogicConcept. If a declaration comes with several assumptions about the declared variables, they can be placed inside an Environment to conjoin them.
Source
Classes
Methods
body() → {LogicConcept|undefined}
Returns the body of this declaration. For an explanation of the meaning of a declaration body, see the documentation for the constructor.
In those cases where the Declaration has a body, it will also be the Declaration's last child. Declarations that were not constructed with a body will have a simple placeholder object as their last child, a symbol indicating where the body would go if there were one. For such Declarations, this function returns undefined.
See
- symbols()
- replaceBody()
Returns
-
LogicConcept
undefined
The body provided to this object at construction time, if there was one, or undefined if not. If there was one, it is guaranteed to be an instance of the LogicConcept class.
Source
copy() → {Declaration}
We override here the default copy() method for LogicConcepts because that method assumes that the arguments the constructor requires are the LogicConcept's children. But in this case, we may need to collect several children into an array, passed as the first parameter.
See
- copy()
- equals()
Returns
-
Declaration
a structural copy of this object
Source
removeBody()
Remove the body of this Declaration, if there is one, replacing it with a placeholder indicating that the Declaration now has no body. Thereafter, calling body() will return undefined.
Source
setBody()
Set a new body for this Declaration, replacing any old body that it had before (or, if it had none, replacing the placeholder that sits where a body would go). Thereafter, calling body() will return the new body provided to this function.
See
Source
symbols() → {Array.<Symbol>}
Return the array of Symbols provided to this object at construction time. This will be of length at least one, since the constructor requires there to be at least one symbol. The only exception to this rule is that Declarations, once constructed, can be modified by removing their children, so one could theoretically remove all symbols from a Declaration, putting it into an invalid form, so clients of this class should not do so.
See
Returns
-
Array.<Symbol>
An array of Symbol instances, those symbols being declared by this object