5 ms·
So it's a stream, not a list, because those have a length.
by nairboon 3y ago
So it's a stream, not a list, because those have a length.
- GrumpySloth 3y agoWhat length does a cyclical list have? (define l '(1 2 3)) (set-cdr! (cddr l) l)
- Tainnor 3y agoℵ₀
- ReleaseCandidat 3y agoAn infinite list has a length, it just happens to be (countable) infinite. Of course, as JS doesn't do (guaranteed) tail call optimisation, even finite lists will have "no length" ;) (and first rewriting `length` to be tail recursive (or using a loop with mutation): function length(l) { function go(l, acc) { if (l == null) { return acc; } else { return go(l.rest, acc + 1); } } return go(l, 0); }