Lurker News
Back to discussion

Comment by jhgb

jhgb3 replies#
> a let rec construction for data

Is there actually any Lisp dialect where letrec works for data? I'm not aware of such, at least where it comes to major ones (CL and common implementations of Scheme).

JonChesterfield1 reply#
It would need a lazy data constructor and the lisp ones are (usually) strict. If you make cons et al lazy then letrec on data works as it does in other languages. Alternatively, make letrec wrap the values in thunks. The resulting cyclic structures are then moderately annoying to work with.
jhgb#
Oh, I forgot lazy Lisps. But those would probably not be considered "major".

> Alternatively, make letrec wrap the values in thunks.
Aaaand of course I forgot that as well. My bad. So basically full lexical scoping and the presence of lambda should be enough to create cyclic structures, even in the absence of mutability.

dan-robertson#
Common Lisp let’s you write e.g.

  (list-length '#1=(1 2 3 4 . #1#))
But I think that isn’t what you mean.
dan-robertson#
I don’t understand how to construct cyclic references using only letrec. Do you have a concrete example?