Re: [open-axiom-devel] [fricas-devel] Re: [fricas-devel] Re: [fricas-devel] Re: iterators and cartesian product.

Ralf Hemmecke <[email protected]> Wed, 24 Oct 2007 03:24:17 +0200
Newsgroups gmane.comp.mathematics.axiom.general
Message-ID <[email protected]>
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.

>> Well, if you have somewhere a function
>>
>>    generator: T -> Generator(Something)
>>
>> (where T is the type of X) around, then Aldor should be able to silently
>> insert that function for you.
>>
> 
> I said only "like Aldor". In my proposal for an extension of Spad and
> the Axiom interpreter, I expect that X must supply this generator
> (iterator), i.e. satisfy some specific language-defined category that
> includes this export.
> 
>> I must say, I am totally happy with just *one* "for" construction.
> 
> That is exactly what I am suggesting. There should be no special cases
> of the "for" construct - only one, where X is as I describe.
> 
>> I am currently not seeing much use in the domain 1..9, i.e. the finite set
>> {1, ..., 9}.
>>
> 
> The point of this whole thread is discussion of suggested constructions like
> 
>   [ f(i,j) for i in 1..9 repeat for j in 1..4 ]
> 
> i.e. some kind of "cross-product" extension of the for-loop iteration
> such as the CROSS construction that Gaby described in Boot. Rather
> than extending the language with this sort of imperative syntax, I
> would like to write this in a more "functional" manner instead:
> 
>   [ f(x.1,x.2) for x in Product(1..9,1..4) ]
> 
> (Right now Product provides only 'selectfirst' and 'selectsecond'
> instead of .1 and .2 but that is easily fixed.)
> 
> Or better
> 
>   map(f,expand()$Product(1..9,1..4))
> 
> which requires some slightly more general implementation of function
> application over such domains.
> 
> Regards,
> Bill Page.

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;
     }
}

???

What you want is available now and no need of 1..9 being a domain.

Ralf