#pragma -ks+ and "A" $ {"A","B","C"}

100 views
Skip to first unread message

a...@poswithlogic.com

unread,
Feb 19, 2015, 4:12:26 PM2/19/15
to harbou...@googlegroups.com
Hi All,
Is this suppose to work?


#pragma -ks+
proc main()
? "A" $ {"A","B","C"}
wait 

 if I link in xhb.hbc it does, but then i get into trouble building an indexes with 'trim' using ADS remote connection. it converts 'trim' into 'xhb_trim'...

Thanks
Abe

Klas Engwall

unread,
Feb 19, 2015, 9:00:54 PM2/19/15
to harbou...@googlegroups.com
Hi Abe,
The answer is in doc\xhb-diff.txt:

Regards,
Klas


### $ OPERATOR EXTENSIONS (arrays and hashes) ###
=======================================================
In Harbour and xHarbour $ operator can be used to check if some key
or hash pair belongs to hash, f.e.:
? "abc" $ { "qwe"=>100, "abc"=>200, "zxc"=>300 }
In xHarbour $ operator can be also used to check if value belongs
to array. It works like ASCAN() but with exact comparison for strings,
f.e.:
? "abc" $ { "qwe", "abc", "zxc" } // result .T.
? "a" $ { "qwe", "abc", "zxc", { "a" } } // result .F.
By default Harbour core code does not allow to use $ operator for arrays
and generate the same as Clipper RT error but it has strong enough OOP API
to allow adding such extension without touching core code even by user at
.prg level. It was implemented in Harbour in XHB.LIB so both compilers
can compile and execute this code:
#ifndef __XHARBOUR__
#include "xhb.ch"
#endif
proc main()
? "abc" $ { "qwe", "abc", "zxc" } // result .T.
? "a" $ { "qwe", "abc", "zxc", { "a" } } // result .F.
return

Warning! Xbase++ also support $ operator for arrays but it makes non
exact comparison so ` "a" $ { "abc" } ' gives .T. in Xbase++
and .F. in xHarbour or in Harbour when xHarbour compatibility
library is used. Harbour users who need strict Xbase++
compatibility
should create own code to overload $ operators used for arrays
which will follow exact Xbase++ rules.
CLIP also has some code for such extension but it has two bugs.
1-st is a semi bug: it uses non exact comparison but reverts
arguments so ` "abc" $ { "a" } ' gives .T.
2-nd which is critical: it has wrong stop condition so does
not stop scanning when locates 1-st matching item. It should
be fixed and I do not know what will be the final CLIP behavior.

a...@poswithlogic.com

unread,
Feb 23, 2015, 1:34:26 PM2/23/15
to harbou...@googlegroups.com
hi Klas,

I said in my message that including xhb.ch gets it to work, but that gives me other problems. What exaclty in xhb.ch makes it work?

Klas Engwall

unread,
Feb 23, 2015, 5:29:21 PM2/23/15
to harbou...@googlegroups.com
Hi Abe,

> I said in my message that including xhb.ch gets it to work

Yes, I know. And I posted the quote from xhb-diff.txt to emphasize that
it is just meant as a workaround for former Xhb users who want to keep
their Xhb code unchanged.

> but that
> gives me other problems. What exaclty in xhb.ch makes it work?

I have no idea. I avoid the xhb contrib at all cost because you never
know what side effects it will bring to the mix.

Do you use the "$" syntax with arrays in a zillion places? Or would it
be possible to change your code to something like the following?

IF Ascan( aTarget, xSearch ) > 0

That would be a more long term solution. The Xhb "$" syntax is a
solution to a problem that does not exist, IMHO.

Regards,
Klas
Reply all
Reply to author
Forward
0 new messages