[plt-scheme] v4 questions

From: Mark Engelberg (mark.engelberg at gmail.com)
Date: Mon Mar 31 00:26:44 EDT 2008

You are right that if you separate operations from data in your code,
and only expose a given interface, you can go through and make
whatever changes you want without affecting users of your code.  What
I'm talking about is the ease of actually going through and making
those changes.  Ideally, it should be easy to replace internal uses of
a list with internal uses of something like a list that sacrifices a
bit of speed on cons, first, and rest, in order to get faster
random-access, for example.

On Sun, Mar 30, 2008 at 8:08 PM, Eli Barzilay <eli at barzilay.org> wrote:
>  > The designers of Scala and F# probably have similar tastes to me in
>  > this regard, because these forms of laziness are offered by those
>  > languages.
>  (Any pointers with interaction examples?)

lazy keyword examples given in
http://www.scala-lang.org/docu/files/ScalaByExample.pdf, chapter 14.
Iterator is the class for streams of values that are recomputed each time.
Stream is the class for cached lazy lists.
Both work with the comprehension syntax.  (Scala's comprehension
syntax automatically determines the type of the output by the first
generator.  So if you generate from a list, you get a list.  If you
generate from a stream, you get a stream, etc.  Comprehension syntax
works for anything that implements the map,flatMap,filter interface.)
Scala probably comes closest to the ideal I mentioned of swappable
data structures.  Many data structures use the Seq interface:
so it's pretty easy to just change the constructor used to make your
data structure, and see how the performance changes.  Obviously, you
can't pass a list to something that explicitly demands a vector, but
the signature for many functions is that they just take something that
implements the seq interface, so there's lots of flexibility.  Most of
the data structures come in both mutable and immutable flavors.

seq is the class for streams of values that are recomputed each time.
LazyList is the class for streams of values that are cached.
When I searched just now on F#'s laziness, I realized I was wrong
about the implicit force when using F#'s lazy keyword.  You do need to
explicitly force the values.


Posted on the users mailing list.