letrec
letrec( ( (s_var1s_initExp1) (s_var2s_initExp2) ... )body) =>g_result
Description
(SKILL++ mode) A letrec expression can be used in SKILL++ mode only. All the bindings are in effect while their initial values are being computed, thus allowing mutually recursive definitions. Use letrec to declare recursive local functions.
Recursive let form. Each binding of a variable has the entire letrec expression as its scope, making it possible to define mutually recursive procedures.
Use letrec when you want to declare recursive local functions. Each initialization expression can refer to the other local variables being declared, with the following restriction: each initialization expression must be executable without accessing any of those variables.
For example, a lambda expression satisfies this restriction because its body gets executed only when called, not when it’s defined.
Arguments
Value Returned
Examples
The following example declares a single recursive local function. The local function f computes the factorial of its argument. The letrec expression returns the factorial of 5.
letrec(
( ;;; variable list
( f
lambda( ( n )
if( n > 0 then n*f(n-1) else 1
) ; if
) ; lambda
) ; f
) ; variable list
f( 5 )
) ; letrec
=> 120
Related Topics
Function and Program Structure
Return to top