Overloading operators with Clipper 
Author Message
 Overloading operators with Clipper


Quote:
> That works ok, but the comparision depends of SET EXACT (as I expect) then I
> try to define "==" and my surprise is that operation "==" works with arrays
> (without defining).

> LOCAL a := { .. }
> LOCAL b := a

> ? a==b
> -> .T.

> Both have the same pointer.

Correct, this is documented in the Clipper manuals and the Norton Guide:

------------------------------------------------------------------------------
 ==
 Exactly equal--binary                           (Relational)
------------------------------------------------------------------------------
 Syntax

     <exp1> == <exp2>

 Type

     All

 Operands

     <exp1> and <exp2> are expressions of the same data type to
     compare.

 Description

     == is a binary operator that compares two values of the same data type
     for exact equality depending on the data type.  It returns true (.T.) if
     <exp1> is equal to <exp2> according to the following rules:

     .  Array: Compares for identity.  If <exp1> and <exp2> are
        variable references to the same array, returns true (.T.); otherwise
        returns false (.F.).
[SNIP]
------------------------------------------------------------------------------

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.*-*-*.com/ |  ng2html - The NG to HTML converter.
http://www.*-*-*.com/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Fri, 22 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
>Correct, this is documented in the Clipper manuals and the Norton Guide:
>     .  Array: Compares for identity.  If <exp1> and <exp2> are
>        variable references to the same array, returns true (.T.);
otherwise
>        returns false (.F.).

You are rigth, and Its also documented y class(y) library in the objects
comparision, also works with CodeBlocks...

If you are interested in overload library you can get from
http://www.ctv.es/USERS/jbarreiro overload.zip (3k) contains library,
include and a demo PRG. You can also overload functions with objects.

Example :

CLASS Tsomething
    DATA x
    OPERATOR (+)
ENDCLASS

OPERATOR Tsomething::(+a)
    ::x += a
RETURN ( self )

Now you can :
LOCAL o := Tsomething():new(...)
LOCAL a := 5

? o + a

Of course you can define complex operations!!

Thanks.



Sat, 23 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
> If you are interested in overload library you can get from
> http://www.ctv.es/USERS/jbarreiro overload.zip (3k) contains library,
> include and a demo PRG. You can also overload functions with objects.

I grabbed a copy but the source for the library was missing so it was of
little interest. Perhaps you'd consider including the source or at least
documenting how it works (and, indeed, how it is used, I couldn't find any
docs for that either)?

At a quick glance it would appear you are doing it via errorsys trickery, is
this the case? The reason I ask is that I played with that idea a number of
years back and realised that while it works up to a point it breaks down the
moment you use custom error handlers.

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Sat, 23 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper
Quote:
>I grabbed a copy but the source for the library was missing so it was of
>little interest. Perhaps you'd consider including the source or at least
>documenting how it works (and, indeed, how it is used, I couldn't find any
>docs for that either)?

You can obtain a explication of how it works in the FAQs & Tips section of
the Web.

Un saludo desde Mallorca.



Sun, 24 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper
Quote:
>At a quick glance it would appear you are doing it via errorsys trickery,
is
>this the case?

Yes, in fact. I explain it in the FAQs & Tips section in the Web.

Quote:
>years back and realised that while it works up to a point it breaks down
the
>moment you use custom error handlers.

STATIC PrevError

init FUNCTION ovlinit()
    PrevError := errorblock({|e| ovlerror(e) })
RETURN NIL

static FUNCTION ovlerror(e)
    ...
    if you recover
        RETURN ...
    endif

RETURN ( eval(PrevError,e) )        // Previous error handler!!!!!!!!

The rest its explained with demostration source code in FAQs & Tips
http://www.ctv.es/USERS/jbarreiro

Un saludo desde Mallorca.



Sun, 24 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper
With objects.lib (FiveWin) you can overload operators without using
overload.lib.

CREATE CLASS Tsomething
EXPORT:
    VAR x
    METHOD sum OPERATOR +
ENDCLASS

METHOD FUNCTION sum(a)
    ::x += a
RETURN ( self )

*Not suported operator =. If you need it, you can use overload.lib.

Saludos desde Mallorca.



Sun, 24 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
>I grabbed a copy but the source for the library was missing so it was of
>little interest. Perhaps you'd consider including the source or at least
>documenting how it works (and, indeed, how it is used, I couldn't find any
>docs for that either)?

I am still working on it, Im doing a class(y) compatible version for
overload operators.

I have an old objects.lib library with no overload operators and the last
objects.lib with overload operators but no support overload = (for example).

Saludos desde Mallorca.



Sun, 24 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
> >I grabbed a copy but the source for the library was missing so it was of
> >little interest. Perhaps you'd consider including the source or at least
> >documenting how it works (and, indeed, how it is used, I couldn't find
> >any docs for that either)?

> You can obtain a explication of how it works in the FAQs & Tips section of
> the Web.

Problem is, I don't speak Spanish, my problem, I know, but....

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Mon, 25 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
> >At a quick glance it would appear you are doing it via errorsys trickery,
> >is this the case?

> Yes, in fact. I explain it in the FAQs & Tips section in the Web.

See my previous post about my command of Spanish.

Quote:
> >years back and realised that while it works up to a point it breaks down
> >the moment you use custom error handlers.

> STATIC PrevError

> init FUNCTION ovlinit()
>     PrevError := errorblock({|e| ovlerror(e) })
> RETURN NIL

There are a couple of problems with this. The main one is that at the time
that this INIT procedure gets executed errorblock() might not yet be the
custom error handler, it isn't uncommon to set the custom error handler as
the first line of code in the first non-init function.

Even if I were to set my custom error handler using an INIT PROCEDURE there
is still no guarantee that my INIT PROCEDURE will be called before the INIT
PROCEDURE in OVERLOAD.LIB.

So, the changes are very high that 'PrevError' will contain:

   {|o| DefError( o ) }

(the default error block in a Clipper application), while errorblock()
really contains something like:

   {|o| DavesErrorHandler( o ) }

and OvlError() doesn't get a look in.

The other problem is local error handlers. It isn't uncommon to see code
like:

   Local bSavErr

   ...

   bSavErr := errorblock( {|o| break( o ) } )

   Begin Sequence
      ...
      // OVERLOAD can't be used here unless the recover block is explicit
      // about which flavor of error it handles.
      ...
   Recover Using o
      ...
   End Sequence

   errorblock( bSavErr )

Quote:
> The rest its explained with demostration source code in FAQs & Tips
> http://www.ctv.es/USERS/jbarreiro

Try this little example to see what I mean about custom error handlers:

----------------------------------------------------------------------------
#include "overload.ch"

Function Main()
Local c := "A"

   // Install my custom error handler.
   errorblock( {|o| DummyError( o ) } )

   DefOper (++) For Type "C" To {|c| CharInc( c, 1 ) }

   ? c
   ? ++c

Return( NIL )

Function CharInc( c, n )
Return( chr( asc( c ) + n ) )

Function DummyError( o )

   ? "Doh!"
   Quit

Return( NIL )
----------------------------------------------------------------------------

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Mon, 25 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
>> You can obtain a explication of how it works in the FAQs & Tips section
of
>> the Web.

>Problem is, I don't speak Spanish, my problem, I know, but....

Dont worry. I can explain it here!

In fact I use the errorsys recovery trap... but my english is not so good
(as yours) and I prefer to answer your especific questions.

Saludos desde Mallorca.



Mon, 25 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper
Try this little example to see what I mean about custom error handlers:

----------------------------------------------------------------------------
#include "overload.ch"

Function Main()
Local c := "A"

   // Install my custom error handler.
   errorblock( {|o| DummyError( o ) } )

   DefOper (++) For Type "C" To {|c| CharInc( c, 1 ) }

   ? c
   ? ++c

Return( NIL )

Function CharInc( c, n )
Return( chr( asc( c ) + n ) )

Function DummyError( o )

   ? "Doh!"
   Quit

Return( NIL )

You can Solve using your own seterrblock() function that works as I
sugested.

STATIC PrevErr

FUNCTION SetErrBlock(new)
    ...
RETURN

You can also make a translate that convert errorblock() to seterrblock() may
be a header in the "overlay.ch" ... or something in that way...

Saludos desde Mallorca.



Mon, 25 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
> In fact I use the errorsys recovery trap... but my english is not so good
> (as yours)

One thing is for sure, your English is a *lot* better than my Spanish. ;-)

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Tue, 26 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
> > [SNIP Dave's example of how custom error handlers can break an operator
> > overloading system that relies on error system trickery]

> You can Solve using your own seterrblock() function that works as I
> sugested.

> STATIC PrevErr

> FUNCTION SetErrBlock(new)
>     ...
> RETURN

> You can also make a translate that convert errorblock() to seterrblock()
> may be a header in the "overlay.ch" ... or something in that way...

Sure thing, you can work around the problem like this. However, once you
start doing this it starts to become less seamless. I'm not saying that this
is a "bad" way of doing things, just that you can't simply drop it into your
application and have it "just work".

This is the reason why I had a play with the idea myself and then gave up on
it, the hassle was greater than the perceived benefit, but it was fun to do.

IMHO the alternative method of doing this is the better one. In this case
you write some code that "hacks" Clipper's byte code interpreter and handles
operator overloading at the byte code level. I've got a funny feeling that
that is what FiveTech's OBJECTS does (at least, I think that is what Antonio
said it does, perhaps you'd like to confirm this Antonio?).

Still, all that said, OVERLOAD looks nice and I'm glad to see that you make
it freely available.

--
Take a look in Hagbard's World: |     w3ng - The WWW Norton Guide reader.
http://www.acemake.com/hagbard/ |  ng2html - The NG to HTML converter.
http://www.hagbard.demon.co.uk/ |       eg - Norton Guide reader for Linux.
Free software, including........|   dgscan - DGROUP scanner for Clipper.



Tue, 26 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper

Quote:
>IMHO the alternative method of doing this is the better one. In this case
>you write some code that "hacks" Clipper's byte code interpreter and
handles
>operator overloading at the byte code level. I've got a funny feeling that
>that is what FiveTech's OBJECTS does (at least, I think that is what
Antonio
>said it does, perhaps you'd like to confirm this Antonio?).

I think OBJECTS does the same with a low-level function called from the
modified error handler.

But I noticed that you cant overload = operator, and I dont know if there
are more operators not acepted.

OBJECTS works only with objects, overload can work with all kind of var
types.

For example, an acumulator :

LOCAL aAcum := { 0,0,0,0,0 }

do while !eof()
    aAcum += { FIELD1,FIELD2,FIELD3...}
    skip
enddo

? aAcum[1],aAcum[2]...

With objects you must define a class like this :

LOCAL oAcum := TAcum():new({0,0,0,0,0,0})

Same Loop

? oAcum:data[1],oAcum:data[2],...

Both methods works fine...

Saludos.
http://www.ctv.es/USERS/jbarreiro



Tue, 26 Dec 2000 03:00:00 GMT  
 Overloading operators with Clipper
I have finished overload.lib.

Now you can overload operators with class(y) & objects (objects 4.2 has
built-in overload operator support, but its also compatible).

I have 2 demo PRGs.

ovdemo for overload support with clipper data types ("C","N","A","D"...)
ovdemo2 for overload support with objects (class(y) & objects) the same PRG.

You can get the latest version from http://www.ctv.es/USERS/jbarreiro
documentation its also available at documentos section (Spanish, english
version coming soon!).

Un saludo desde Mallorca.
PD/ Help wanted, You dont need to speak Spanish, I will made a english
versin, but a need somebody who will supervise my "spanglish". Please send
me an email if you are interested.



Fri, 29 Dec 2000 03:00:00 GMT  
 
 [ 16 post ]  Go to page: [1] [2]

 Relevant Pages 

1. operator overloading and user definable operators.

2. Overloading logical operators and bitwise operators

3. Operator overload of base operator and compiler diagnostic

4. operator overloading

5. Errorhadler- overload operators (how to?)

6. VO: Operator overloading (babble)

7. Forth with arbitrary objects (operator overloading)

8. Overloading of arithmetic and equality operators

9. Any way to do operator overloading in Dylan?

10. Operator overloading?

11. Operator overloading?

12. ???Mindy operator overloading???

 

 
Powered by phpBB® Forum Software