let
SKILL mode let(l_bindingsg_expr1... ) =>g_resultSKILL++ mode let( [s_var] ( (s_var1 s_initExp1) (s_var2 s_initExp2) ... ) body ) =>g_result
Description
In the SKILL mode, this function provides a faster alternative to prog for binding local variables only. This is a syntax form. In the SKILL++ mode, this function declares a lexical scope. This includes a collection of local variables, as well as body expressions to be evaluated. This becomes a named let if the optional s_var is given.
The SKILL mode argument l_bindings is either a list of variables or a list of the form (s_variable g_value). The bindings list is followed by one or more forms to be evaluated. The result of the let form is the value of the last g_expr.
let is preferable to prog in all circumstances where a single exit point is acceptable, and where the go and label constructs are not required.
Whereas, the functions, let, letseq, and letrec give SKILL++ a block structure. The syntax of the three constructs is similar, but they differ in the regions they establish for their variable bindings.
-
In a
letexpression, the initial values are computed before any of the variables become bound. -
In a
letseqexpression, the bindings and evaluations are performed sequentially. -
In a
letrecexpression, all the bindings are in effect while their initial values are being computed, thus allowing mutually recursive definitions.
Use the let form to declare a collection of local variables. You can provide an initialization expression for each variable. The order of evaluation of the initialization expressions is unspecified. Each variable has the body of the let expression as its lexical scope. This means that the initialization expressions should not cross-references to the other local variables.
In SKILL++ mode, local defines can appear at the beginning of the body of a let, letseq, or letrec form.
Arguments
Value Returned
Examples
The following example describes the use of the let function in the SKILL mode.
x = 5
let( ((x '(a b c)) y)
println( y ) ; Prints nil.
x)
=> (a b c) ; Returns the value of x.
procedure( test( x y )
let( ((x 6) (z "return string"))
if( (equal x y)
then z
else nil)))
test( 8 6 ) ; Call function test.
=> "return string" ; z is returned because 6 == 6.
The following example describes the use of the let function in the SKILL++ mode.
let( ( ( x 2 ) ( y 3 ) )
x*y
)
=> 6
let( ( ( x 2 ) ( y 3 ) )
let( (( z 4 ))
x + y + z
) ; let
) ; let
=> 9
let( ( ( x 2 ) ( y 3 ) )
let( (( x 7 ) ( foo lambda( ( z ) x + y + z ) ) )
foo( 5 )
) ; let
) ; let
=> 10 ;not 15
let( ((x 2) (y 3))
define( f(z) x*z+y)
f(5)
)
=> 13
Related Topics
Function and Program Structure
Return to top