On 22 October 2014 14:32, Fluid Dynamics <a2093...@trbvm.com> wrote: > On Wednesday, October 22, 2014 6:09:04 AM UTC-4, James Reeves wrote: >> >> >> No, I mean unrestricted uniform access. >> >> Clojure's laziness is restricted to seqs >> > > Not quite; there's also delay and force, and it's possible to use these to > construct other lazy data-structures. >
I'm not sure I'd consider a delay to be a lazy structure, at least not in the same way as a seq, because dereferencing is a very explicit operation, even with force. > and is guaranteed to always produce the same value for the same field. >> > > Nope: > > => (def foo (int-array [1 2 2 5 9 3])) > #'user/foo > => (def bar (seq foo)) > #'user/bar > => bar > (1 2 2 5 9 3) > => (aset foo 3 3) > 3 > => bar > (1 2 2 3 9 3) > Okay, I'll grant that Clojure has very few concrete guarantees, especially when interoperating with mutable Java structures. Often guarantees of correctness are traded for performance. However, this is clearly a side effect of performance concerns rather than something put in to give seqs mutability. That said, seqs still have their issues, even with their inherent >> restrictions. For instance, it's easy to accidentally hold onto the head of >> a seq, particularly if it's passed in as an argument to a function. For >> example: >> >> (defn print-seq [xs] >> (doseq [x xs] >> (println x))) >> > > Locals clearing should prevent head-holding in this case, since xs isn't > referenced after the doseq, shouldn't it? > I think you're right in this case. I ran into this issue a few months ago, and there was some combination of effects that caused the head to be retained. I remember it was counterintuitive. It might have involved destructuring. - James -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.