In search of feedback for the use of functions as promisers

14 views
Skip to first unread message

Nick Anderson

unread,
Aug 25, 2016, 1:53:41 PM8/25/16
to help-cfengine, dev-cfengine
In an attempt to minimize the number of intermediary variables that
get created when transforming strings Ted [originally proposed]
special string escapes.

- `$(~var)' to canonify a variable
- `$(\var)' to escape a variable
- `$((3+2))' to do math inline bash-style, formatting as integer if
the result is close enough to an integer

,----
| bundle agent main
| {
| vars:
| "var1" string => "value needs transformed";
|
| "$(~var1)" string => "$(var1)"; # Would define
value_needs_transformed with
| # the value of var1
|
| reports:
| "$(~var1)"; # Should report 'value_needs_transformed'
| "$((3+2))"; # Should report '5'
| "$(\var1)"; # Should report 'value\ needs\ transformed'
| }
`----

Alternatively:

- `$(:escape:var)' or `$(escape(var))', to escape a variable.
- `$(:canonify:var)' `$(canonify(var))' to canonify a variable.
- `$(:eval:2+2)' or `$(eval(2+2))' to do math inline.

These alternates were considered easier to read however generally the
special string escapes were disliked by the core developers who
support better function nesting and the use of a function as a
promiser.

[https://tracker.mender.io/browse/CFE-1092] is open to track the use
of functions for any string in the CFEngine policy, and a [pull
request] is currently open to allow functions to be used as promisers.

,----
| bundle agent example
| {
| vars:
| "iter" slist => { "1", "2", "3" };
|
| # This promise should define 'promiser_addition' as an empty string.
| canonify(concat("promiser ", canonify("addition"))) string => "";
|
| # This promise should define 'clean' as an empty string.
| canonify("clean") string => "";
|
| # This promise should define 'my_name_is_canonified' as an empty
string.
| canonify("my name is canonified") string => "";
|
| # This promise should define 'iter_canon_1' with the string
value 'iter =
| # 1', 'iter_canon_2' with the string value 'iter = 2', and
'iter_canon_3'
| # with the string value 'iter = 3'
| concat("iter_canon_", canonify($(iter))) string => "iter = $(iter)";
| }
`----

Some discussion has taken place in
[https://tracker.mender.io/browse/CFE-1092] regarding the use of
functions for any string in the CFEngine policy but no decision or
concensus has been reached. There are some objections to readability
as well as the specific implementation details.

The community advisory board discussed the basic feature of being able
to use functions as promisers. Mike Svoboda, Neil Watson, Jonathan
Clarke, and Ted Zlatanov support the feature. Nick Anderson is on the
fence primarily concerned with readability. Eystein Stenberg and Bas
van der Vlies were not in attendance.

Especially because of the mixed support and because the feature is a
large language change we would like additional user feedback in
[https://tracker.mender.io/browse/CFE1092]. If you support the change
please add yourself as a watcher and vote for the issue. More
commentary in the ticket describing the reason for your support or
opposition is also welcome.


[originally proposed]
https://groups.google.com/forum/#!msg/dev-cfengine/kDt0tAAcUis/VCbdhqBj4HcJ

[pull request] https://github.com/cfengine/core/pull/2295


Thanks!

signature.asc
Reply all
Reply to author
Forward
0 new messages