[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: comprehensions

This page is part of the web mail archives of SRFI 40 from before July 7th, 2015. The new archives for SRFI 40 contain all messages, not just those from before July 7th, 2015.



On Friday, July 18, 2003 10:34 AM, Taylor Campbell [SMTP:campbell@xxxxxxxxxxxx] wrote:
> Are there any plans to make STREAM-OF a little more consistent with SRFI 42? --
> while SRFI 42 is _Eager_ Comprehensions and STREAM-OF is a _lazy_ comprehension,
> and it is stated somewhere in the SRFI 42 document that the methods used were
> quite different, they do seem like they should have at least something in common
> -- e.g., have the same general form -- (stream-of outer inner expr) --, or have
> a similar sort of mechanism for defining new generators on STREAM-OF as 
> in SRFI 42, or something?

I chose (stream-of expr outer inner) for its similarity to Haskell.  Dr Egner chose
(stream-of outer inner expr) because it makes the scope of variables flow from left
to right -- variables bound in outer are available in inner, and variables bound in both
outer and inner are available in expr.  I don't think either reason is particularly
compelling.  I do think the semantics of streams and SRFI 42 are sufficiently
different that it doesn't matter if their syntax is the same or not.  Does anyone
have any particularly strong feelings about the subject?

SRFI 42 required a mechanism for defining new generators as part of its basic
promise of efficient execution, which Egner was able to hide in a rather complex
set of macros.  Streams have no such need, since the closures, delays and
garbage collection implicit in streams will always have a fairly high run-time
cost; instead, the user can just write a function returning a stream, and use that
as a stream-of generator.  Thus, I do not anticipate adding a mechanism for
defining generators to stream-of as in SRFI 42.

The question that you didn't raise is whether the 'in' and 'is' keywords should be
prefix or infix.  I have been surprised that no one has raised this question.  I know
no reason to choose one or the other except for personal preference.  I do note
that Kent Dybvig, in section 9.3 of his book The Scheme Programming Language
(www.scheme.com/'tspl2ed.html), makes them infix.  Dybvig also uses the
(set-of expr outer inner) syntax.  Haskell uses infix '<-' instead of 'in' but prefix
'let' instead of infix 'is'.

You might also be interested in the generic comprehensions provided by Eli
Barzilay's Swindle system (www.barzilay.org/swindle), which use a somewhat
different syntax for user-defined generators and a completely different underlying
implementation than Egner.  Barzilay's syntax is (list-of expr outer inner), with
extensions; he uses '<-' as an infix keyword in place of 'in', and also provides
infix 'is', as well as several other possibilities.

Phil