New function ADiff( aArray1, aArray2 )

New function ADiff( aArray1, aArray2 )

Postby Antonio Linares » Wed Feb 14, 2024 7:46 am

Included in next FWH build:
Code: Select all  Expand view  RUN
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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: New function ADiff( aArray1, aArray2 )

Postby Silvio.Falconi » Thu Feb 15, 2024 1:02 pm

Antonio Linares wrote:Included in next FWH build:
Code: Select all  Expand view  RUN
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?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
User avatar
Silvio.Falconi
 
Posts: 7075
Joined: Thu Oct 18, 2012 7:17 pm

Re: New function ADiff( aArray1, aArray2 )

Postby Antonio Linares » Thu Feb 15, 2024 1:30 pm

Code: Select all  Expand view  RUN
#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
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42122
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: New function ADiff( aArray1, aArray2 )

Postby paquitohm » Thu Feb 15, 2024 4:59 pm

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
paquitohm
 
Posts: 266
Joined: Fri Jan 14, 2022 8:37 am

Re: New function ADiff( aArray1, aArray2 )

Postby nageswaragunupudi » Thu Feb 15, 2024 6:10 pm

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?
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10654
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: New function ADiff( aArray1, aArray2 )

Postby paquitohm » Thu Feb 15, 2024 8:25 pm

Here you are:

Code: Select all  Expand view  RUN
//------------------------------------------------------------------//
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
*
 
paquitohm
 
Posts: 266
Joined: Fri Jan 14, 2022 8:37 am


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 22 guests