Question: In Example 8.52 we noted that functional languages can safely use reference counts since the lack of an assignment statement prevents them from introducing circularity.
In Example 8.52 we noted that functional languages can safely use reference counts since the lack of an assignment statement prevents them from introducing circularity. This isn’t strictly true; constructs like the Lisp letrec can also be used to make cycles, so long as uses of circularly defined names are hidden inside lambda expressions in each definition:

Each of the functions a, b, and c contains a reference to the next:

How might you address this circularity without giving up on reference counts?
(define foo (lambda () (letrec ((a (lambda (f) (if f #\A b))) (b (lambda (f) (if f #\B c))) (c (lambda (f) (if f #\C a)))) a)))
Step by Step Solution
3.34 Rating (163 Votes )
There are 3 Steps involved in it
In a pure functional language data is immut... View full answer
Get step-by-step solutions from verified subject matter experts
