Lambda function - HiStructClient/femcad-doc GitHub Wiki

Lambda function

FemCad supports the creation of anonymous functions (i.e. functions that are not bound to a name), using a construct called "lambda". This is a very powerful concept that is often used in conjunction with typical functional concepts.

Lambda functions can have any number of arguments but only one expression. The expression is evaluated and returned. Lambda functions can be used wherever function objects are required. If the function is only used once, or a limited number of times, an anonymous function may be syntactically lighter than using a named function.

 function := argument => expression

example

PointsDifference := u,v => {X:=u.X-v.X, Y:=u.Y-v.Y, Z:=u.Z-v.Z}

which, when used for an array of points,

points := [ {X:=3, Y:=0, Z:= 0}, {X:=0, Y:=4, Z:=0} ]
difference := PointsDifference(points[0], points[1])

results in

difference := {X = 3, Y = -4, Z = 0}
⚠️ **GitHub.com Fallback** ⚠️