Doc: fractions and dictionaries
This commit is contained in:
+52
-2
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user