Operator overloading with Text labels or words

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Operator overloading with Text labels or words

noreply
It's not possible to define an operator like:

Operator AbcXyz(r : real; z1 : complex) z : complex;
begin
end;

Is it?

Has to be a symbol?

If one could use words or text as operators this might be very
interesting, although, probably a double edged sword like Lisp where you
could embed programming languages inside programming languages.

For example:

  x := 4 PLUS 4;
  writeln(x);

Prints 8..


Operator Plus(...);
begin
end;

So you just invented Cobol inside fpc or something like cobol. Bad example..
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Operator overloading with Text labels or words

Michael Van Canneyt


Hi,

You can use words.
But only words that the compiler defines. See the documentation.

Michael.

On Mon, 30 Jan 2017, Lars wrote:

> It's not possible to define an operator like:
>
> Operator AbcXyz(r : real; z1 : complex) z : complex;
> begin
> end;
>
> Is it?
>
> Has to be a symbol?
>
> If one could use words or text as operators this might be very
> interesting, although, probably a double edged sword like Lisp where you
> could embed programming languages inside programming languages.
>
> For example:
>
>  x := 4 PLUS 4;
>  writeln(x);
>
> Prints 8..
>
>
> Operator Plus(...);
> begin
> end;
>
> So you just invented Cobol inside fpc or something like cobol. Bad example..
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Operator overloading with Text labels or words

Sven Barth-2
In reply to this post by noreply

Am 30.01.2017 08:47 schrieb "Lars" <[hidden email]>:
>
> It's not possible to define an operator like:
>
> Operator AbcXyz(r : real; z1 : complex) z : complex;
> begin
> end;
>
> Is it?
>
> Has to be a symbol?

Only existing operators can be overloaded. For everything else, use a function.

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: Operator overloading with Text labels or words

Sven Barth-2
In reply to this post by Michael Van Canneyt

Am 30.01.2017 09:12 schrieb "Michael Van Canneyt" <[hidden email]>:
>
>
>
> Hi,
>
> You can use words. But only words that the compiler defines. See the documentation.

That's not what he meant. Even if one overloads operator "Less" then one still has to use it as "<".

Regards,
Sven


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal