From ec0963e26f64cc1235cb8d0e1ab7f014de65ab9d Mon Sep 17 00:00:00 2001 From: Celestino Amoroso Date: Wed, 19 Jun 2024 22:46:35 +0200 Subject: [PATCH] Doc: little changes --- doc/Expr.adoc | 135 ++++++++++++++++++++---------- doc/Expr.html | 226 ++++++++++++++++++++++++++++++++++---------------- 2 files changed, 243 insertions(+), 118 deletions(-) diff --git a/doc/Expr.adoc b/doc/Expr.adoc index b288ce4..2db393b 100644 --- a/doc/Expr.adoc +++ b/doc/Expr.adoc @@ -104,7 +104,7 @@ dev-expr -- Expressions calculator v1.10.0(build 14),2024/06/17 (celestino.amoro -p Print prefix form -t Print tree form <2> -v, --version Show program version ->>> +>>> ---- <1> Only available for single fraction values @@ -186,7 +186,7 @@ Value range: *-9223372036854775808* to *9223372036854775807* | [blue]`*` | _product_ | Multiply two values | [blue]`-1 * 2` -> -2 | [blue]`/` | _Division_ | Divide the left value by the right one^(*)^ | [blue]`-10 / 2` -> 5 | [blue]`%` | _Modulo_ | Remainder of the integer division | [blue]`5 % 2` -> 1 -|=== +|=== ^(*)^ See also the _float division_ [blue]`./` below. @@ -204,15 +204,20 @@ _dec-seq_ = _see-integer-literal-syntax_ .Examples `>>>` [blue]`1.0` + -[green]`1` + +[green]`1` + `>>>` [blue]`0.123` + -[green]`0.123` + +[green]`0.123` + `>>>` [blue]`4.5e+3` + -[green]`4500` + +[green]`4500` + `>>>` [blue]`4.5E-33` + -[green]`4.5e-33` + +[green]`4.5e-33` + `>>>` [blue]`4.5E-3` + -[green]`0.0045` + +[green]`0.0045` + `>>>` [blue]`4.5E10` + [green]`4.5e+10` @@ -242,35 +247,43 @@ _digit-seq_ = _see-integer-literal-syntax_ ==== .Examples -// [source,go] -// ---- `>>>` [blue]`1 | 2` + -[green]`1|2` + +[green]`1|2` + `>>>` [blue]`4|6` [gray]_// Fractions are always reduced to their lowest terms_ + -[green]`2|3` + +[green]`2|3` + `>>>` [blue]`1|2 + 2|3` + -[green]`7|6` + +[green]`7|6` + `>>>` [blue]`1|2 * 2|3` + -[green]`1|3` + +[green]`1|3` + `>>>` [blue]`1|2 / 1|3` + -[green]`3|2` + +[green]`3|2` + `>>>` [blue]`1|2 ./ 1|3` [gray]_// Force decimal division_ + -[green]`1.5` + +[green]`1.5` + `>>>` [blue]`-1|2` + -[green]`-1|2` + +[green]`-1|2` + `>>>` [blue]`1|-2` [gray]_// Invalid sign specification_ + -[red]_Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1_ + +[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. .Examples `>>>` [blue]`1|2 + 5` + -[green]`11|2` + +[green]`11|2` + `>>>` [blue]`4 - 1|2` + -[green]`7|2` + +[green]`7|2` + `>>>` [blue]`1.0 + 1|2` + [green]`1.5` @@ -281,12 +294,15 @@ Strings are character sequences enclosed between two double quote [blue]`"`. .Examples `>>>` [blue]`"I'm a string"` + -[green]`I'm a string` + +[green]`I'm a string` + `>>>` [blue]`"123abc?!"` + -[green]`123abc?!` + +[green]`123abc?!` + `>>>` [blue]`"123\nabc"` + [green]`123` + -[green]`abc` + +[green]`abc` + `>>>` [blue]`"123\tabc"` + [green]`123{nbsp}{nbsp}{nbsp}{nbsp}abc` @@ -307,25 +323,30 @@ The items of strings can be accessed using the square `[]` operator. .Item access syntax ==== -_item_ = _string-expr_ "**[**" _integer-expr_ "**]**" +*_item_* = _string-expr_ "**[**" _integer-expr_ "**]**" ==== .Sub-string syntax ==== -_sub-string_ = _string-expr_ "**[**" _integer-expr_ "**:**" _integer-expr_ "**]**" +*_sub-string_* = _string-expr_ "**[**" _integer-expr_ "**:**" _integer-expr_ "**]**" ==== .String examples `>>>` [blue]`s="abcd"` [gray]_// assign the string to variable s_ + -[green]`"abcd"` + +[green]`"abcd"` + `>>>` [blue]`s[1]` [gray]_// char at position 1 (starting from 0)_ + -[green]`"b"` + +[green]`"b"` + `>>>` [blue]`s.[-1]` [gray]_// char at position -1, the rightmost one_ + -[green]`"d"` + +[green]`"d"` + `>>>` [blue]`\#s` [gray]_// number of chars_ + -[gren]`4` + +[gren]`4` + `>>>` [blue]`#"abc"` [gray]_// number of chars_ + -[green]`3` + +[green]`3` + `>>>` [blue]`s[1:3]` [gray]_// chars from position 1 to position 3 excluded_ + [grean]`"bc"` @@ -432,7 +453,7 @@ Array's items can be accessed using the index `[]` operator. .Sub-array (or slice of array) syntax ==== -*_slice_* = _string-expr_ "**[**" _integer-expr_ "**:**" _integer-expr_ "**]**" +*_slice_* = _string-expr_ "**[**" _integer-expr_ "**:**" _integer-expr_ "**]**" ==== .Items of list @@ -457,10 +478,13 @@ Array's items can be accessed using the index `[]` operator. `>>>` [blue]`#list` + [green]`3` -`>>>` [blue]`index=2; ["a", "b", "c", "d"].index` + +`>>>` [blue]`index=2; ["a", "b", "c", "d"][index]` + [green]`c` +`>>>` [blue]`["a", "b", "c", "d"][2:]` + +[green]`["c", "d"]` + === Dictionaries The _dictionary_, or _dict_, data-type is set of pairs _key/value_. It is also known as _map_ or _associative array_. @@ -474,14 +498,11 @@ _empty-dict_ = "**{}**" + _non-empty-dict_ = "**{**" _key-scalar_ "**:**" _any-value_ {"**,**" _key-scalar_ "**:**" _any-value} "**}**" + ==== -.Examples -`>>>` [blue]`{1:"one", 2:"two"}` + -[green]`{1: "one", 2: "two"}` + -`>>>` [blue]`{"one":1, "two": 2}` + -[green]`{"one": 1, "two": 2}` + -`>>>` [blue]`{"sum":1+2+3, "prod":1*2*3}` + -[green]`{"sum": 6, "prod": 6}` +.Item access syntax +==== +*_item_* = _dict-expr_ "**[**" _key-expr_ "**]**" +==== .Dict operators [cols="^2,^2,4,5"] @@ -489,11 +510,27 @@ _non-empty-dict_ = "**{**" _key-scalar_ "**:**" _any-value_ {"**,**" _key-scalar | Symbol | Operation | Description | Examples | [blue]`+` | _Join_ | Joins two dicts | [blue]`{1:"one"}+{6:"six"}` -> _{1: "one", 6: "six"}_ -| [blue]`.` | _Dict item value_ | Item value of given key | [blue]`{"one":1, "two":2}."two"` -> _2_ +| [blue]`[]` | _Dict item value_ | Item value of given key | [blue]`{"one":1, "two":2}["two"]` -> _2_ | [blue]`in` | _Key in dict_ | True if key is in dict | [blue]`"one" in {"one":1, "two":2}` -> _true_ + [blue]`"six" in {"one":1, "two":2}` -> _false_ |=== +.Examples +`>>>` [blue]`{1:"one", 2:"two"}` + +[green]`{1: "one", 2: "two"}` + +`>>>` [blue]`{"one":1, "two": 2}` + +[green]`{"one": 1, "two": 2}` + +`>>>` [blue]`{"sum":1+2+3, "prod":1*2*3}` + +[green]`{"sum": 6, "prod": 6}` + +`>>>` [blue]`{"one":1, "two":2}["two"]` + +[green]`2` + +`>>>` [blue]`d={"one":1, "two":2}; d["six"]=6; d` + +[green]`{"two": 2, "one": 1, "six": 6}` + == Variables _Expr_, like most programming languages, supports variables. A variable is an identifier with an assigned value. Variables are stored in _contexts_. @@ -509,17 +546,23 @@ NOTE: The assign operator [blue]`=` returns the value assigned to the variable. .Examples `>>>` [blue]`a=1` + -[green]`1` + +[green]`1` + `>>>` [blue]`a_b=1+2` + -[green]`1+2` + +[green]`1+2` + `>>>` [blue]`a_b` + -[green]`3` + +[green]`3` + `>>>` [blue]`x = 5.2 * (9-3)` [gray]_// The assigned value has the approximation error typical of the float data-type_ + -[green]`31.200000000000003` + +[green]`31.200000000000003` + `>>>` [blue]`x = 1; y = 2*x` + -[green]`2` + +[green]`2` + `>>>` [blue]`_a=2` + -[red]`Parse Error: [1:2] unexpected token "_"` + +[red]`Parse Error: [1:2] unexpected token "_"` + `>>>` [blue]`1=2` + [red]`Parse Error: assign operator ("=") must be preceded by a variable` diff --git a/doc/Expr.html b/doc/Expr.html index ac4d953..14167a1 100644 --- a/doc/Expr.html +++ b/doc/Expr.html @@ -904,16 +904,26 @@ dev-expr -- Expressions calculator v1.10.0
Examples

>>> 1.0
-1
->>> 0.123
-0.123
->>> 4.5e+3
-4500
->>> 4.5E-33
-4.5e-33
->>> 4.5E-3
-0.0045
->>> 4.5E10
+1

+ +
+

>>> 0.123
+0.123

+
+
+

>>> 4.5e+3
+4500

+
+
+

>>> 4.5E-33
+4.5e-33

+
+
+

>>> 4.5E-3
+0.0045

+
+
+

>>> 4.5E10
4.5e+10

@@ -985,22 +995,38 @@ dev-expr -- Expressions calculator v1.10.0
Examples

>>> 1 | 2
-1|2
->>> 4|6 // Fractions are always reduced to their lowest terms
-2|3
->>> 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 // Invalid sign specification
-Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1
->>> 1|(-2)
+1|2

+ +
+

>>> 4|6 // Fractions are always reduced to their lowest terms
+2|3

+
+
+

>>> 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 // Invalid sign specification
+Eval Error: [1:3] infix operator "|" requires two non-nil operands, got 1

+
+
+

>>> 1|(-2)
-1|2

@@ -1009,10 +1035,14 @@ dev-expr -- Expressions calculator v1.10.0
Examples

>>> 1|2 + 5
-11|2
->>> 4 - 1|2
-7|2
->>> 1.0 + 1|2
+11|2

+
+
+

>>> 4 - 1|2
+7|2

+
+
+

>>> 1.0 + 1|2
1.5

@@ -1025,13 +1055,19 @@ dev-expr -- Expressions calculator v1.10.0
Examples

>>> "I’m a string"
-I’m a string
->>> "123abc?!"
-123abc?!
->>> "123\nabc"
+I’m a string

+ +
+

>>> "123abc?!"
+123abc?!

+
+
+

>>> "123\nabc"
123
-abc
->>> "123\tabc"
+abc

+
+
+

>>> "123\tabc"
123    abc

@@ -1076,7 +1112,7 @@ dev-expr -- Expressions calculator v1.10.0Example 4. Item access syntax
-

item = string-expr "[" integer-expr "]"

+

item = string-expr "[" integer-expr "]"

@@ -1084,23 +1120,33 @@ dev-expr -- Expressions calculator v1.10.0Example 5. Sub-string syntax
-

sub-string = string-expr "[" integer-expr ":" integer-expr "]"

+

sub-string = string-expr "[" integer-expr ":" integer-expr "]"

String examples

>>> s="abcd" // assign the string to variable s
-"abcd"
->>> s[1] // char at position 1 (starting from 0)
-"b"
->>> s.[-1] // char at position -1, the rightmost one
-"d"
->>> #s // number of chars
-4
->>> #"abc" // number of chars
-3
->>> s[1:3] // chars from position 1 to position 3 excluded
+"abcd"

+
+
+

>>> s[1] // char at position 1 (starting from 0)
+"b"

+
+
+

>>> s.[-1] // char at position -1, the rightmost one
+"d"

+
+
+

>>> \#s // number of chars
+4

+
+
+

>>> #"abc" // number of chars
+3

+
+
+

>>> s[1:3] // chars from position 1 to position 3 excluded
"bc"

@@ -1395,9 +1441,13 @@ dev-expr -- Expressions calculator v1.10.03

-

>>> index=2; ["a", "b", "c", "d"].index
+

>>> index=2; ["a", "b", "c", "d"][index]
c

+
+

>>> ["a", "b", "c", "d"][2:]
+["c", "d"]

+

2.5. Dictionaries

@@ -1417,14 +1467,13 @@ dev-expr -- Expressions calculator v1.10.0 +
Example 10. Item access syntax
+
-
Examples
-

>>> {1:"one", 2:"two"}
-{1: "one", 2: "two"}
->>> {"one":1, "two": 2}
-{"one": 1, "two": 2}
->>> {"sum":1+2+3, "prod":1*2*3}
-{"sum": 6, "prod": 6}

+

item = dict-expr "[" key-expr "]"

+
+
@@ -1450,10 +1499,10 @@ dev-expr -- Expressions calculator v1.10.0

{1:"one"}+{6:"six"}{1: "one", 6: "six"}

- + - + @@ -1464,6 +1513,27 @@ dev-expr -- Expressions calculator v1.10.0 +
Examples
+

>>> {1:"one", 2:"two"}
+{1: "one", 2: "two"}

+ +
+

>>> {"one":1, "two": 2}
+{"one": 1, "two": 2}

+
+
+

>>> {"sum":1+2+3, "prod":1*2*3}
+{"sum": 6, "prod": 6}

+
+
+

>>> {"one":1, "two":2}["two"]
+2

+
+
+

>>> d={"one":1, "two":2}; d["six"]=6; d
+{"two": 2, "one": 1, "six": 6}

+
@@ -1474,7 +1544,7 @@ dev-expr -- Expressions calculator v1.10.0
Table 7. Dict operators

.

[]

Dict item value

Item value of given key

{"one":1, "two":2}."two"2

{"one":1, "two":2}["two"]2

in