comp.lang.ada
 help / color / mirror / Atom feed
* attributes on expressions, not name
@ 2018-02-28 16:57 Mehdi Saada
  2018-02-28 17:55 ` Niklas Holsti
  0 siblings, 1 reply; 4+ messages in thread
From: Mehdi Saada @ 2018-02-28 16:57 UTC (permalink / raw)


why aren't attributes allowed on expressions ?
Like LINE'Length, assuming LINE is a function returning STRING.
That limitation is PAINFUL.
The type of an expression is always static, even when it is a class-wide type, an attribute defined for the type of that expression, will never fail. At least I can't see any case. Please tell me if I'm wrong.

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

* Re: attributes on expressions, not name
  2018-02-28 16:57 attributes on expressions, not name Mehdi Saada
@ 2018-02-28 17:55 ` Niklas Holsti
  2018-02-28 18:38   ` Alejandro R. Mosteo
  0 siblings, 1 reply; 4+ messages in thread
From: Niklas Holsti @ 2018-02-28 17:55 UTC (permalink / raw)


On 18-02-28 18:57 , Mehdi Saada wrote:
> why aren't attributes allowed on expressions ?
> Like LINE'Length, assuming LINE is a function returning STRING.

There is no such limitation.

RM 4.1.4: attribute_reference ::= prefix'attribute_designator

RM 4.1: prefix ::= name ...

RM 4.1; name ::= ... function_call ...

> The type of an expression is always static,

The type of the value returned by a function call is known only after 
compile-time overload resolution, which depends on the context of the 
expression. Applying an attribute to (the result of) a function call 
does not always provide enough context to resolve overloading.

In your example, there could be several different functions called LINE, 
some returning types to which the Length attribute could apply, and some 
returning types to which it does not apply. It is not clear which of 
these functions should be called.

If I have one function LINE return String, and another LINE return 
Integer, and try to compute LINE'Length, GNAT tells me:

func_attr.adb:22:41: ambiguous prefix for "Length" attribute

Is that the error message you get?

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


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

* Re: attributes on expressions, not name
  2018-02-28 17:55 ` Niklas Holsti
@ 2018-02-28 18:38   ` Alejandro R. Mosteo
  2018-02-28 21:36     ` Mehdi Saada
  0 siblings, 1 reply; 4+ messages in thread
From: Alejandro R. Mosteo @ 2018-02-28 18:38 UTC (permalink / raw)


On 28/02/18 18:55, Niklas Holsti wrote:
> 
> If I have one function LINE return String, and another LINE return 
> Integer, and try to compute LINE'Length, GNAT tells me:
> 
> func_attr.adb:22:41: ambiguous prefix for "Length" attribute

Recently in a similar case, GNAT even suggested to me to disambiguate 
like so:

String'(LINE)'Length

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

* Re: attributes on expressions, not name
  2018-02-28 18:38   ` Alejandro R. Mosteo
@ 2018-02-28 21:36     ` Mehdi Saada
  0 siblings, 0 replies; 4+ messages in thread
From: Mehdi Saada @ 2018-02-28 21:36 UTC (permalink / raw)


It said the same 10 minutes after. Saved me a tour in the RM.
I did solve my case with a qualified expression.

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

end of thread, other threads:[~2018-02-28 21:36 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 16:57 attributes on expressions, not name Mehdi Saada
2018-02-28 17:55 ` Niklas Holsti
2018-02-28 18:38   ` Alejandro R. Mosteo
2018-02-28 21:36     ` Mehdi Saada

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