Set functions.
Funciones
Text Set2Txt(Set valSet, Text iniTxt, Text endTxt, Text sepTxt, Text sepLst, Text txtDet, Text datFmt, Text dteDet, Text dteFmt)Set SetShuffle(Set anySet)//////////////////////////////////////////////////////////////////////////////
Text Set2Txt(Set valSet, // Set of elements
Text iniTxt, // Initial text for list
Text endTxt, // End text for list
Text sepTxt, // Element separators
Text sepLst, // 2 last elements separator
Text txtDet, // Delimiter for texts
Text datFmt, // Format for real numbers
Text dteDet, // Delimiter for dates
Text dteFmt) // Format for dates
//////////////////////////////////////////////////////////////////////////////
{
Real card = Card(valSet);
Text body =
If(EQ(card,0), "",
If(EQ(card,1), F(valSet[1]),
If(EQ(card,2), F(valSet[1])+sepLst+F(valSet[2]),
{
Set txtVal = For(2,card,Text(Real p)
{
If(EQ(p,card),sepLst,sepTxt) + F(valSet[p])
});
F(valSet[1]) + BinGroup("+",txtVal)
})));
iniTxt+body+endTxt
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text like a list with all the elements of valSet converted in a
text format (elements types: Text, Real or Date).
Arguments:
- iniTxt initial text, for example: '(', '[[', '', etc.
- endTxt end text, for example ')', ']]', '', etc.
- sepTxt elements separator, for example '; ', ',', '', etc.
- sepLst two last elements separator, for example, ' & ', ' and ', etc.,
you can specify the same as sepTxt
- txtDet text delimiters, for exmple, quotes for TOL, single quote for
SQL, nothing, etc.
- datFmt real numbers format, for explame, '%.0lf' for integers, if none
then uses the default TOL real number format.
- dteDet date delimiters, for example, simgle quote for SQL.
- dteFmt date format, for example, '%c%Y%m%d', if none
then uses the default TOL dates format.
Only works with TOL types Text, Real or Date, when find a Set type then
works in a recursive way with the same arguments.",
Set2Txt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetShuffle(Set anySet) // Set of Anything
//////////////////////////////////////////////////////////////////////////////
{
Set tabSet = EvalSet(anySet, Set(Anything anyVal) // Para todo elemento
{ [[ Real Rand(0,1), anyVal ]] }); // Par [random, valor]
Set tabSrt = Sort(tabSet, Real(Set a, Set b) // Ordenar por el aleatorio
{ Compare(a[1],b[1]) });
EvalSet(tabSrt, Anything(Set parSet) { parSet[2] }) // Desordenados
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de lo que sea desordenado, para ello:
- Para cada elemento del conjunto, sea lo que sea, Anything,
construye una tabla de pares formados por un numero aleatorio y cada uno
de los elementos.
- Ordena por el elemento aleatorio, por lo que sera un total desorden.
- Recorre la tabla desordenada retornando el conjunto de los valores
originales.",
SetShuffle);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FILE : set.tol
// AUTHOR : http://www.asolver.com
// PURPOSE : Set functions.
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Text Set2Txt(Set valSet, // Set of elements
Text iniTxt, // Initial text for list
Text endTxt, // End text for list
Text sepTxt, // Element separators
Text sepLst, // 2 last elements separator
Text txtDet, // Delimiter for texts
Text datFmt, // Format for real numbers
Text dteDet, // Delimiter for dates
Text dteFmt) // Format for dates
//////////////////////////////////////////////////////////////////////////////
{
Real card = Card(valSet);
Text body =
If(EQ(card,0), "",
If(EQ(card,1), F(valSet[1]),
If(EQ(card,2), F(valSet[1])+sepLst+F(valSet[2]),
{
Set txtVal = For(2,card,Text(Real p)
{
If(EQ(p,card),sepLst,sepTxt) + F(valSet[p])
});
F(valSet[1]) + BinGroup("+",txtVal)
})));
iniTxt+body+endTxt
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Returns a text like a list with all the elements of valSet converted in a
text format (elements types: Text, Real or Date).
Arguments:
- iniTxt initial text, for example: '(', '[[', '', etc.
- endTxt end text, for example ')', ']]', '', etc.
- sepTxt elements separator, for example '; ', ',', '', etc.
- sepLst two last elements separator, for example, ' & ', ' and ', etc.,
you can specify the same as sepTxt
- txtDet text delimiters, for exmple, quotes for TOL, single quote for
SQL, nothing, etc.
- datFmt real numbers format, for explame, '%.0lf' for integers, if none
then uses the default TOL real number format.
- dteDet date delimiters, for example, simgle quote for SQL.
- dteFmt date format, for example, '%c%Y%m%d', if none
then uses the default TOL dates format.
Only works with TOL types Text, Real or Date, when find a Set type then
works in a recursive way with the same arguments.",
Set2Txt);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
Set SetShuffle(Set anySet) // Set of Anything
//////////////////////////////////////////////////////////////////////////////
{
Set tabSet = EvalSet(anySet, Set(Anything anyVal) // Para todo elemento
{ [[ Real Rand(0,1), anyVal ]] }); // Par [random, valor]
Set tabSrt = Sort(tabSet, Real(Set a, Set b) // Ordenar por el aleatorio
{ Compare(a[1],b[1]) });
EvalSet(tabSrt, Anything(Set parSet) { parSet[2] }) // Desordenados
};
//////////////////////////////////////////////////////////////////////////////
PutDescription(
"Retorna el conjunto de lo que sea desordenado, para ello:
- Para cada elemento del conjunto, sea lo que sea, Anything,
construye una tabla de pares formados por un numero aleatorio y cada uno
de los elementos.
- Ordena por el elemento aleatorio, por lo que sera un total desorden.
- Recorre la tabla desordenada retornando el conjunto de los valores
originales.",
SetShuffle);
//////////////////////////////////////////////////////////////////////////////
ChRules.Iterative programa de aplicacion iterativa de reglas de areas de caracteres
2015 asolver.com | Aviso legal | XHTML | Δ Θ Ξ | Creative Commons | Mapa y funciones del sitio