You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Such function, would be a way to support locally scoped variables and have a return result. it could look something like this:
<variables>
<variableid="thing"scope="match"default="5"/>
<variableid="result"scope="match"/>
</variables>
<actions>
<!-- Defines a get-avg function, that takes in params `a` and `b`, with a local `tmp` variable, and a `res` result variable -->
<functionid="get-avg"param="a"param="b"local="tmp"result="res"scope="match">
<setvar="tmp"value="a" />
<setvar="tmp"value="tmp + b" />
<setvar="res"value="tmp/2" />
</function>
<callid="comp-avg"fn="get-avg"param="1"param="5"var="result"/>
</actions>
Note: the example is intentionally verbose, that comp-avg call could all be just a <set var="result" value="(1+5)/2"/>, and the get-avg function uses a tmp that it does not need at all.
Also note, while calls can be nested inside other actions, functions should remain always top-level definitions as they do nothing but just define a set of tasks by themselves, they have to be called to actually do anything, and can't be directly used as an action for a trigger or similar.
They are not to be actions at code level, because they have different semantics, they require parameters passed in, something being done with the result, etc. You can't just make a trigger take in an action="get-avg" because it'd make no sense. You'd make a trigger take comp-avg which is a call action, that calls the function with certain params and stores the result. This is similar to how a variable isn't an action, but set action can do things with the variable.
This is not an easy task, it's pretty challening to implement a new scope or variables (local function variables) and have them work with other expressions, but it's something that could help the current status-quo of needing everything to be a global variable due to the lack of a local scope.
The text was updated successfully, but these errors were encountered:
Pablete1234
changed the title
Implement a <function> action
Implement functions in pgm
Nov 4, 2023
Such function, would be a way to support locally scoped variables and have a return result. it could look something like this:
Note: the example is intentionally verbose, that
comp-avg
call could all be just a<set var="result" value="(1+5)/2"/>
, and theget-avg
function uses a tmp that it does not need at all.Also note, while
call
s can be nested inside other actions, functions should remain always top-level definitions as they do nothing but just define a set of tasks by themselves, they have to be called to actually do anything, and can't be directly used as an action for a trigger or similar.They are not to be actions at code level, because they have different semantics, they require parameters passed in, something being done with the result, etc. You can't just make a
trigger
take in anaction="get-avg"
because it'd make no sense. You'd make a trigger takecomp-avg
which is acall
action, that calls the function with certain params and stores the result. This is similar to how a variable isn't an action, butset
action can do things with the variable.This is not an easy task, it's pretty challening to implement a new scope or variables (local function variables) and have them work with other expressions, but it's something that could help the current status-quo of needing everything to be a global variable due to the lack of a local scope.
The text was updated successfully, but these errors were encountered: