"for" question (newbie)

Denys Duchier Denys.Duchier at ps.uni-sb.de
Thu Sep 12 21:06:43 CEST 2002


bspight at pacbell.net (Bill Spight) writes:

> for
>   X in L
>   Y in {Tail L}
> do
>  (X<Y)=true
> end
>
> L is a list of integers (not necessarily instantiated).
>
> At first glance, and upon checking the documentation, it seems like the
> loop should traverse the cartesian product of L and its tail.

I don't know where you got this idea. "Upon checking the documention",
ahem, you'll find (in the document "Loop Support"):

      In order to provide convenient syntax for loops, two new
      keywords have been introduced in Mozart 1.1.0: for and do. Thus,
      a new statement is introduced in the Oz language and its syntax
      is:

		for Declarations do ... end

      where Declarations is a sequence of 0 or more iterator and
      feature declarations. An iterator has the form: Pat in Generator
      where Generator describes how to generate the successive values
      for pattern Pat whose variables are local to the loop. The
      generators are stepped in parallel and the loop terminates as
      soon as one of the generators runs out of values.

Notice the sentence "generators are stepped in parallel" :-)  I
actually added this sentence at Joachim's request to attempt to remove
a possible ambiguity.  I guess I failed :-(

Here is the scoop. Consider the following loop:

	for
	   X in [a b c]
	   Y in [1 2 3 4]
	in
	   ...
	end

Here is what happens on each iteration:

	Iteration 1: X=a Y=1
	Iteration 2: X=b Y=2
	Iteration 3: X=c Y=3

then the generator for X runs out of values, which causes the loop to
terminate.  Maybe, that's what I should put in the documentation.

Cheers,

-- 
Dr. Denys Duchier			Denys.Duchier at ps.uni-sb.de
Forschungsbereich Programmiersysteme	(Programming Systems Lab)
Universitaet des Saarlandes, Geb. 45	http://www.ps.uni-sb.de/~duchier
Postfach 15 11 50			Phone: +49 681 302 5618
66041 Saarbruecken, Germany		Fax:   +49 681 302 5615
-
Please send submissions to users at mozart-oz.org
and administriva mail to users-request at mozart-oz.org.
The Mozart Oz web site is at http://www.mozart-oz.org/.





More information about the mozart-users mailing list