comp.lang.ada
 help / color / mirror / Atom feed
* function "and"
@ 2004-10-05 18:58 Rick Santa-Cruz
  2004-10-05 19:20 ` David C. Hoos
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: Rick Santa-Cruz @ 2004-10-05 18:58 UTC (permalink / raw)


Hi,

if I wanna overload the operator "and" then why I have to use quotes?
Are there other cases when I have to use quotes?

Thanks in advance,
Rick 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
@ 2004-10-05 19:20 ` David C. Hoos
  2004-10-05 19:22 ` Frank J. Lhota
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: David C. Hoos @ 2004-10-05 19:20 UTC (permalink / raw)
  To: Rick Santa-Cruz; +Cc: comp.lang.ada@ada.eu.org

Any time you want to overload an _operator_, you must use quotes.

This distinguishes the _declaration_ of an operator from an instance
of its invocation.

----- Original Message ----- 
From: "Rick Santa-Cruz" <rick_santa_cruz75@msn.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada-france.org>
Sent: Tuesday, October 05, 2004 1:58 PM
Subject: function "and"


> Hi,
> 
> if I wanna overload the operator "and" then why I have to use quotes?
> Are there other cases when I have to use quotes?
> 
> Thanks in advance,
> Rick 
> 
> 
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada-france.org
> http://www.ada-france.org/mailman/listinfo/comp.lang.ada
> 



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
  2004-10-05 19:20 ` David C. Hoos
@ 2004-10-05 19:22 ` Frank J. Lhota
  2004-10-05 19:56 ` Jeffrey Carter
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Frank J. Lhota @ 2004-10-05 19:22 UTC (permalink / raw)


"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> wrote in message 
news:cjuqtc$pka$02$1@news.t-online.com...
> Hi,
>
> if I wanna overload the operator "and" then why I have to use quotes?
> Are there other cases when I have to use quotes?

Ada uses quotes like this for overlaoding operators. Other operators that 
can be overloaded are "<", "*", "not" and "=".

> Thanks in advance,
> Rick
> 





^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
  2004-10-05 19:20 ` David C. Hoos
  2004-10-05 19:22 ` Frank J. Lhota
@ 2004-10-05 19:56 ` Jeffrey Carter
  2004-10-05 22:38 ` John Woodruff
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Jeffrey Carter @ 2004-10-05 19:56 UTC (permalink / raw)


Rick Santa-Cruz wrote:

> if I wanna overload the operator "and" then why I have to use quotes?
> Are there other cases when I have to use quotes?

Operators are functions whose names are strings: "+", "xor", and so on. 
That's why you have to use quotes.

-- 
Jeff Carter
"We burst our pimples at you."
Monty Python & the Holy Grail
16




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
                   ` (2 preceding siblings ...)
  2004-10-05 19:56 ` Jeffrey Carter
@ 2004-10-05 22:38 ` John Woodruff
  2004-10-06  8:18 ` Martin Krischik
  2004-10-06  9:33 ` Dmitry A. Kazakov
  5 siblings, 0 replies; 7+ messages in thread
From: John Woodruff @ 2004-10-05 22:38 UTC (permalink / raw)


"Rick Santa-Cruz" <rick_santa_cruz75@msn.com> wrote in message news:<cjuqtc$pka$02$1@news.t-online.com>...
> Hi,
> 
> if I wanna overload the operator "and" then why I have to use quotes?
> Are there other cases when I have to use quotes?


Hi Rick

I've been reading your queries and benefiting from the discussions, so
I'll throw in an attempt at this one:

"And" is an operator which can be overloaded.  As such it can (unlike
other functions that are not operators) occur in an infix expression.

Operators are denoted by a few special symbols, or by reserved words,
thus are recognized in a compiler's parser.

The operators that behave like this are *, **, /, +, -, and, or, xor,
mod, rem, &, and the relationals (> and its friends).

You can overload any of these (the declaration needs to qoute the
operator name) but you can't define new operators.

John



^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
                   ` (3 preceding siblings ...)
  2004-10-05 22:38 ` John Woodruff
@ 2004-10-06  8:18 ` Martin Krischik
  2004-10-06  9:33 ` Dmitry A. Kazakov
  5 siblings, 0 replies; 7+ messages in thread
From: Martin Krischik @ 2004-10-06  8:18 UTC (permalink / raw)


Rick Santa-Cruz wrote:

> Hi,
> 
> if I wanna overload the operator "and" then why I have to use quotes?

For the same reason you have to write "operator && ()"  in C++. Just so that
the compiler knows you want to overload the operator and not write a
functions named And. Of corse C++ only has only got very few operators
using keywords (sizeof, typeof and such like) - and non can be overloaded -
soe the operator keyword comes more naturaly then the quote in Ada.

> Are there other cases when I have to use quotes?

Wherever you would use the keyword operator in C++ - thats when you want to
write a userdefined operator.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: function "and"
  2004-10-05 18:58 function "and" Rick Santa-Cruz
                   ` (4 preceding siblings ...)
  2004-10-06  8:18 ` Martin Krischik
@ 2004-10-06  9:33 ` Dmitry A. Kazakov
  5 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2004-10-06  9:33 UTC (permalink / raw)


On Tue, 5 Oct 2004 20:58:50 +0200, Rick Santa-Cruz wrote:

> if I wanna overload the operator "and" then why I have to use quotes?
> Are there other cases when I have to use quotes?

Everywhere you want to use functional notation instead of operational one.
Compare:

   X, Y : Boolean;
   ...
   if X and Y then -- operator 'and' in infix context
   ...
   if "and" (X, Y) then -- operator 'and' as a function 

Both 'and' and '"and"' refer the same thing, but in different contexts.

When you declare an operator you the only valid notation is functional, so
function "and", function "abs" etc. If 'and' were not a reserved word in
Ada, then one could also declare funny:

function and (X, Y : Boolean) return Boolean
   renames "and"; -- Not legal!

So that:

   (X and Y) = "and" (X, Y) = and (X, Y)

Nevertheless, "and"() and and() cannot be equalized, because otherwise any
unary or binary function declared would automatically become an operator,
and so kill the language grammar.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-10-06  9:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-05 18:58 function "and" Rick Santa-Cruz
2004-10-05 19:20 ` David C. Hoos
2004-10-05 19:22 ` Frank J. Lhota
2004-10-05 19:56 ` Jeffrey Carter
2004-10-05 22:38 ` John Woodruff
2004-10-06  8:18 ` Martin Krischik
2004-10-06  9:33 ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox