diff --git a/doc/Expr.adoc b/doc/Expr.adoc index a9719b1..c2c4fcd 100644 --- a/doc/Expr.adoc +++ b/doc/Expr.adoc @@ -615,7 +615,10 @@ The table below shows all supported operators by decreasing priorities. |=== == Functions -Functions in _Expr_ are very similar to functions in many programming languages. +Functions in _Expr_ are very similar to functions available in many programming languages. Actually, _Expr_ supports two types of function, _expr-functions_ and _go-functions_. + +* _expr-functions_ are defined using _Expr_ syntax. They can be passed as arguments to other functions and can be returned from functions. Moreover, they bind themselves to the defining context, thus becoming closures. +* _go-functions_ are regular Golang functions callable from _Expr_ expressions. They are defined in Golang source file called _modules_ and compiled within the _Expr_ package. To make Golang functions available in _Expr_ contextes, it is required to _import_ the module within they are defined. 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 [blue]`@` it is possibile to export local definition to the calling context. diff --git a/doc/Expr.html b/doc/Expr.html index ca7acf1..eb19a09 100644 --- a/doc/Expr.html +++ b/doc/Expr.html @@ -1609,7 +1609,7 @@ These operators have a high priority, in particular higher than the operator

.

Infix

Dict item

-

dict "" anyany

+

dict "." anyany

INC

@@ -1834,7 +1834,17 @@ These operators have a high priority, in particular higher than the operator 6. Functions
-

Functions in Expr are very similar to functions in many programming languages.

+

Functions in Expr are very similar to functions available in many programming languages. Actually, Expr supports two types of function, expr-functions and go-functions.

+
+
+
    +
  • +

    expr-functions are defined using Expr syntax. They can be passed as arguments to other functions and can be returned from functions. Moreover, they bind themselves to the defining context, thus becoming closures.

    +
  • +
  • +

    go-functions are regular Golang functions callable from Expr expressions. They are defined in Golang source file called modules and compiled within the Expr package. To make Golang functions available in Expr contextes, it is required to import the module within they are defined.

    +
  • +

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.

@@ -1874,7 +1884,7 @@ These operators have a high priority, in particular higher than the operator diff --git a/t_func-string_test.go b/t_func-string_test.go index dd3ef26..874da9c 100644 --- a/t_func-string_test.go +++ b/t_func-string_test.go @@ -64,6 +64,6 @@ func TestFuncString(t *testing.T) { //t.Setenv("EXPR_PATH", ".") - // parserTestSpec(t, "Func", inputs, 69) + // parserTestSpec(t, section, inputs, 19) parserTest(t, section, inputs) } diff --git a/t_funcs_test.go b/t_funcs_test.go index d04ffa9..421013f 100644 --- a/t_funcs_test.go +++ b/t_funcs_test.go @@ -29,6 +29,7 @@ func TestFuncs(t *testing.T) { /* 15 */ {`f=func(x,n=2){x+n}; f(3)`, int64(5), nil}, /* 16 */ {`f=func(x,n=2,y){x+n}`, nil, errors.New(`[1:16] can't mix default and non-default parameters`)}, /* 17 */ {`f=func(x,n){1}; f(3,4,)`, nil, errors.New(`[1:24] expected "function-param-value", got ")"`)}, + // /* 18 */ {`f=func(a){a*2}`, nil, errors.New(`[1:24] expected "function-param-value", got ")"`)}, } // t.Setenv("EXPR_PATH", ".")