Expr.doc: new Linked list type and review of iterators' operators

This commit is contained in:
2026-06-02 02:36:02 +02:00
parent 4b2b573420
commit 20cffbddfa
+22 -6
View File
@@ -480,7 +480,7 @@ TIP: `dev-expr` provides the _ctrl()_ function that allows to change this behavi
==== ====
=== Lists === Lists
_Expr_ supports list of mixed-type values, also specified by normal expressions. Internally, _Expr_'s lists are Go arrays. _Expr_ supports list of mixed-type values, also specified by normal expressions. Internally, _Expr_'s lists are Go slices.
.List literal syntax .List literal syntax
==== ====
@@ -585,7 +585,21 @@ Array's items can be accessed using the index `[]` operator.
`>>>` [blue]`[1,2,3,2,4] - [2,4]` + `>>>` [blue]`[1,2,3,2,4] - [2,4]` +
[green]`[1, 3]` [green]`[1, 3]`
=== Linked Lists
Linked lists are a special kind of lists that are used to represent sequences of items that can be easily modified. They are represented as lists of two items: the first item is the value of the current node, and the second item is the next node in the list. The last node in the list has a next node that is _nil_.
Internally,Expr's linked lists hold two pointers: one to the head of the list and one to the tail of the list. This allows for efficient insertion and deletion of items at both ends of the list. Also, linked lists keep track of their size, so the number of items in a linked list can be obtained in constant time.
.Linked List literal syntax
====
*_linked-list_* = "**[<**" [_item-expr_ {"**,**" _item-expr_}] "**>]**" +
_item-expr_ = _any-value_
====
`>>>` [blue]`ls=[<1,2,3,4>]` +
[green]`[<1, 2, 3, 4>]`
#to be completed#
=== Dictionaries === Dictionaries
The _dictionary_, or _dict_, data-type represents sets of pairs _key/value_. It is also known as _map_ or _associative array_. The _dictionary_, or _dict_, data-type represents sets of pairs _key/value_. It is also known as _map_ or _associative array_.
@@ -1709,6 +1723,8 @@ Returns a string obtained by converting all characters of the specified string t
`>>>` [blue]`strLower("Hello, world!")` + `>>>` [blue]`strLower("Hello, world!")` +
[green]`"hello, world!"` [green]`"hello, world!"`
== Iterators == Iterators
Iterators are objects that can be used to traverse collections, such as lists and dictionaries. They are created by providing a _data-source_ object, the collection, in a `$(<data-source>)` expression. Once an iterator is created, it can be used to access the elements of the collection one by one. Iterators are objects that can be used to traverse collections, such as lists and dictionaries. They are created by providing a _data-source_ object, the collection, in a `$(<data-source>)` expression. Once an iterator is created, it can be used to access the elements of the collection one by one.
@@ -1723,16 +1739,16 @@ _data-source_ = _explicit_ | _list-spec_ | _dict-spec_ | _custom-data-source_
_explicit_ = _any-expr_ { "**,**" _any-expr_ } _explicit_ = _any-expr_ { "**,**" _any-expr_ }
_list-spec_ = _list_ _range-options_ + _list-spec_ = _list_ ["**,**" _range-options_] +
_list_ = "**[**" _any-expr_ { "**,**" _any-expr_ } "**]**" + _list_ = "**[**" _any-expr_ { "**,**" _any-expr_ } "**]**" +
_range-options_ = [ "**,**" _start-index_ [ "**,**" _end-index_ [ "**,**" _step_ ]]] + _range-options_ = _start-index_ [ "**,**" _end-index_ [ "**,**" _step_ ]] +
_start-index_, _end-index_, _step_ = _integer-expr_ _start-index_, _end-index_, _step_ = _integer-expr_
_dict-spec_ = _dict_ _dict-options_ + _dict-spec_ = _dict_ ["**,**" _dict-options_] +
_dict_ = "**{**" _key-value-pair_ { "**,**" _key-value-pair_ } "**}**" + _dict_ = "**{**" _key-value-pair_ { "**,**" _key-value-pair_ } "**}**" +
_key-value-pair_ = _scalar-value_ "**:**" _any-expr_ + _key-value-pair_ = _scalar-value_ "**:**" _any-expr_ +
_scalar-value_ = _string_ | _number_ | _boolean_ + _scalar-value_ = _string_ | _number_ | _boolean_ +
_dict-options_ = [ "**,**" _sort-order_ [ "**,**" _iter-mode_ ] ] + _dict-options_ = _sort-order_ [ "**,**" _iter-mode_ ] +
_sort-order_ = _asc-order_ | _desc-order_ | _no-sort_ | _default-order_ + _sort-order_ = _asc-order_ | _desc-order_ | _no-sort_ | _default-order_ +
_asc-order_ = "**asc**" | "**a**" + _asc-order_ = "**asc**" | "**a**" +
_desc-order_ = "**desc**" | "**d**" + _desc-order_ = "**desc**" | "**d**" +
@@ -1810,7 +1826,7 @@ Negative steps are also allowed. They are interpreted as reverse iteration. For
The above example shows the use of the [blue]`{plusplus}` operator to get the next element of an iterator. The [blue]`{plusplus}` operator is a postfix operator that can be used with iterators. It returns the next element of the collection and updates the state of the iterator. When there are no more elements to iterate over, it returns the error [red]_Eval Error: EOF_. The above example shows the use of the [blue]`{plusplus}` operator to get the next element of an iterator. The [blue]`{plusplus}` operator is a postfix operator that can be used with iterators. It returns the next element of the collection and updates the state of the iterator. When there are no more elements to iterate over, it returns the error [red]_Eval Error: EOF_.
After the first use of the [blue]`{plusplus}` operator, the prefixed operato [blue]`{star}` operator can be used to get the current element of the collection without updating the state of the iterator. When there are no more elements to iterate over, it returns the error [red]_Eval Error: EOF_. Same error is returned if the [blue]`{star}` operator is used before the first use of the [blue]`{plusplus}` operator. After the first use of the [blue]`{plusplus}` operator, the prefixed operator [blue]`{star}` operator can be used to get the current element of the collection without updating the state of the iterator. When there are no more elements to iterate over, it returns the error [red]_Eval Error: EOF_. Same error is returned if the [blue]`{star}` operator is used before the first use of the [blue]`{plusplus}` operator.
.Example: using the [blue]`{star}` operator .Example: using the [blue]`{star}` operator
`>>>` [blue]`it = $(["one", "two", "three"])` + `>>>` [blue]`it = $(["one", "two", "three"])` +