From 5d9764dd698b147b3edacf440888857ea7c0dd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Mon, 18 Feb 2019 15:10:16 +0100 Subject: [PATCH] Added macro functions. Manually cherry-picked from cfee93b0809909f4da28c39ad1743abad27ae09a. --- src/source/the-model-file.rst | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/source/the-model-file.rst b/src/source/the-model-file.rst index 8d4f9b35e..cf544ea1d 100644 --- a/src/source/the-model-file.rst +++ b/src/source/the-model-file.rst @@ -10141,8 +10141,8 @@ Macro expressions It is possible to construct macro-expressions which can be assigned to macro-variables or used within a macro-directive. The expressions are -constructed using literals of the four basic types (integers, strings, -arrays of strings, arrays of integers), macro-variables names and +constructed using literals of five basic types (integers, strings, +arrays of strings, arrays of integers, and string functions), macro-variables names and standard operators. String literals have to be enclosed between **double** quotes (like @@ -10186,6 +10186,11 @@ The following operators can be used on arrays: ``1:length(["a", "b", "c"])`` is equivalent to integer array ``[1,2,3]``) +The following operators can be used on string functions: + + * Comparison operators: ``==``, ``!=`` + * Concatenation of two strings: ``+`` + Macro-expressions can be used at two places: * Inside macro directives, directly; @@ -10237,18 +10242,20 @@ Macro directives .. macrodir:: @#define MACRO_VARIABLE = MACRO_EXPRESSION - |br| Defines a macro-variable. + |br| Defines a macro-variable or macro function. *Example* :: - @#define x = 5 // Integer - @#define y = "US" // String - @#define v = [ 1, 2, 4 ] // Integer array - @#define w = [ "US", "EA" ] // String array - @#define z = 3 + v[2] // Equals 5 - @#define t = ("US" in w) // Equals 1 (true) + @#define x = 5 // Integer + @#define y = "US" // String + @#define v = [ 1, 2, 4 ] // Integer array + @#define w = [ "US", "EA" ] // String array + @#define z = 3 + v[2] // Equals 5 + @#define t = ("US" in w) // Equals 1 (true) + @#define f(x) = " + @{x} + @{y}" // Defines a function 'f' with argument 'x' + // that resturns the string ' + @{x} + US' *Example* @@ -10256,15 +10263,16 @@ Macro directives @#define x = [ "B", "C" ] @#define i = 2 + @#define f(x) = " + @{x}" model; - A = @{x[i]}; + A = @{x[i]+f("D")}; end; The latter is strictly equivalent to:: model; - A = C; + A = C + D; end;