FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour operador In
Posts: 1956
Joined: Fri Oct 07, 2005 07:08 PM
operador In
Posted: Sun Feb 21, 2021 11:28 PM
Hola.

Code (fw): Select all Collapse
local aDatos:={1,2,3}
if (x in aDatos)
   ? "esta"
endif

eso al ejecutarlo me da un error de argumento, que hago mal?
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: operador In
Posted: Mon Feb 22, 2021 09:53 AM
Hola Gustavo.

El operador In ahora me entero que existe en Harbour, creo poder afirmar que en Clipper no existia.

si fueran cadenas podrias utilizar el operador $

de la forma

Code (fw): Select all Collapse
   local x := "a"
   local aDatos := "abc"
    if (x $ aDatos)
       ? "esta"
    endif


pero con numeros, como sabes puedes utilizar

Code (fw): Select all Collapse
   local x := 1
  local aDatos := {1,2,3}
    if (Ascan(aDatos, x)>0)
       ? "esta"
    endif


Saludos

Jose.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operador In
Posted: Mon Feb 22, 2021 10:15 AM
Code (fw): Select all Collapse
x IN aDatos

is permissible syntax in xHarbour and is very powerful.
I do not understand the reason for the runtime error, because we can use any datatype for x in this syntax.
Regards



G. N. Rao.

Hyderabad, India
Posts: 607
Joined: Mon Mar 04, 2013 04:32 PM
Re: operador In
Posted: Mon Feb 22, 2021 10:59 AM
Mr. Rao

I think Gustavo is using Harbour , the operator IN only exists in XHarbour

in Harbour and with arrays should uses
Code (fw): Select all Collapse
(Ascan(aDatos, x)>0)


Regards

Jose.
Fwh 24.07 64 bits + Harbour 64 bits 3.2dev(r2407221137) + MSVC64
Posts: 8523
Joined: Tue Dec 20, 2005 07:36 PM
Re: operador In
Posted: Mon Feb 22, 2021 01:23 PM
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operador In
Posted: Mon Feb 22, 2021 05:13 PM
I think Gustavo is using Harbour , the operator IN only exists in XHarbour

If he is using Harbour, he should get a compilation error but not runtime error.
Regards



G. N. Rao.

Hyderabad, India
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: operador In
Posted: Tue Feb 23, 2021 03:10 AM
Now, I understand.

This sample program:
Code (fw): Select all Collapse
#include "fivewin.ch"
#include "hbcompat.ch"

function Main()

   local x     := 2
   local aList := { 1,2,3 }

   if ( x IN aList )
      ? "ok"
   else
      ? "not ok"
   endif

return nil

When compiled and built with xHarbour works perfectly.

When we compile with Harbour, the hbcompat.ch uses this translate to preprocess:
Code (fw): Select all Collapse
   #translate ( <exp1> IN <exp2> )     => ( ( <exp1> ) $ ( <exp2> ) )


So,
Code (fw): Select all Collapse
   if ( x IN aList )

is translated and compiled as:
Code (fw): Select all Collapse
if ( x $ aList )

This naturally results in runtime error.
Regards



G. N. Rao.

Hyderabad, India

Continue the discussion