comp.lang.ada
 help / color / mirror / Atom feed
* Ada Procedure Parameters That Use the Plus Sign
@ 2015-06-11 17:24 NiGHTS
  2015-06-11 17:36 ` David Botton
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: NiGHTS @ 2015-06-11 17:24 UTC (permalink / raw)


I recently stumbled across some Ada code that appends a plus sign in front of a parameter name of a function or procedure call. From the context it seems like it is doing a forced cast between two incompatible types. 

Here is one example I found in the AdaGtk demo create_tree_view.adb line 243:

Gtk_New (Tree, +Model);


My questions are:

1. What is this called? Is there a name for this?

2. What exactly is happening here?

3. Is it safe? Should it be avoided?

4. Is there another way to accomplish this without the use of '+' ?

5. Where can I find out more about this?


Thank you for your help.


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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
@ 2015-06-11 17:36 ` David Botton
  2015-06-11 18:21   ` NiGHTS
  2015-06-12  8:00 ` Dmitry A. Kazakov
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: David Botton @ 2015-06-11 17:36 UTC (permalink / raw)


Ada allows operator overloading. So look for where "+" is defined in the code.

http://www.adaic.org/resources/add_content/standards/05rm/html/RM-6-6.html

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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 17:36 ` David Botton
@ 2015-06-11 18:21   ` NiGHTS
  2015-06-11 18:52     ` David Botton
  0 siblings, 1 reply; 7+ messages in thread
From: NiGHTS @ 2015-06-11 18:21 UTC (permalink / raw)


On Thursday, June 11, 2015 at 1:36:19 PM UTC-4, David Botton wrote:
> Ada allows operator overloading. So look for where "+" is defined in the code.
> 
> http://www.adaic.org/resources/add_content/standards/05rm/html/RM-6-6.html

According to your link there are two forms of the call.

A := B + C;
A := "+"(B, C);

But in this case we are dealing with apparently one parameter, so does that mean that the first form is being used with B omitted like this... 

A := + C;

If so, is it also valid to do this?

A := C +;


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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 18:21   ` NiGHTS
@ 2015-06-11 18:52     ` David Botton
  0 siblings, 0 replies; 7+ messages in thread
From: David Botton @ 2015-06-11 18:52 UTC (permalink / raw)


Line 7 :
" The operators "+" and "-" are both unary and binary operators, and hence may be overloaded with both one- and two-parameter functions. "

A := +C;

is valid if you override the unary operator.

A := C +;

I know of know valid way to make that a legal Ada statement.


David Botton


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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
  2015-06-11 17:36 ` David Botton
@ 2015-06-12  8:00 ` Dmitry A. Kazakov
  2015-06-12  8:45 ` Jacob Sparre Andersen
  2015-06-12 15:19 ` NiGHTS
  3 siblings, 0 replies; 7+ messages in thread
From: Dmitry A. Kazakov @ 2015-06-12  8:00 UTC (permalink / raw)


On Thu, 11 Jun 2015 10:24:45 -0700 (PDT), NiGHTS wrote:

> I recently stumbled across some Ada code that appends a plus sign in front
> of a parameter name of a function or procedure call. From the context it
> seems like it is doing a forced cast between two incompatible types. 

Compatible types actually.
 
> Here is one example I found in the AdaGtk demo create_tree_view.adb line 243:
> 
> Gtk_New (Tree, +Model);
> 
> My questions are:
> 
> 1. What is this called? Is there a name for this?

In this case it is a downcast, I believe.

> 2. What exactly is happening here?

A concrete tree model is converted to the model interface. There is no
physical conversion, of course, just a reference object is converted to
another reference object. Thus from the language POV it is a conversion,
from the GTK's POV it is not.

> 3. Is it safe? Should it be avoided?

It is safe, though a quite lot irritating.

> 4. Is there another way to accomplish this without the use of '+' ?

In this concrete case there is no other way (I mean without an explicit
call) because Ada lacks the sort of MI/subtyping which would be required
for this.

In GtkAda, I think (too lazy to look), you could also use To_Interface
instead:

   Gtk_New (Tree, To_Interface (Model));

which is just same, but looks better and cleaner.

> 5. Where can I find out more about this?

Ada reference manual, GtkAda reference?

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


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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
  2015-06-11 17:36 ` David Botton
  2015-06-12  8:00 ` Dmitry A. Kazakov
@ 2015-06-12  8:45 ` Jacob Sparre Andersen
  2015-06-12 15:19 ` NiGHTS
  3 siblings, 0 replies; 7+ messages in thread
From: Jacob Sparre Andersen @ 2015-06-12  8:45 UTC (permalink / raw)


NiGHTS <nights@unku.us> writes:

> I recently stumbled across some Ada code that appends a plus sign in
> front of a parameter name of a function or procedure call. From the
> context it seems like it is doing a forced cast between two
> incompatible types.
>
> Here is one example I found in the AdaGtk demo create_tree_view.adb line 243:
>
> Gtk_New (Tree, +Model);
>
> My questions are:
>
> 1. What is this called? Is there a name for this?

Unary plus operator.

> 2. What exactly is happening here?

A function is called:

   function "+" (Item : in One_Type) return Maybe_Another_Type;

> 3. Is it safe? Should it be avoided?

Yes.  No.

> 4. Is there another way to accomplish this without the use of '+' ?

   function To_Another_Type (Item : in One_Type) return Another_Type;

   Gtk_New (Tree, To_Another_Type (Model));

> 5. Where can I find out more about this?

In the reference manual, and probably also in Ada text books.

Greetings,

Jacob
-- 
"It is very easy to get ridiculously confused about the
 tenses of time travel, but most things can be resolved
 by a sufficiently large ego."

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

* Re: Ada Procedure Parameters That Use the Plus Sign
  2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
                   ` (2 preceding siblings ...)
  2015-06-12  8:45 ` Jacob Sparre Andersen
@ 2015-06-12 15:19 ` NiGHTS
  3 siblings, 0 replies; 7+ messages in thread
From: NiGHTS @ 2015-06-12 15:19 UTC (permalink / raw)


I see so its not a special language function, its a special use of a overloaded operator. Thank you all for the clarification.


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

end of thread, other threads:[~2015-06-12 15:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-11 17:24 Ada Procedure Parameters That Use the Plus Sign NiGHTS
2015-06-11 17:36 ` David Botton
2015-06-11 18:21   ` NiGHTS
2015-06-11 18:52     ` David Botton
2015-06-12  8:00 ` Dmitry A. Kazakov
2015-06-12  8:45 ` Jacob Sparre Andersen
2015-06-12 15:19 ` NiGHTS

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