Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ConstantElement.cs
1using System.Collections.Generic;
2using System.Threading.Tasks;
5
6namespace Waher.Script.Model
7{
12 {
13 private readonly IElement constant;
14
23 : base(Start, Length, Expression)
24 {
25 this.constant = Constant;
26 }
27
31 public IElement Constant => this.constant;
32
37 public override bool IsAsynchronous => false;
38
46 {
47 return this.constant;
48 }
49
56 public override Task<IElement> EvaluateAsync(Variables Variables)
57 {
58 return Task.FromResult<IElement>(this.constant);
59 }
60
67 public override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary<string, IElement> AlreadyFound)
68 {
69 return this.constant.Equals(CheckAgainst) ? PatternMatchResult.Match : PatternMatchResult.NoMatch;
70 }
71
78 public ScriptNode Differentiate(string VariableName, Variables Variables)
79 {
80 return new ConstantElement(DoubleNumber.ZeroElement, this.Start, this.Length, this.Expression);
81 }
82
86 public string DefaultVariableName => null;
87
89 public override bool Equals(object obj)
90 {
91 return obj is ConstantElement O &&
92 this.constant.Equals(O.constant) &&
93 base.Equals(obj);
94 }
95
97 public override int GetHashCode()
98 {
99 int Result = base.GetHashCode();
100 Result ^= Result << 5 ^ this.constant.GetHashCode();
101 return Result;
102 }
103 }
104}
Class managing a script expression.
Definition: Expression.cs:39
Represents a constant element value.
override PatternMatchResult PatternMatch(IElement CheckAgainst, Dictionary< string, IElement > AlreadyFound)
Performs a pattern match operation.
ConstantElement(IElement Constant, int Start, int Length, Expression Expression)
Represents a constant element value.
string DefaultVariableName
Default variable name, if any, null otherwise.
override bool Equals(object obj)
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
ScriptNode Differentiate(string VariableName, Variables Variables)
Differentiates a script node, if possible.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
override Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
IElement Constant
Constant value.
Base class for leaf nodes in a parsed script tree.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
static readonly DoubleNumber ZeroElement
0
Definition: DoubleNumber.cs:16
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
Base interface for lambda expressions.
PatternMatchResult
Status result of a pattern matching operation.
Definition: ScriptNode.cs:17