{1:"one", 2:"two"}
+{"one":1, "two": 2}
+{"sum":1+2+3, "prod":1*2*3}
+From dce49fd2b7f369c884e4689b8f6d70096fea8207 Mon Sep 17 00:00:00 2001
From: Celestino Amoroso 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.