[plt-scheme] for.ss

From: David Einstein (deinst at gmail.com)
Date: Thu Sep 20 14:58:08 EDT 2007

On 9/20/07, Jens Axel Søgaard <jensaxel at soegaard.net> wrote:
> David Einstein wrote:
> > I am glad to see that plt is considering including some comprehension
> > macros.  I realize that they are not yet final, but I have some
> comments.
> >
> > A) The behavior of in-range seems to have been inherited from srfi-42
> > and python.  In my opinion it is one of the few things that python gets
> > wrong.  If you assign problems 7 through 9 as homework to your students,
> > do you really expect them to hand back just problems 7 and 8?  (These
> > would be abstract ideal students.)
> ad A)
> Given a vector (or string or byte-string) v it common to iterate through
> the indices 0, 1, ... (- (vector-length v) 1). Convenience of the
> common case therefore dictates the last index in the range to be
> excluded.

Yes, but in this case you would just use the appropriate string or
byte-string sequence.  The  purpose of  comprehensions is to get away from

> D)  A 'for*/seq'  form that takes a set of nested sequences and
> > returns a generator for all the values of the nested would be useful.
> > I've been trying to get one integrated into Jens' srfi-42 rewrite
> > using William Farr's multiple value yield, but my macro skills are not
> > yet up to the task.
> ad D)
> Do you have an example of the intended behaviour?

 In terms of srfi-42 something the ability to do something like

(list-ec (:while [:nested (:range a 2 10) (:range b 1 a) (if (= 1 (gcd a
b)))] (< 7 (+ a b)) [list a b])

in terms of for.ss, something like

(for (stop-after [(a b) (for*/seq ((a1 [in-range 2 10])(b1 [in-range 1 a1])
#:when (= 1 [gcd a1 b1])) (yield a1 b1)] (< 7 (+ a b))) (list a b))

these should result in

'((2 1) (3 1) (3 2) (4 1))

essentially what I want is functionality similar to Java's labeled breaks.
Not something that you need often (unless you're doing Project Euler
problems), but when you need them, they are indispensable. I don't see any
real need to be able to run nested loops in parallel, but I don't see any
reason that running them in parallel should be disallowed.

I'm not sure of the syntax of for*/seq.  playing with :nested in srfi-42, I
just returned everything declared, but I can see that it might be useful to
be able to specify some subset (It makes the macrology easier as well, as
the macro does not need to collect the variable names)

> Jens Axel Søgaard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20070920/09fb30fc/attachment.html>

Posted on the users mailing list.