Page 1 of 1
New function ADiff( aArray1, aArray2 )
Posted: Wed Feb 14, 2024 7:46 am
by Antonio Linares
Included in next FWH build:
Code: Select all | Expand
function ADiff( a, b )
local c := {}
AEval( a, { | u, n | If( n > Len( b ), AAdd( c, u ),;
If( ValType( u ) != ValType( b[ n ] ), AAdd( c, u ),;
If( ! u == b[ n ], AAdd( c, u ),;
If( ValType( u ) == "A" .and. ValType( b[ n ] ) == "A", AAdd( c, ADiff( u, b[ n ] ) ), ) ) ) ) } )
AEval( b, { | u, n | If( n > Len( a ), AAdd( c, u ),) } )
return c
Re: New function ADiff( aArray1, aArray2 )
Posted: Thu Feb 15, 2024 1:02 pm
by Silvio.Falconi
Antonio Linares wrote:Included in next FWH build:
Code: Select all | Expand
function ADiff( a, b )
local c := {}
AEval( a, { | u, n | If( n > Len( b ), AAdd( c, u ),;
If( ValType( u ) != ValType( b[ n ] ), AAdd( c, u ),;
If( ! u == b[ n ], AAdd( c, u ),;
If( ValType( u ) == "A" .and. ValType( b[ n ] ) == "A", AAdd( c, ADiff( u, b[ n ] ) ), ) ) ) ) } )
AEval( b, { | u, n | If( n > Len( a ), AAdd( c, u ),) } )
return c
Can we have an example of use?
Re: New function ADiff( aArray1, aArray2 )
Posted: Thu Feb 15, 2024 1:30 pm
by Antonio Linares
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local a := { "uno", { "hola", "adios" }, "dos", "tres" }
local b := { "uno", "cuatro", { "hola", "adios" }, "cinco", 123 }
XBrowser( ADiff( a, b ) )
return nil
Re: New function ADiff( aArray1, aArray2 )
Posted: Thu Feb 15, 2024 4:59 pm
by paquitohm
Fw_ValToExp_Mia(a) --> (C) Len: 37 "{'uno',{'hola','adios'},'dos','tres'}"
Fw_ValToExp_Mia(b) --> (C) Len: 45 "{'uno','cuatro',{'hola','adios'},'cinco',123}"
Fw_ValToExp_Mia(c) --> (C) Len: 35 "{{'hola','adios'},'dos','tres',123}"
Según se ve en el resultado, devuelve los valores de a que no existen en la misma posición de b, pudiendo ser los valores de cualquier tipo. Una posible variante sería que los valores pudieran estar en cualquier posición de b
Re: New function ADiff( aArray1, aArray2 )
Posted: Thu Feb 15, 2024 6:10 pm
by nageswaragunupudi
FWH provides the function FW_ValToExp( uVal )
Where is the function Fw_ValToExp_Mia() from?
In what way it is different from the original FW_ValtoExp() function?
Re: New function ADiff( aArray1, aArray2 )
Posted: Thu Feb 15, 2024 8:25 pm
by paquitohm
Here you are:
Code: Select all | Expand
//------------------------------------------------------------------//
function FW_ValToExp_Mia( uVar )
local cExp, cType := ValType( uVar )
#Define TOLITERAL_(c) ("'"+ c+ "'" )
do case
case uVar == nil
cExp := ''
case cType == 'A'
cExp := '{'
if ! Empty( uVar )
cExp += FW_ValToExp_Mia( uVar[ 1 ] )
AEval( uVar, { |x| cExp += ',' + FW_ValToExp_Mia( x ) }, 2 )
endif
cExp += '}'
case cType == 'C'
cExp := TOLITERAL_( uVar )
case cType == 'D'
cExp := 'SToD("' + DToS( uVar ) + '")'
case cType == 'T'
// Al menos en Harbour nn.nn no existe el TToS() (Now year 2014)
cExp := TOLITERAL_("Datos Time no pueden ser grabados")
case cType == 'O'
cExp := TOLITERAL_("Objetos no pueden ser grabados")
otherwise
cExp := cValToChar( uVar )
endcase
return cExp
*