Behavior and non-behavior #818
-
I keep getting stymied by these "Behavior function in a non-behavior property" errors as I am trying to build my own PFX implementation. In general, I get the idea: there are properties that expect an output and not an operation. and there are operations that expect actions (or behavior) and do not expect (or, at least, do not require) an output. But I am having a hard time wrapping my head around how the Eval method is determining which expressions are and are not non-behavior properties. Sometimes I get this error on statements as simple as "Set(avariable, 1)" and I find it hard to imagine how that could be seen as a "non-behavior property". Is there a reference page somewhere that can help me understand this? The core documentation wiki reads kinda like a CS textbook (no offense!) so it is hard to figure out what I am looking for there. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
A behavior function is a function that changes the value of a variable, or database table, or any other value that is somewhere previously stored. Most of Power Fx formulas (non-behavior) receive 0..N arguments, return a calculated value, and that's the end of it. The behavior function result, in the other hand, persists. Take a closer look at these two lines: line 29 line 37 |
Beta Was this translation helpful? Give feedback.
A behavior function is a function that changes the value of a variable, or database table, or any other value that is somewhere previously stored. Most of Power Fx formulas (non-behavior) receive 0..N arguments, return a calculated value, and that's the end of it. The behavior function result, in the other hand, persists.
Currently there are mainly 4 behavior functions: Set, Collect, Patch, and Remove.
To enable the behavior functions, you got to explicitly "tell" the engine to. Please check the following test cases:
https://github.com/microsoft/Power-Fx/blob/main/src/tests/Microsoft.PowerFx.Interpreter.Tests/MutationFunctionsTests.cs
Take a closer look at these two lines:
line 29
private…