From 1322378975f8d6539b189a7e243e0420ff1c24c4 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Thu, 31 Jan 2019 16:45:01 -0600 Subject: [PATCH] DOCS: Update the docs with the new functional operator syntax. --- docsite/site/content/reference/expressions.md | 49 ++++++++++++++----- docsite/site/content/reference/grammar.md | 4 +- 2 files changed, 40 insertions(+), 13 deletions(-) diff --git a/docsite/site/content/reference/expressions.md b/docsite/site/content/reference/expressions.md index 3144458..7ee49da 100644 --- a/docsite/site/content/reference/expressions.md +++ b/docsite/site/content/reference/expressions.md @@ -330,7 +330,7 @@ Functional processing expressions UCG has a few functional processing expressions called `map`, `filter`, and `reduce`. All of them can process a string, list, or tuple. -Their syntax starts with either `map` `filter`, or `reduce followed by a symbol +Their syntax starts with either `map` `filter`, or `reduce` followed by a symbol that references a valid func and finally an expression that resolves to either a list or a tuple. @@ -339,7 +339,7 @@ a list or a tuple. Map functions should produce either a valid value or a list of [field, value] that will replace the element or field it is curently processing. -**For Lists** +**Lists** When mapping a function across a list the result field can be any valid value. The function is expected to take a single argument. @@ -348,10 +348,10 @@ function is expected to take a single argument. let list1 = [1, 2, 3, 4]; let mapper = func (item) => item + 1; -map mapper, list1 == [2, 3, 4, 5]; +map(mapper, list1) == [2, 3, 4, 5]; ``` -**For Tuples** +**Tuples** Functions for mapping across a tuple are expected to take two arguments. The first argument is the name of the field. The second argument is the value in that @@ -367,7 +367,16 @@ let tpl_mapper = func (name, val) => select name, [name, val], { "foo" = ["foo", "barbar"], quux = ["cute", "pygmy"], }; -map tpl_mapper, test_tpl == {foo = "barbar", cute = "pygmy"}; +map(tpl_mapper, test_tpl) == {foo = "barbar", cute = "pygmy"}; +``` + +**Strings** + +``` +let string = "foo"; +let string_mapper = func (item) => item + item; + +map(string_reducer, 0, string) == "ffoooo"; ``` ### Filter expressions @@ -384,7 +393,7 @@ let filtrator = func (item) => select item, NULL, { foo = item, }; -filter filtrator, list2 == ["foo", "foo"]; +filter(filtrator, list2) == ["foo", "foo"]; ``` **Tuples** @@ -395,14 +404,23 @@ let test_tpl = { quux = "baz", }; let tpl_filter = func (name, val) => name != "foo"; -filter tpl_filter, test_tpl == { quux = "baz" }; +filter(tpl_filter, test_tpl) == { quux = "baz" }; +``` + +**Strings** + +``` +let string = "foo"; +let string_filter = func (item) => item != "f"; + +filter(string_reducer, 0, string) == "oo"; ``` ### Reduce expressions Reduce expressions start with the reduce keyword followed by a symbol -referencing a func, an expression for the accumulator, and finally the tuple or -list to process. +referencing a func, an expression for the accumulator, and finally the tuple +list, or string to process. **Tuples** @@ -416,7 +434,7 @@ let tpl_reducer = func (acc, name, val) => acc{ vals = self.vals + [val], }; -reduce tpl_reducer, {keys = [], vals = []}, test_tpl == {keys = ["foo", "quux"], vals = ["bar", "baz"]}; +reduce(tpl_reducer, {keys = [], vals = []}, test_tpl) == {keys = ["foo", "quux"], vals = ["bar", "baz"]}; ``` **Lists** @@ -425,7 +443,16 @@ reduce tpl_reducer, {keys = [], vals = []}, test_tpl == {keys = ["foo", "quux"], let list1 = [1, 2, 3, 4]; let list_reducer = func (acc, item) => acc + item; -reduce list_reducer, 0, list1 == 0 + 1 + 2 + 3 + 4; +reduce(list_reducer, 0, list1) == 0 + 1 + 2 + 3 + 4; +``` + +**Strings** + +``` +let string = "foo"; +let string_reducer = func (acc, item) => acc + [item]; + +reduce(string_reducer, 0, string) == ["f", "o", "o"]; ``` Include expressions diff --git a/docsite/site/content/reference/grammar.md b/docsite/site/content/reference/grammar.md index f0ee1c5..409c57d 100644 --- a/docsite/site/content/reference/grammar.md +++ b/docsite/site/content/reference/grammar.md @@ -141,8 +141,8 @@ format_expr: str, percent, (format_arg_list | format_expr_arg) ; ``` func_op_kind: map_keyword | filter_keyword ; -map_or_filter_expr: func_op_kind, expr, expr ; -reduce_expr: reduce_keyword, expr, expr, expr ; +map_or_filter_expr: func_op_kind, lparen, expr, expr, rparen ; +reduce_expr: reduce_keyword, lparen, expr, expr, expr, rparen ; processing_expr: map_or_filter_expr | reduce_expr ```