sdmx-twg / vtl

This repository is used for maintaining the SDMX-VTL specification
11 stars 7 forks source link

Errors in Reference Manual #32

Closed stratosn closed 1 year ago

stratosn commented 7 years ago
reporter issue reference document (UM/RM/EBNF) page line
DI-21 RM 162 if-then-else p. 162
DI-22 RM 162 if-then-else p. 162

Keyword elseif is unnecessary. Construct else if does the trick without any syntactical complications with elseif, because after else one can put another if. Sub-expressions ds_1, ds_2 and ds_3 are incorrectly described as either datasets or constants. Any expression returning either a dataset or some other VTL 1.1 type (scalar, etc.) can be used. For instance, (a+4*b+c)/6 is a scalar expression which is perfectly valid to stand after then or else but is not a constant.

Expain what is the type of if A then B else C based on types of B and C.

capacma commented 7 years ago

I agree to eliminate elseif. NB: VTL defines if-then-else as an expression but in most programming languages if-then-else is a statement and not an expression. It would be wise to replace the if-then-else syntax with the "case" syntax that can be found in many programming languages: case when Condition then Expression { when Condition then Expression} * else Expression end

bellomarini commented 7 years ago

Independently of the syntax we choose, this conditional operator should remain an expression.

Since we are in a declarative language, we cannot have it exactly as a control flow control flow operator. However, I understand that a control-flow-like version is easy to understand and intuitive to many users, thus I would suggest the introduction of a pattern matching operator, syntactically more compact (yet semantically equivalent to the expression form of case-when) and used in functional languages, but "visually" resembling an imperative flow control structure.

An example follows:

DS1 =  match DS2 with:
| DS3 -> DS2*2 + DS3
| DS5 -> (DS2 + DS5) / 2
...

For all the datapoints of DS2 that have correspondences in DS3 (in terms of identifier components), return a Datapoint calculated by multiplying the measures by 2 and summed to DS3. For all the datapoints of DS2 that have correspondences in DS5, return (DS2 + DS5)/2 and so on.

Nested expressions in the pattern matching operator can give a "visual" idea of flow control, though remaining in the functional and declarative paradigm.

DS1  = match DS2 with:
   | DS3 -> match DS4 with:
       | DS5 -> DS4 + DS3
       | DS6 -> DS4 - DS3
   | DS2 -> match DS2 with:
      | DS7 ...