Skip to content
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

Implement functions in pgm #1269

Open
Pablete1234 opened this issue Nov 4, 2023 · 0 comments
Open

Implement functions in pgm #1269

Pablete1234 opened this issue Nov 4, 2023 · 0 comments
Labels
discussion Just talking feature New feature or request

Comments

@Pablete1234
Copy link
Member

Pablete1234 commented 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:

<variables>
  <variable id="thing" scope="match" default="5"/>
  <variable id="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 -->
  <function id="get-avg" param="a" param="b" local="tmp" result="res" scope="match">
    <set var="tmp" value="a" />
    <set var="tmp" value="tmp + b" />
    <set var="res" value="tmp/2" />
  </function>

  <call id="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.

@Pablete1234 Pablete1234 changed the title Implement a <function> action Implement functions in pgm Nov 4, 2023
@Pablete1234 Pablete1234 added feature New feature or request discussion Just talking labels Nov 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Just talking feature New feature or request
Development

No branches or pull requests

1 participant