New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use functions for constraints in order to unify expression language #132
Comments
Feedback:
|
Instead of reusing $get_property, we can introduce a new TOSCA-path-aware function, $get_value (and then we don't need the special name "VAL"): Count1:
derived_from: integer
validation: { $greater_or_equal: [ { $get_value: [] }, 0 ] }
Count2:
derived_from: integer
validation: { $greater_or_equal: [ $VALUE, 0 ] }
FrequencyRange:
properties:
low:
type: scalar-unit.frequency
high:
type: scalar-unit.frequency
validation:
$greater_or_equal: [ { $get_value: [ high ] }, { $get_value: [ low ] } ] |
If we do decide that the shortcut is desireable then rather that it being '$VALUE' we should consider I'm not totally convinced the short cut is worth it. Would the following be valid and equivalent to the first example ?
|
We should consider making our function syntax more flexible, and adopt the following:
is the same as
is the same as
I think this would simplify function syntax without introducing additional parsing challenges. |
The propsal from @lauwers looks good but I have one question: If I were writing a custom function which took only one argument would I have to write it so that had the capability to accept |
Some input regarding what functions would be useful for both conditions and constraints and have them as supported by default (all of them boolean):
$forall: [equal, [el1, el2, ... eln], value]] $forall: [has_value, [el1, el2, ... eln], value]] Note1: we do not write equal with $ since we do not want to evaluate equal before evaluating forall Non-boolean: arithmetic functions: |
In today's ad hoc with proposed a general syntax for magic words in TOSCA, see issue #133. With that in mind we proposed that the function to use to retrieve the current value in constraint contexts be data_types:
# Full syntax with no arguments
Count1:
derived_from: integer
validation: { $greater_or_equal: [ { $value: [] }, 0 ] }
# Magic word
Count2:
derived_from: integer
validation: { $greater_or_equal: [ $value, 0 ] }
# Full syntax with arguments
FrequencyRange:
properties:
low:
type: scalar-unit.frequency
high:
type: scalar-unit.frequency
validation:
$greater_or_equal: [ { $value: [ high ] }, { $value: [ low ] } ] |
As I understand it a custom function could in principle also be called So in my experience, it is a good idea to reserve a namespace for TOSCA reserved words before anyone is using the custom functions feature. For example we could say that all reserved magic words must end in two underscores |
I believe the current spec makes it impossible to define a custom function with the same name as a built-in function, since such a function would be interpreted as a refinement/augmentation of the built-in function, not an entirely new function in its own right. My understanding is that refinements can only add implementations to existing function signatures, or append new function signatures. |
This is an important issue for us to consider -- what if you import two profiles in which each defines a function with the same name? @pmbruun has a point that perhaps functions should be namespaced, perhaps with the same ":" notation we use for types. e.g. something like |
Yes, I thought we had previously decided that function names are namespaced. Can you think of reasons why they shouldn't? |
This proposal has been accepted and is documented in Section 5.4.6 of https://docs.oasis-open.org/tosca/TOSCA/v2.0/csd05/TOSCA-v2.0-csd05.html. That section shows the use of the |
As discussed last week, here is a proposal for how it could look.
Three concepts are introduced:
validation
keyname (instead ofconstraints
) that is simply a boolean expression. It must evaluate to true for the value to be valid. Any expression can be used with any function with any degree of nesting.VAL
special name that refers to the current value, which can be used as the first argument in$get_property
likeSELF
,TARGET
, etc.$VAL
as a shortcut for{ $get_property: [ VAL ] }
Examples:
The text was updated successfully, but these errors were encountered: