destructuringBind
destructuringBind( l_variablesl_expression[g_body] ) =>g_result
Description
Enables you to bind value to variables in a list. The list of values is obtained by evaluating the l_expression. The destructuringBind macro then evaluates the g_body form.
destructuringBind does not check the correctness of l_variables.
Arguments
Value Returned
Examples
-
Simple case:
(destructuringBind (a b) '(1 2) a+b )
=> 3
-
Complex case: assume
myBBox() returns ((0 0) (5 5))(destructuringBind (p1 p2) myBBox()
printf( "%L and %L points of a bounding box" p1 p2))
(0 0) and (5 5) points of a bounding box
=> t
(destructuringBind ((x1 y1) (x2 y2)) myBBox()
printf( "(%L %L) and (%L %L) points of a bounding box" x1 y1 x2 y2))
(0 0) and (5 5) points of a bounding box
=> t
-
Optional case
(destructuringBind (a b @optional (c 1)) '(1 2 5)
printf("a=%L b=%L c=%L\n" a b c) a+b )
a=1 b=2 c=5
=> 3
-
Keyword case: assume
myKeys() returns (100 ?key1 “Hello” ?key2 “World”)(destructuringBind (v1 @key key1 key2) myKeys()
printf( "Position value %L and key values %L %L" v1 k1 k2))
Position value 100 and key values "Hello" "World"
=> t
Related Topics
Function and Program Structure
Return to top