5 ms·
> 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
by jhgb 5y ago
> 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).
- dan-robertson 5y agoCommon 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 5y agoI don’t understand how to construct cyclic references using only letrec. Do you have a concrete example?
- JonChesterfield 5y agoIt 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 5y agoOh, 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.