Page Numbers: Yes X: 310 Y: 10.42" First Page: 1
Margins: Top: 1.0" Bottom: 1.5"
Heading:
3-LISP WORKING GUIDE#5: Replace
———————————————————————————————————————————
Issue #5:REPLACE
Description:The sole primitive operation with a structural field side effect should be REPLACE, which replaces a structure with one of the same category. Replacements would be limited to the constructible structural categories: rails, pairs, atoms, and closures. All other structure-changing operations can be done in terms of it. This will make it quite easy to consider a side-effect-free variant of 3-LISP.
Status:Almost resolved. Discussion hangs on two points: what should it return, and should atoms be included in the list of smashable categories?
Last Edited:September 20, 1982 (Jim des Rivières)
———————————————————————————————————————————
Some examples of how REPLACE would work:
1> (SET X ’[1])
1> (SET Y ’[2])
1> (= X Y)
=> $F
1> (REPLACE X Y)
; REPLACE makes the first structure
1> (= X Y)
; identical to the second.
=> $T
1> $X
; X’s old binding is nowhere to be
=> ’[2]
; found,
1> $Y
; but Y is still intact.
=> ’[2]
1> (REPLACE ’(A.B) ’(C.D)); REPLACE works on pairs,
1> (REPLACE (CCONS ’SIMPLE ’[] ’[] ’[])
; and closures,
(CCONS ’REFLECT ’[] ’[] ’[]))
1> (REPLACE ’A ’B)
; even atoms (perhaps).
1> ’A
=> ’B
; (or ’A, depending on theta.)
The standard pair and rail mutators can be defined as follows.
1> (define RPLACA; Make the structure y stand in the
(lambda simple [x y]
; CAR relationship to the pair x.
(replace x (pcons y (cdr x)))))
; No result.
1> (define RPLACD; Make the structure y stand in the
(lambda simple [x y]
; CDR relationship to the pair x.
(replace x (pcons (car x) y))))
; No result.
1> (define RPLACT; Make the structure y stand in the
(lambda simple [n x y]
; TAIL relationship to the nth
(replace (tail n x) y)))); tail of x. No result.
1> (define RPLACN; Make the structure y stand in the
(lambda simple [n x y]
; FIRST relationship to the (n-1)st
(replace (tail (- n 1) x) ; tail of the rail x. No result.
(prep y (tail n x)))))