Skip to content

Latest commit

 

History

History
5 lines (3 loc) · 2.19 KB

File metadata and controls

5 lines (3 loc) · 2.19 KB

Bindings and Scope: SETQ, LET, and LET*

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.

FormScopeExampleComments by Line Number
SETQGlobal Binding
  1. (SETQ TEMP1 (IPLUS 5 5))
  2. (SETQ RESULT (ITIMES 2 TEMP1))
  3. (SETQ GLOBAL.VALUE TEMP1)



  4. 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).
LETLocal, Parallel Binding
  1. (LET ((TEMP1 (IPLUS 5 5))
  2. (RESULT 20))
  3. (SETQ GLOBAL.VALUE TEMP1)


  4. (ITIMES RESULT 2))
  1. Local bindings: TEMP1 = 10
  2. RESULT = 20 (Evaluated in parallel. Cannot use TEMP1 here.)
  3. Global value of GLOBAL.VALUE set to 10.
  4. Returns (ITIMES RESULT 2) = 40.
LET*Local, Sequential Binding
  1. (LET* ((TEMP1 (IPLUS 5 5))
  2. (RESULT (ITIMES 2 TEMP1)))
  3. (SETQ GLOBAL.VALUE TEMP1)



  4. RESULT)
  1. Local binding: TEMP1 = 10
  2. RESULT = (ITIMES 2 TEMP1) = 20
  3. Global value of GLOBAL.VALUE set to 10.
  4. Returns local RESULT = 20.