Variable Bindings and Scope
In Interlisp, SETQ creates a persistent or global binding that keeps its value across computations. In contrast, LET and LET* create temporary, local variables that exist only within the current expression or function. LET evaluates and binds all variables in parallel, so none of them can refer to another defined in the same form. LET*, however, binds variables one at a time in sequence, allowing each new variable to use the values of those bound earlier, making it useful for stepwise calculations or dependent local values.
SETQ
Global Binding
(SETQ TEMP1 (IPLUS 5 5))(SETQ RESULT (ITIMES 2 TEMP1))(SETQ GLOBAL.VALUE TEMP1)RESULT
1. Global assignment: TEMP1 is now 10.
2. Global assignment: RESULT is now 20.
3. Global assignment: GLOBAL.VALUE is now 10.
4. Returns the current value of RESULT (20).
LET
Local, Parallel Binding
(LET ((TEMP1 (IPLUS 5 5))(RESULT 20))(SETQ GLOBAL.VALUE TEMP1)(ITIMES RESULT 2))
Local bindings:
TEMP1 = 10RESULT = 20(Evaluated in parallel. Cannot use TEMP1 here.)Global value of
GLOBAL.VALUEset to 10.Returns
(ITIMES RESULT 2)= 40.
LET*
Local, Sequential Binding
(LET* ((TEMP1 (IPLUS 5 5))(RESULT (ITIMES 2 TEMP1)))(SETQ GLOBAL.VALUE TEMP1)RESULT)
Local binding:
TEMP1 = 10RESULT = (ITIMES 2 TEMP1)= 20Global value of
GLOBAL.VALUEset to 10.Returns local
RESULT= 20.
Last updated
Was this helpful?
