Ralf,

Thanks for the example.

On July 29, 2006 1:43 AM you wrote:
> 
> >> I turned exports into a function, as you'd probably want to 
> >> call it more than once.
> 
> > I don't understand the relevance of whether exports is a function
> > or not. As a generator we can use it as often as we like. No?
> 
> Try the following piece of code.
> 
> ---BEGIN aaa14.as
> #include "aldor"
> #include "aldorio"
> 
> main(): () == {
>       import from Integer, List Integer;
>       
>       fun(): Generator Integer == generate {
>               yield 0;
>               yield 1;
>       };
> 
>       const: Generator Integer == fun();
> 
>       stdout << [fun()] << newline;
>       stdout << [fun()] << newline;
>       stdout << [const] << newline;
>       stdout << [const] << newline;
> }
> main();
> ---END aaa14
> 
>  >aldor -grun -laldor aaa14.as
> [0,1]
> [0,1]
> [0,1]
> []
> 
> I agree that const is not constant. But a Generator is inherently 
> destructive.
>

Hmmm... I see. A constant that is not constant... Generators are
"mutable"? That seems like a very peculiar and questionable semantics
to me!

So if I write:

  for x in const repeat
    ...
  for x in const repeat
    ...

The 2nd loop is guarranteed never to execute?!

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.

> 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

Do you know of any other language where Generators have the
same semantics as in Aldor?

Regards,
Bill Page.




_______________________________________________
Axiom-developer mailing list
Axiom-developer@nongnu.org
http://lists.nongnu.org/mailman/listinfo/axiom-developer

Reply via email to