Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product.
Ralf Hemmecke <[email protected]> Wed, 24 Oct 2007 23:11:45 +0200
| Newsgroups | gmane.comp.mathematics.axiom.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Bill,
On 10/24/2007 03:56 AM, Bill Page wrote:
> On 10/23/07, Ralf Hemmecke wrote:
>> On 10/24/2007 03:07 AM, Bill Page wrote:
>>> On 10/23/07, Ralf Hemmecke wrote:
>>>>>> Seems OK, but, of course the _domain_ 1..9 is then inappropriate in a
>>>>>> construction like
>>>>>>
>>>>>> for i in 1..9 repeat ...
>>>>>>
>>>>>> don't you agree?
>>>>>>
>>>>> No. My proposal also includes the idea that the construct
>>>>>
>>>>> for i in X repeat
>>>>>
>>>>> should expect X to be any domain that supplies a generator (like Aldor).
>>>> In Aldor, at the place of X there must be an element of type
>>>> "Generator(Something)", not a domain.
>>> Can you give an example of an "element of type Generator(Something)"
>>> that is not a domain?
>> g: Generator(Integer) := generate {yield 0}
>>
>> Take g.
>>
>
> Ok, yes I see what you mean. But this requires some new basic
> functionality in the language, right?
I cannot live anymore without "Generator". And I very much hope it will
make it into SPAD.
> Contrast this with 'Stream' in
> Axiom which (so far as I understand) does not require such an
> extension of Spad.
For me a stream is like a generator with memory. If I step a generator
then I can never repeat that step. Take (Aldor)
g: Generator Integer := generate yield 1;
l1: List Integer := [x for x in g];
l2: List Integer := [x for x in g]
that yields l1=[1] and l2=[].
If you replace g by
s: Stream(Integer) := ...
you would probably expect that also l2=[1]
Oh, I am totally wrong. Streams are always infinite, Generators are not.
So I would have to write
[x for x in s for i in 1..1]
>> Hmmm, didn't you like
>>
>> http://lists.gnu.org/archive/html/axiom-math/2007-10/msg00023.html
>>
>> main(): () == {
>> import from Z, Product(Z, Z);
>> s1: Segment Z := 1..3;
>> s2: Segment Z := 11..12;
>> for ab in s1 * s2 repeat {
>> (a, b) := ab;
>> stdout << a << ", " << b << newline;
>> }
>> }
> Yes, that is "ok" but ... we already have a domain construction
> Product in the Axiom library that takes two *domains* as it's
> parameters.
OK if you like that so much then OK. As Martin said, that is very much
what we do in Aldor-combinat. There is a Product functor that takes two
species and produces the product species. Each species comes with a function
structures: SetSpecies L -> Generator %;
So for us it would mean
for s in structures([1,2,3,4])$Times(F, G)(Integer) repeat ...
where F and G would be the species corresponding to 1..9 and 1..4.
I don't see that this makes life easier.
I am sure one could simplify some libraries so that you end up with
for s in generator()$Product(1..9, 1..9) repeat
where 1..9 should be interpreted as a domain that also provides a function
generator: () -> Generator %
Fine. But look closer and you see that I build again on the concept of
Generator.
If I understand you correctly, you basically want to have the same
functions but like the compiler to allow you to write
for s in Product(1..9, 1..9) ...
as syntactic sugar for my line above.
I hopefully don't introduce too much confusion here. I don't know enough
of the limitations of SPAD.
Ralf