Hello,
[ Generators ]
Hmmm... I see. A constant that is not constant...
For exactly this reason, you should not define a Generator to be constant.
It's bad style ;)
You can modify every connstant that has destructive functions...
Is there any language forbidding this?
Generators are "mutable"? That seems like a very peculiar and
questionable semantics
to me!
No. It's the whole point of generators...
So if I write:
for x in const repeat
...
for x in const repeat
...
The 2nd loop is guarranteed never to execute?!
I assume, you have some
const == someGenerator;
before the for loops. Then segfaults happen (occasionally) with such
constructs.
But after all, you should not write such code.
But if I have some other constant constant like a list
const2: List Integer == [1,2,3]
for x in const2 repeat
...
for x in const2 repeat
...
or even
for x in 1..10 repeat
...
for x in 1..10 repeat
...
this works as expected even though in Aldor iteration over a list
is implemented as a generator.
yes. Because the you call the generator FUNCTION once your every for loop.
Your loops *magic* are translated into
for x in generator const2 repeat
{
...
}
for x in generator const2 repeat
{
...
}
(or something equivalent). So the generatos are NOT constants. But the
List you take the generator of is constant.
If you like you could also say something like
a: Record(x: Integer) == [1];
a.x := 0;
and the "constant" a changes. But you should note that the
last line is
actually
set!(a, x, 0)
so that is a destructive function and thus you should expect strange
things. The BANG functions (like set!) are only for people
who know what they do.
Of course but I do not see the relevance of this to a generator.
Yes I understand that a generator is always in a certain "state"
and what the generator yields depends on that state, but surely
there are reasonable contexts in which the state of the generator
is reset?
Further what does this have to do with the type of the constant,
i.e. whether it is>
const: Generator Integer
or
const: () -> Generator Integer
I already explained things above. If it's still a mystery to you ... tell
me, and I'll be more explicit.
Do you know of any other language where Generators have the
same semantics as in Aldor?
For example Java:
http://java.sun.com/j2se/1.3/docs/api/java/util/Iterator.html
For example C++:
http://www.sgi.com/tech/stl/Iterators.html
--
Kind regards,
Christian
_______________________________________________
Axiom-developer mailing list
Axiom-developer@nongnu.org
http://lists.nongnu.org/mailman/listinfo/axiom-developer