Product Documentation
Cadence SKILL Language Reference
Product Version IC23.1, November 2023

let

SKILL mode
let( 
l_bindings 
g_expr1 ... 
) 
=> g_result 
SKILL++ 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.

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

l_bindings

(SKILL mode) Local variable bindings, can either be bound to a value or nil (the default).

g_expr1

(SKILL mode) Any number of expressions.

s_var

(SKILL++ mode) When the optional s_var is given, this becomes a named let. A named let is just like an ordinary let except that s_var is bound within the body to a function whose formal arguments are the bound variables and whose body is body.

s_var1

(SKILL++ mode) Name of local variable. The variables are bound to fresh locations holding the result of evaluating the corresponding initExp.

s_initExp

(SKILL++ mode) Expression evaluated for the initial value. The initExps are evaluated in the current environment (in some unspecified order).

body

(SKILL++ mode) A sequence of one or more expressions. The expressions in (body) are evaluated sequentially in the extended environment. Each local variable binding has body as its scope.

Value Returned

g_result

The result of the last expression evaluated.

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

letrec

letseq


Return to top
 ⠀
X