User Tools

Site Tools


groimp-platform:xl-lambda

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
groimp-platform:xl-lambda [2024/05/06 12:05] – [custom rules] TimObgroimp-platform:xl-lambda [2025/01/24 08:12] (current) – [In-line Lambda functions] Tim
Line 1: Line 1:
 +====== XL Lambda function ======
 +
 +
 Since the java version used in GroIMP does not yet support the java lambda functions, GroIMP comes with a set of own lambda functions. Since the java version used in GroIMP does not yet support the java lambda functions, GroIMP comes with a set of own lambda functions.
 A Lambda function or anonymous function is a function that is not connected to an identifier and can be handled like a variable.  A Lambda function or anonymous function is a function that is not connected to an identifier and can be handled like a variable. 
Line 33: Line 36:
 </code> </code>
  
-====== custom rules ======+===== custom rules =====
  
 By using a Object function (eg. ObjectToFloat, BooleanToObject, ObjectToObject) the object can be more specifically defined in the function. By using a Object function (eg. ObjectToFloat, BooleanToObject, ObjectToObject) the object can be more specifically defined in the function.
Line 59: Line 62:
 </code> </code>
  
-====== Generators ======+===== Generators =====
  
 Moreover it is possible to create lambda functions that return series of values.  Moreover it is possible to create lambda functions that return series of values. 
Line 71: Line 74:
 </code> </code>
    
 +
 +===== In-line Lambda functions =====
 +
 +
 +In RGG, for Java as well as XL blocks it is possible to combine several expressions in one expression, using brackets and separating them by comma. The expressions will then be executed in order from left to right, and the last one on the right defines the return value of the surrounding lambda expression.
 +
 +An expression can be almost any feature of RGG:
 +  * Variable declaration
 +  * Variable assignment/change
 +  * XL context query
 +  * Java/RGG functions
 +  * Ternary conditional operator
 +
 +==== Variable handling ====
 +
 +A simple example for a in-line lambda is the combination of several mathematical steps in one expression would be the following, which sets the value if a to 6.
 +<code java>
 +int a = (int i=1,i++,i*3);
 +</code> 
 +The variable i stays in the scope of the lambda expression and can be used by the two following expressions but not outside of the brackets. 
 +
 +==== XL Context queries ====
 +
 +XL context queries e.g. ''%%(*F*)%%'' (loop over all F) can be used either access a field of each of the queried nodes directly (e.g. ''%%(*F*).length%%'') or to create query variables (e.g. ''%%(*f:F*)%%'').
 +
 +For example ''%%((*f:F*),f.length/f.diameter)%%'' would loop over each F and return the ratio of length to diameter. The result can then be used the same way as ''%%(*F*).length%%'', e.g. with the [[groimp-platform:xl-builtin-methods|Analytical Operators]].
 +
 +It is also possible to create several query variables, here for the average change in length from one F to the next F:
 +<code java>
 +float m =mean(((*f1:F > f2:F*),f2.length/f1.length));
 +</code>
 +
 +
 +This can be combined with any other expression, yet it is important to keep in mind that the expressions on the right of the context query are repeated for each found pattern!
 +Therefore ''%%(int i=0,i++,(*F*),i*=2)%%'' and ''%%(int i=0,(*F*),i++,i*=2)%%'' would have different values, because in the first one ''i++'' is only called once and in the second one its called for every F in the scene.
 +
 +==== Ternary conditional operator ====
 +
 +An Ternary conditional operator is in simple terms a inline if else expression, using the following syntax  to write for instance: if x then b else c with  ''a ? b : c''. With a being a boolean condition and b and c being expressions.  
 +
 +
  
groimp-platform/xl-lambda.1714989927.txt.gz · Last modified: 2024/05/06 12:05 by TimOb