Matrix ( )

Function stats

Average user rating
46
171
9999
Support
FileMaker 8.0 +
Date posted
27 December 2008
Last updated
27 December 2008
Version
Recursive function
No

Author Info
 Agnès

17 functions

Average Rating 4.6

author_avatar



 

Function overview

Prototype

Matrix  ( MatrixList;   SeparatorOrTagXml;   KeepEmpty )


Parameters

MatrixList  


SeparatorOrTagXml  


KeepEmpty  


Description

Tags:  Matrix   List   concatenate  

To build a Matrix with several lists
Matrix can be used to concatenate all combinaisons to prepare search

Requires CustomList ( start ; End ; Function )
Not recursive function

---------------------------------- Parameter
MatrixList --> Enter one list or more for build the list
SeparatorOrTagXml --> tag xml for one list, or séparator for more
KeepEmpty --> Boolean and optional : Keep empty list or not

---------------------------------- Usage [Matrix in Matrix]
Matrix ( Matrix ( MatrixList ; SeparatorOrTagXml ; KeepEmpty ) & Matrix ( MatrixList ; SeparatorOrTagXml ; KeepEmpty ) & (...) ; SeparatorOrTagXml ; KeepEmpty )

---------------------------------- Example with 5 lists (with two empty list)

List_A contains "1¶2¶3"
List_B contains "A¶B"
List_C is empty
List_D contains "y¶z"
List_E is empty

1/ all KeepEmpty < 1 : we do not keep empty lists | Principal SeparatorOrTagXml are " | "

Matrix ( Matrix ( List_A ; "" ; "" ) & Matrix ( List_B ; "" ; "" ) & Matrix ( List_C ; "" ; "" ) & Matrix ( List_D ; "" ; "" ) & Matrix ( List_E ; "" ; "" ) ; " | " ; 0 )

Result :
1 | A | y
2 | A | y
3 | A | y
1 | B | y
2 | B | y
3 | B | y
1 | A | z
2 | A | z
3 | A | z
1 | B | z
2 | B | z
3 | B | z

2/ Principal KeepEmpty = 1 : we keep empty lists | Principal SeparatorOrTagXml are " . "

Matrix ( Matrix ( List_A ; "" ; "" ) & Matrix ( List_B ; "" ; "" ) & Matrix ( List_C ; "" ; "" ) & Matrix ( List_D ; "" ; "" ) & Matrix ( List_E ; "" ; "" ) ; " . " ; 1 )

Result :
1 . A . EmptyList . y . EmptyList
2 . A . EmptyList . y . EmptyList
3 . A . EmptyList . y . EmptyList
1 . B . EmptyList . y . EmptyList
2 . B . EmptyList . y . EmptyList
3 . B . EmptyList . y . EmptyList
1 . A . EmptyList . z . EmptyList
2 . A . EmptyList . z . EmptyList
3 . A . EmptyList . z . EmptyList
1 . B . EmptyList . z . EmptyList
2 . B . EmptyList . z . EmptyList
3 . B . EmptyList . z . EmptyList

3/ Principal KeepEmpty = 0 and secondary KeepEmpty are 0 or 1 : we do not keep all empty lists | Principal SeparatorOrTagXml are " "

Matrix ( Matrix ( List_A ; "" ; 1 ) & Matrix ( List_B ; "" ; 1 ) & Matrix ( List_C ; "" ; 1 ) & Matrix ( List_D ; "" ; 1 ) & Matrix ( List_E ; "" ; 0 ) ; " " ; 0 )

Result :
1 A EmptyList y
2 A EmptyList y
3 A EmptyList y
1 B EmptyList y
2 B EmptyList y
3 B EmptyList y
1 A EmptyList z
2 A EmptyList z
3 A EmptyList z
1 B EmptyList z
2 B EmptyList z
3 B EmptyList z

4/ Principal KeepEmpty = 1 : we keep empty lists | Principal SeparatorOrTagXml are " " and secondary SeparatorOrTagXml are Tag for tag Data

Matrix ( Matrix ( List_A ; "L_A" ; "" ) & Matrix ( List_B ; "L_B" ; "" ) & Matrix ( List_C ; "L_C" ; "" ) & Matrix ( List_D ; "L_D" ; "" ) & Matrix ( List_E ; "L_E" ; "" ) ; " " ; 1 )

Result :
<L_A>1</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>

5/ All KeepEmpty are empty : we keep empty lists | Principal SeparatorOrTagXml are " | " and secondary SeparatorOrTagXml are Tag for tag Data

Matrix ( Matrix ( List_A ; "L_A" ; "" ) & Matrix ( List_B ; "L_B" ; "" ) & Matrix ( List_C ; "L_C" ; "" ) & Matrix ( List_D ; "L_D" ; "" ) & Matrix ( List_E ; "L_E" ; "" ) ; " | " ; "" )

Result :
<L_A>1</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>2</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>3</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>1</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>2</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>3</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>1</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>2</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>3</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>1</L_A> | <L_B>B</L_B> | <L_D>z</L_D>
<L_A>2</L_A> | <L_B>B</L_B> | <L_D>z</L_D>
<L_A>3</L_A> | <L_B>B</L_B> | <L_D>z</L_D>

Examples

Sample input

1/ --------------------
Matrix ( Matrix ( "Toyota¶Chrysler" ; "" ; "" ) & Matrix ( "Yellow¶Red¶Black" ; "" ; "" ) & Matrix ( "2 doors¶5 doors" ; "" ; "" ) ; " | " ; 0 )

2/ --------------------
Matrix ( Matrix ( "Toyota¶Chrysler" ; "Car" ; "" ) & Matrix ( "Yellow¶Red¶Black" ; "Color" ; "" ) & Matrix ( "2 doors¶5 doors" ; "Door" ; "" ) ; " " ; 0 )


Sample output

1/ --------------------
Toyota | Yellow | 2 doors
Chrysler | Yellow | 2 doors
Toyota | Red | 2 doors
Chrysler | Red | 2 doors
Toyota | Black | 2 doors
Chrysler | Black | 2 doors
Toyota | Yellow | 5 doors
Chrysler | Yellow | 5 doors
Toyota | Red | 5 doors
Chrysler | Red | 5 doors
Toyota | Black | 5 doors
Chrysler | Black | 5 doors

2/ --------------------
<Car>Toyota</Car> <Color>Yellow</Color> <Door>2 doors</Door>
<Car>Chrysler</Car> <Color>Yellow</Color> <Door>2 doors</Door>
<Car>Toyota</Car> <Color>Red</Color> <Door>2 doors</Door>
<Car>Chrysler</Car> <Color>Red</Color> <Door>2 doors</Door>
<Car>Toyota</Car> <Color>Black</Color> <Door>2 doors</Door>
<Car>Chrysler</Car> <Color>Black</Color> <Door>2 doors</Door>
<Car>Toyota</Car> <Color>Yellow</Color> <Door>5 doors</Door>
<Car>Chrysler</Car> <Color>Yellow</Color> <Door>5 doors</Door>
<Car>Toyota</Car> <Color>Red</Color> <Door>5 doors</Door>
<Car>Chrysler</Car> <Color>Red</Color> <Door>5 doors</Door>
<Car>Toyota</Car> <Color>Black</Color> <Door>5 doors</Door>
<Car>Chrysler</Car> <Color>Black</Color> <Door>5 doors</Door>

 

Function code

// Matrix ( MatrixList ; SeparatorOrTagXml ; KeepEmpty ) v2.0
// requires CustomList ( start ; End ; Function )

/*
Usage :
Matrix ( Matrix ( MatrixList ; SeparatorOrTagXml ; KeepEmpty ) & Matrix ( MatrixList ; SeparatorOrTagXml ; KeepEmpty ) & (...) ; SeparatorOrTagXml ; KeepEmpty )
*/
/*
To build a Matrix with several lists
Matrix can be used to concatenate all combinaisons to prepare search
*/

//---------------------------------- Parameter
// MatrixList --> Enter one list or more
// SeparatorOrTagXml --> tag xml for one list, or séparator for more
// KeepEmpty --> Boolean and optional : Keep empty list or not

//---------------------------------- Example with 5 lists (with two empty list)
/*
List_A contains "1¶2¶3"
List_B contains "A¶B"
List_C is empty
List_D contains "y¶z"
List_E is empty

1/ all KeepEmpty < 1 : we do not keep empty lists | Principal SeparatorOrTagXml are " | "
Matrix ( Matrix ( List_A ; "" ; "" ) & Matrix ( List_B ; "" ; "" ) & Matrix ( List_C ; "" ; "" ) & Matrix ( List_D ; "" ; "" ) & Matrix ( List_E ; "" ; "" ) ; " | " ; 0 )

Result :
1 | A | y
2 | A | y
3 | A | y
1 | B | y
2 | B | y
3 | B | y
1 | A | z
2 | A | z
3 | A | z
1 | B | z
2 | B | z
3 | B | z

2/ Principal KeepEmpty = 1 : we keep empty lists | Principal SeparatorOrTagXml are " . "
Matrix ( Matrix ( List_A ; "" ; "" ) & Matrix ( List_B ; "" ; "" ) & Matrix ( List_C ; "" ; "" ) & Matrix ( List_D ; "" ; "" ) & Matrix ( List_E ; "" ; "" ) ; " . " ; 1 )

Result :
1 . A . EmptyList . y . EmptyList
2 . A . EmptyList . y . EmptyList
3 . A . EmptyList . y . EmptyList
1 . B . EmptyList . y . EmptyList
2 . B . EmptyList . y . EmptyList
3 . B . EmptyList . y . EmptyList
1 . A . EmptyList . z . EmptyList
2 . A . EmptyList . z . EmptyList
3 . A . EmptyList . z . EmptyList
1 . B . EmptyList . z . EmptyList
2 . B . EmptyList . z . EmptyList
3 . B . EmptyList . z . EmptyList

3/ Principal KeepEmpty = 0 and secondary KeepEmpty are 0 or 1 : we do not keep all empty lists | Principal SeparatorOrTagXml are " "
Matrix ( Matrix ( List_A ; "" ; 1 ) & Matrix ( List_B ; "" ; 1 ) & Matrix ( List_C ; "" ; 1 ) & Matrix ( List_D ; "" ; 1 ) & Matrix ( List_E ; "" ; 0 ) ; " " ; 0 )

Result :
1 A EmptyList y
2 A EmptyList y
3 A EmptyList y
1 B EmptyList y
2 B EmptyList y
3 B EmptyList y
1 A EmptyList z
2 A EmptyList z
3 A EmptyList z
1 B EmptyList z
2 B EmptyList z
3 B EmptyList z

4/ Principal KeepEmpty = 1 : we keep empty lists | Principal SeparatorOrTagXml are " " and secondary SeparatorOrTagXml are Tag for tag Data
Matrix ( Matrix ( List_A ; "L_A" ; "" ) & Matrix ( List_B ; "L_B" ; "" ) & Matrix ( List_C ; "L_C" ; "" ) & Matrix ( List_D ; "L_D" ; "" ) & Matrix ( List_E ; "L_E" ; "" ) ; " " ; 1 )

Result :
<L_A>1</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>y</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>A</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>1</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>2</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>
<L_A>3</L_A> <L_B>B</L_B> <L_C>EmptyList</L_C> <L_D>z</L_D> <L_E>EmptyList</L_E>

5/ All KeepEmpty are empty : we keep empty lists | Principal SeparatorOrTagXml are " | " and secondary SeparatorOrTagXml are Tag for tag Data
Matrix ( Matrix ( List_A ; "L_A" ; "" ) & Matrix ( List_B ; "L_B" ; "" ) & Matrix ( List_C ; "L_C" ; "" ) & Matrix ( List_D ; "L_D" ; "" ) & Matrix ( List_E ; "L_E" ; "" ) ; " | " ; "" )

Result :
<L_A>1</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>2</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>3</L_A> | <L_B>A</L_B> | <L_D>y</L_D>
<L_A>1</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>2</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>3</L_A> | <L_B>B</L_B> | <L_D>y</L_D>
<L_A>1</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>2</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>3</L_A> | <L_B>A</L_B> | <L_D>z</L_D>
<L_A>1</L_A> | <L_B>B</L_B> | <L_D>z</L_D>
<L_A>2</L_A> | <L_B>B</L_B> | <L_D>z</L_D>
<L_A>3</L_A> | <L_B>B</L_B> | <L_D>z</L_D>

*/
//----------------------------------
// @ Agnès. December, 2008 BugReport - barouh.agnes@wanadoo.fr
//----------------------------------


Case (

//================================= Part One - Buid one List
not PatternCount ( MatrixList ; "EndListMatrix" ) ;

Let ([

Nettoyage = Substitute ( "#^#" & MatrixList & "#^#" ;
[ ¶ & "#^#" ; "" ] ; [ ¶ ; "¶#^#" ]; [ "#^#¶"; "" ]; [ "¶#^#"; ¶ ]; [ "¶#^#"; "" ]; [ "#^#"; "" ] ) ;
$MX_Passe = $MX_Passe + 1 ;
TagL = "§#§" & $MX_Passe & "§#§" & "<" & SeparatorOrTagXml & ">" ;
TagR = "</" & SeparatorOrTagXml & ">"
];
Case (
IsEmpty ( Nettoyage ) ;
TagL & "EmptyList" & Choose ( KeepEmpty ; "" ; "§#§" ) & TagR ;
TagL & Substitute ( Nettoyage ; [ ¶ ; TagR & ¶ & TagL ] ) & TagR
) & "<EndListMatrix>" )
;
//================================= Part Two - Build The List with all "first list"
not IsEmpty ( MatrixList ) ;

Let ([

cfMx = "<EndListMatrix>" ;
$MX_rc = ¶ ; $MX_num = 0 ; $MX_Passe = 0 ; $MX_sum = 0 ; $MX_x = 1 ; $MX_Count = 0 ; $MX_M = "" ; $MX_n = "" ;
$MX_Keep = KeepEmpty ;

$MX_GetV = Substitute ( MatrixList & "#^#" ; [ cfMx & "#^#" ; "" ] ; [ ¶ ; "^§|§^" ] ; [ cfMx ; ¶ ] ; [ "#^#"; "" ] ) ;

Charge = CustomList ( 1 ; ValueCount ( $MX_GetV ) ; "Let ([
Value = Substitute ( GetValue ( $MX_GetV ; [n] ) ; \"^§|§^\" ; $MX_rc ) ;
Test = PatternCount ( Value ; \">EmptyList<\" ) ;
Result = Case ( ( $MX_Keep <> 1 And Test <> 1 ) or $MX_Keep = 1 ; Let ([
$MX_num = $MX_num + 1 ;
$MX_MxVar[$MX_num] = Value ;
$MX_sum = $MX_sum + ValueCount ( $MX_MxVar[$MX_num] ) ;
$MX_n = $MX_n & Case ( not IsEmpty ( $MX_n ) ; $MX_rc ) & [n] ]; GetValue ( $MX_MxVar[$MX_num] ; 1 ) ) ) ]; Result )" ) ;

$MX_First = Substitute ( Charge ; $MX_rc ; SeparatorOrTagXml ) ;

Result = CustomList ( 1 ; $MX_sum ; "Let ([
Variable = $MX_MxVar[$MX_x] ;
$MX_Count = Case ( $MX_Count = ValueCount ( Variable ) ; 1 ; $MX_Count + 1 ) ;
Value = GetValue ( Variable ; 1 ) ;
Test = $MX_Count = 1 And [n] > 1 ;
$MX_M = Choose ( Test ; $MX_M & Case ( not IsEmpty ( $MX_M ) ; $MX_rc ) & Substitute ( $MX_First ; Value ; GetValue ( Variable ; $MX_Count ) ) ; $MX_First ) ;
$MX_x = $MX_x + Test ;
$MX_First = Case ( $MX_Count = ValueCount ( $MX_MxVar[$MX_x] ) ; Substitute ( $MX_M ; [ \"§#§\" & GetValue ( $MX_n ; $MX_x ) & \"§#§\" ; \"\" ] ) ; $MX_First )];\"\" )" )
];
Substitute ( $MX_First ; [ "<>" ; "" ] ; [ "</>" ; "" ] ; [ "EmptyList§#§" ; "EmptyList" ] )
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/171

    Prototype: Matrix( MatrixList; SeparatorOrTagXml; KeepEmpty )
    Function Author: Agnès (http://www.fmfunctions.com/mid/46)
    Last updated: 27 December 2008
    Version: 1.4

*/
// ===================================