{1:"one", 2:"two"}
+{"one":1, "two": 2}
+{"sum":1+2+3, "prod":1*2*3}
+diff --git a/doc/Expr.adoc b/doc/Expr.adoc index fb3fa9e..ff6a06b 100644 --- a/doc/Expr.adoc +++ b/doc/Expr.adoc @@ -22,7 +22,7 @@ Expressions calculator toc::[] -#TODO: Work in progress (last update on 2024/05/07, 07:15 am)# +#TODO: Work in progress (last update on 2024/05/09, 07:17 am)# == Expr _Expr_ is a GO package capable of analysing, interpreting and calculating expressions. @@ -140,7 +140,44 @@ Numbers can be integers (GO int64) or float (GO float64). In mixed operations in |=== -=== String +=== Fractions +_Expr_ also suports fractions. Fraction literals are made with tow integers separated by a vertical bar `|`. + +.Examples +// [source,go] +// ---- +`>>>` [blue]`1 | 2` + +[green]`1|2` + +`>>>` [blue]`4|6` + +[green]`2|3` [gray]_Fractions are always reduced to theri lowest terms_ + +`>>>` [blue]`1|2 + 2|3` + +[green]`7|6` + +`>>>` [blue]`1|2 * 2|3` + +[green]`1|3` + +`>>>` [blue]`1|2 / 1|3` + +[green]`3|2` + +`>>>` [blue]`1|2 ./ 1|3` [gray]_Force decimal division_ + +[green]`1.5` + +`>>>` [blue]`-1|2` + +[green]`-1|2` + +`>>>` [blue]`1|-2` [gray]_Wrong sign specification_ + +[red]_Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1_ + +`>>>` [blue]`1|(-2)` + +[green]`-1|2` +// ---- + +Fractions can be used together with integers and floats in expressions. + +`>>>` [blue]`1|2 + 5` + +[green]`11|2` + +`>>>` [blue]`4 - 1|2` + +[green]`7|2` + +`>>>` [blue]`1.0 + 1|2` + +[green]`1.5` + + + + +=== Strings Strings are character sequences enclosed between two double quote [blue]`"`. Example: [blue]`"I'm a string"`. Some arithmetic operators can also be used with strings. @@ -232,6 +269,19 @@ _Expr_ supports list of mixed-type values, also specified by normal expressions. | [blue]`-` | _Difference_ | Left list without elements in the right list | [blue]`[1,2,3] - [2]` _[ [1,3] ]_ |=== +== Dictionaries +The _dictionary_ data-type is set of pairs _key/value_. It is also known as _map_ or _associative array_. Dictionary literals are sequences of pairs separated by comma `,`; sequences are enclosed between brace brackets. + +.List examples +[source,go] +---- +{1:"one", 2:"two"} +{"one":1, "two": 2} +{"sum":1+2+3, "prod":1*2*3} +---- + +WARNING: Support for dictionaries is still ongoing. + == Variables A variable is an identifier with an assigned value. Variables are stored in the object that implements the _ExprContext_ interface. diff --git a/doc/Expr.html b/doc/Expr.html index d770864..d0f9ed4 100644 --- a/doc/Expr.html +++ b/doc/Expr.html @@ -542,31 +542,33 @@ pre.rouge .ss {
TODO: Work in progress (last update on 2024/05/07, 07:15 am)
+TODO: Work in progress (last update on 2024/05/09, 07:17 am)
Expr also suports fractions. Fraction literals are made with tow integers separated by a vertical bar |
.
>>>
1 | 2
+1|2
+>>>
4|6
+2|3
Fractions are always reduced to theri lowest terms
+>>>
1|2 + 2|3
+7|6
+>>>
1|2 * 2|3
+1|3
+>>>
1|2 / 1|3
+3|2
+>>>
1|2 ./ 1|3
Force decimal division
+1.5
+>>>
-1|2
+-1|2
+>>>
1|-2
Wrong sign specification
+Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1
+>>>
1|(-2)
+-1|2
Fractions can be used together with integers and floats in expressions.
+>>>
1|2 + 5
+11|2
+>>>
4 - 1|2
+7|2
+>>>
1.0 + 1|2
+1.5
Strings are character sequences enclosed between two double quote "
. Example: "I’m a string"
.
Boolean data type has two values only: true and false. Relational and Boolean expressions produce Boolean values.
Expr supports list of mixed-type values, also specified by normal expressions.
The dictionary data-type is set of pairs key/value. It is also known as map or associative array. Dictionary literals are sequences of pairs separated by comma ,
; sequences are enclosed between brace brackets.
{1:"one", 2:"two"}
+{"one":1, "two": 2}
+{"sum":1+2+3, "prod":1*2*3}
++ + | ++Support for dictionaries is still ongoing. + | +
A variable is an identifier with an assigned value. Variables are stored in the object that implements the ExprContext interface.
@@ -1028,10 +1096,10 @@ Here are some examples of execution.;
operator;
operatorThe semicolon operator ;
is an infixed pseudo-operator. It evaluates the left expression first and then the right expression. The latter is the final result.
;
is not treated as a real operator. It ac
but
operatorbut
operatorbut
is an infixed operator. Its operands can be expressions of any type. It evaluates the left expression first, then the right expression. The value of the right expression is the final result. Examples: 5 but 2
returns 2, x=2*3 but x-1
returns 5.
;
is not treated as a real operator. It ac
=
=
The assignment operator =
is used to define variables in the evaluation context or to change their value (see ExprContext).
The value on the left side of =
must be an identifier. The value on the right side can be any expression and it becomes the result of the assignment operation.
=
must be an identifier.
? : ::
? : ::
The selector operator is very similar to the switch/case/default statement available in many programming languages.
=
must be an identifier.
The table below shows all supported operators by decreasing priorities.
@@ -1350,7 +1418,7 @@ The value on the left side of=
must be an identifier.
Functions in Expr are very similar to functions in many programming languages.
@@ -1359,13 +1427,13 @@ The value on the left side of=
must be an identifier.
In Expr functions compute values in a local context (scope) that do not make effects on the calling context. This is the normal behavior. Using the reference operator @
it is possibile to export local definition to the calling context.
TODO: function definitions operations
=
must be an identifier.
TODO: builtins
import(<source-file>) loads the multi-expression contained in the specified source and returns its value.
=
must be an identifier.