What is the result of the following?
eq? is pointer equality, and
equal? is a recursive
equal?of mutable values is nonsensical
Why do we use a box when implementing a cyclic data structure?
A box’s mutability allows us to continuously extend our data structure such that it behaves cyclically without creating a cycle.
A box’s I/O side effect (at least the “O” part) allows us to easily identify when we encounter a cycle.
A box’s mutability allows it to ultimately refer to itself via a cycle of pointers.
A box is particularly compatible with the “recursive function constructor” (the Y Combinator) which allows us to generate a cyclic data structure with ease.
We don’t use a box because it does not allow us to create a cycle of pointers.
We can’t use a box because of its lack of subtyping.
We have seen in the past Racket’s
let local binder, and an example
that shows how it respects lexical scope:
There is also
let* which is shorthand for nesting each binding at a
time as if it’s in its own
And last week we also added
letrec as a new kind of binder, one that
creates a recursive environment. Ignoring types, what would we get
let, so: ’(x= 2 y= 1)
let*, so: ’(x= 2 y= 2)
letrecshould always be used with function expressions (