Francois Maltey <[EMAIL PROTECTED]> writes:

> With axiom I only find this multi-line command :
> L := reduce
>  (append, 
>   [reduce
>    (append, 
>     [reduce
>      (append, 
>       [[matrix [[a,b,15-a-b],[c,d,15-c-d],[15-a-c,15-b-d,15-a-d]] 
>         for a in 1..9] for b in 1..9]) for c in 1..9]) for d in 1..9]) ;

you can shorten this in two different ways:

* reduce(append, l) is the same as concat l, thus, you can write

L := concat [concat [concat [[matrix [[a,b,15-a-b],_
                                      [c,d,15-c-d],_
                                      [15-a-c,15-b-d,15-a-d]] _
                              for a in 1..9]_
                             for b in 1..9]_
                     for c in 1..9] _
             for d in 1..9]

* you could first generate all Cartesian products with

L := concat [concat [concat [[[a,b,c,d] _
                              for a in 1..9] _
                             for b in 1..9] _
                     for c in 1..9] _
             for d in 1..9]

and then loop over them:

[eval(matrix [[a,b,15-a-b],[c,d,15-c-d],[15-a-c,15-b-d,15-a-d]], [a,b,c,d], l) 
for l in L]

> a train of for creates only one zip-list.

Yes, and that's something very useful! For example

[f(l) for l in L for i in 1..4]

only uses the first for elements in L, or

[f(l, i) for l in L for i in 1..]

is in my opinion much better to read then

[f(L.i, i) for i in 1..#L]


Martin



_______________________________________________
Axiom-developer mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/axiom-developer

Reply via email to