This set is a bit cleaner.

Using the fact that in MATRIX you can do things like.

COMPUTE x=f(x).

I use the result of previous iteration and replace it with the new

calculation.

Didn't make sense to have a single line of code in the worker macro so I

stuffed it into the recursive function.

Makes more sense memory wise since only one result matrix is retained.

Consequently makes it less confusing to call.

---

DEFINE !RecursiveCartesianProduct ( !POS !CHAREND ("|" ) /!POS !CMDEND )

!IF (!TAIL(!1) !NE !NULL ) !THEN

COMPUTE !2={KRONEKER(!HEAD(!1),MAKE(NROW(!HEAD(!TAIL (!1))),1,1)),

KRONEKER(MAKE(NROW(!HEAD(!1)),1,1),!HEAD(!TAIL (!1)))}.

!RecursiveCartesianProduct !2 !TAIL(!TAIL(!1)) | !2.

!IFEND

!ENDDEFINE.

/* Recursive loading method */.

DEFINE !Load (!POS !CHAREND("|" ) / !POS !CMDEND )

!IF (!1 !NE !NULL ) !THEN

COMPUTE !HEAD(!1)=!UNQUOTE(!HEAD(!2)).

!Load !TAIL(!1) | !TAIL(!2).

!IFEND

!ENDDEFINE.

/* Different ways to call into the beast */.

SET MPRINT ON PRINTBACK ON.

OUTPUT CLOSE ALL.

MATRIX.

!Load A B C D E | 'T({1:10}/10)' 'T({1:10}/20)' 'T({1:10}/30)'

'T({1:10}/40)' 'T({1:10}/50)' .

!RecursiveCartesianProduct A B C D E | Z .

PRINT NROW(Z).

PRINT Z.

END MATRIX.

DEFINE !A () 'T({1:10}/10)' !ENDDEFINE.

DEFINE !B () 'T({1:10}/20)' !ENDDEFINE.

DEFINE !C () 'T({1:10}/30)' !ENDDEFINE.

DEFINE !D () 'T({1:10}/40)' !ENDDEFINE.

DEFINE !E () 'T({1:10}/50)' !ENDDEFINE.

/* You didn't grock this previously */.

DEFINE !Mx (!POS !ENCLOSE("(",")") )

!CONCAT('!',!1)

!ENDDEFINE.

OUTPUT CLOSE ALL.

MATRIX.

!Load A B C D E | !Mx(A) !Mx(B) !Mx(C) !Mx(D) !Mx(E) .

!RecursiveCartesianProduct A B C D E | Z .

PRINT NROW(Z).

PRINT Z.

END MATRIX.

OUTPUT CLOSE ALL.

MATRIX.

!Load A B C D E | !A !B !C !D !E .

!RecursiveCartesianProduct A B C D E | Z .

PRINT NROW(Z).

PRINT Z.

END MATRIX.

OUTPUT CLOSE ALL.

MATRIX.

COMPUTE A={1;2;3;4;5;6}.

COMPUTE B={7;8;9}.

COMPUTE C={10;20;30;40}.

COMPUTE D={-1;-2;-3;-4}.

COMPUTE E={1;2;3;4;5;6}.

!RecursiveCartesianProduct A B C D E | Z .

PRINT NROW(Z).

PRINT Z.

END MATRIX.

-----

Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.

---

"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."

Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"

--

Sent from:

http://spssx-discussion.1045642.n5.nabble.com/=====================

To manage your subscription to SPSSX-L, send a message to

[hidden email] (not to SPSSX-L), with no body text except the

command. To leave the list, send the command

SIGNOFF SPSSX-L

For a list of commands to manage subscriptions, send the command

INFO REFCARD

Please reply to the list and not to my personal email.

Those desiring my consulting or training services please feel free to email me.

---

"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."

Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"