-
Notifications
You must be signed in to change notification settings - Fork 0
Lambda function
jpodval edited this page Sep 18, 2017
·
1 revision
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
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}
- Localisation
- Basics
- FemCAD workings
- Geometry
- Input
- Direct edit
- Analysis
- Output
-
Stories
- FAQ
- Stupid user mistakes
- How to discover speed issues in the code
- How to run script faster
- How to list evaluated variables
- How I got lost in graphical interface when dealing with labels
- How to create Bill of material
- How to deal with point transfer between UCS and LCS
- How to define input
- How to make output