harbour / core

Portable, xBase compatible programming language and environment
https://harbour.github.io/
Other
322 stars 207 forks source link

Class operators Distinct from xHarbour #245

Open Hovestar opened 3 years ago

Hovestar commented 3 years ago

This is likely at most something to document in xhb-diff.txt, but xHarbour supports these 6 class operator overloads, that harbour does not:

 OpBitAnd
 OpBitOr
 OpBitShiftL
 OpBitShiftR
 OpBitXor
 OpForEach

Also the naming convention, which can be used to override an operator, is different for xHb's __OpContains and hb's (Interchangeable?) __OPINCLUDE and __OPINSTRING

Is the choice to not have the Bit operators and for each intentional?

As a note, since I haven't seen documentation for for each overloading in xhb this is the behavior:

class forEachRecnoObjectHolder
   data nTop
   method iterate operator "FOR EACH"
   method new constructor
endclass
method new(nTop)
   default nTop to 2
   ::nTop := nTop
return self
method iterate(nDepth,nStep)
   if nDepth == 1
      return self
   endif
   if nDepth > 2
      return nil
   endif
   if nStep > ::nTop
      break
   endif
return nStep

So calling for each n in forEachReconObjectHolder():new(3) will iterate through 1,2,3 and then exit. From the iterate call, it first calls with a depth, 1, where you then can return. If you return something iteratable it will iterate through it and then call with a nDepth of 2. If an object is returned it then will call with the same depth and a step, and the value will reflect exactly what you return, even if it's nil. To break the loop you need to call break at which point it will call with the next depth.

alcz commented 1 year ago

Harbour does not support bit operators overloads, because there is no support for those operators at all: https://github.com/harbour/core/blob/master/doc/xhb-diff.txt#L1055

I think this is mainly due to Clipper compatibility clashes. & is a macro operator.

There is a FOR EACH overloading example though: https://github.com/harbour/core/blob/master/tests/foreach2.prg