comp.lang.ada
 help / color / mirror / Atom feed
* Why doesn't Ada allow user-defined attributes?
@ 2017-07-20  0:02 Shark8
  2017-07-20  9:34 ` Brian Drummond
                   ` (2 more replies)
  0 siblings, 3 replies; 15+ messages in thread
From: Shark8 @ 2017-07-20  0:02 UTC (permalink / raw)


While reading up on VHDL I found out about its user-defined attributes and got to wondering why Ada doesn't have them. I can see how restricting them to those defined in the standard can keep the code "clean" and certainly [mostly] uniform... though the allowance of implementation-defined attributes undermines the last portion of that argument. -- Does anyone know?


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20  0:02 Why doesn't Ada allow user-defined attributes? Shark8
@ 2017-07-20  9:34 ` Brian Drummond
  2017-07-20 16:07   ` Shark8
  2017-07-20 18:53 ` Randy Brukardt
  2017-07-20 23:58 ` Matt Borchers
  2 siblings, 1 reply; 15+ messages in thread
From: Brian Drummond @ 2017-07-20  9:34 UTC (permalink / raw)


On Wed, 19 Jul 2017 17:02:35 -0700, Shark8 wrote:

> While reading up on VHDL I found out about its user-defined attributes
> and got to wondering why Ada doesn't have them. I can see how
> restricting them to those defined in the standard can keep the code
> "clean" and certainly [mostly] uniform... though the allowance of
> implementation-defined attributes undermines the last portion of that
> argument. -- Does anyone know?

What would they be used for?

Apart from Read and Write attributes for streaming objects, which are 
user ... overrideable, rather than defineable.

In VHDL, user defined attributes don't normally affect the design in any 
tangible way, they are normally used to pass information to tools, such 
as synthesis or backend tools, for purposes outside the language's remit 
(such as setting voltage standards on I/O pins).

Offhand I'm not sure I can see similar purposes for extending Ada's 
attributes. 

Got any use cases in mind?

-- Brian


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20  9:34 ` Brian Drummond
@ 2017-07-20 16:07   ` Shark8
  2017-07-21  4:46     ` Georg Bauhaus
  0 siblings, 1 reply; 15+ messages in thread
From: Shark8 @ 2017-07-20 16:07 UTC (permalink / raw)


On Thursday, July 20, 2017 at 3:38:52 AM UTC-6, Brian Drummond wrote:
> 
> Offhand I'm not sure I can see similar purposes for extending Ada's 
> attributes. 
> 
> Got any use cases in mind?

Yes; several.

First, considering this diagram of types in Ada -- https://upload.wikimedia.org/wikipedia/commons/c/c2/Ada_types.png -- as well as the descriptions in the LRM (Annex A in LRM-83, Annex K.2 in LRM-2012), it seems like grouping these into a hierarchy as shown in the picture might be a good thing. (That wouldn't necessarily necessitate user-defined attributes... but making such a hierarchy w/o allowing user-defined attributes seems unlikely.)

Second, and more intimidate, would be allowing Ada.Containers to implement a full Array interface, where appropriate. (e.g. having Vector'Length and Vector'Range; this consistency of interface will be nice as then you wouldn't have to remember "I'm using a vector, I have to use V.Length *not* V'Length.")


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20  0:02 Why doesn't Ada allow user-defined attributes? Shark8
  2017-07-20  9:34 ` Brian Drummond
@ 2017-07-20 18:53 ` Randy Brukardt
  2017-07-20 23:58 ` Matt Borchers
  2 siblings, 0 replies; 15+ messages in thread
From: Randy Brukardt @ 2017-07-20 18:53 UTC (permalink / raw)


I recall we considered this once, or maybe even twice. You can probably find 
some discussion in the development of Ada 2005 (that is, in the Ada 95 AIs) 
and the associated minutes. I don't really remember what the issues were and 
I have too much to do today to spend time looking it up for you. Good 
luck... - Randy

"Shark8" <onewingedshark@gmail.com> wrote in message 
news:f8aceb25-018f-4248-bc1b-d3a145108e93@googlegroups.com...
While reading up on VHDL I found out about its user-defined attributes and 
got to wondering why Ada doesn't have them. I can see how restricting them 
to those defined in the standard can keep the code "clean" and certainly 
[mostly] uniform... though the allowance of implementation-defined 
attributes undermines the last portion of that argument. -- Does anyone 
know? 


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20  0:02 Why doesn't Ada allow user-defined attributes? Shark8
  2017-07-20  9:34 ` Brian Drummond
  2017-07-20 18:53 ` Randy Brukardt
@ 2017-07-20 23:58 ` Matt Borchers
  2017-07-21  7:14   ` Simon Wright
  2 siblings, 1 reply; 15+ messages in thread
From: Matt Borchers @ 2017-07-20 23:58 UTC (permalink / raw)


I don't think I ever thought of a great user defined attribute but I do recall wishing that some other attributes could be overloaded.  For example, a linked list implementation where 'First could be overloaded to return the head pointer, 'Last to return the tail pointer, and 'Length to return the number of elements in the list.  These attributes are only usable on scalar types and arrays so it would be mildly useful to use them in other contexts.  In reality, however, the attributes would just be another notation for calling the function that was defined to do the overload so it doesn't make much sense. However, if the implementing function can be hidden so that the only interface was the attributes, that would be better.

I'm a little bit disappointed that when you do overload the 'Read, 'Write, 'Input, and 'Output attributes on a tagged type that the functions have to be visible in the package specification giving the user of the package the option to use the attributes or just call the functions themselves.  This seems unfortunate since it gives the user the ability to be inconsistent.  If this is not true, please let me know.

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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20 16:07   ` Shark8
@ 2017-07-21  4:46     ` Georg Bauhaus
  2017-07-21  7:08       ` Dmitry A. Kazakov
  0 siblings, 1 reply; 15+ messages in thread
From: Georg Bauhaus @ 2017-07-21  4:46 UTC (permalink / raw)


Shark8 <onewingedshark@gmail.com> wrote:
> On Thursday, July 20, 2017 at 3:38:52 AM UTC-6, Brian Drummond wrote:
>> 
>> Offhand I'm not sure I can see similar purposes for extending Ada's 
>> attributes. 
>> 
>> Got any use cases in mind?
> 
> Yes; several.
> 
> 
> Second, and more intimidate, would be allowing Ada.Containers to
> implement a full Array interface, where appropriate. (e.g. having
> Vector'Length and Vector'Range; this consistency of interface will be
> nice as then you wouldn't have to remember "I'm using a vector, I have to
> use V.Length *not* V'Length.")
> 

Do you really need 'Length?
It seems an implementation detail whenever the language doesn't have forall
or exists.
So, I'd rather want to use arrays with the generalized iteration scheme.
(Granted, I don't need to write Binary Search etc.)

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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-21  4:46     ` Georg Bauhaus
@ 2017-07-21  7:08       ` Dmitry A. Kazakov
  2017-07-21 17:11         ` Georg Bauhaus
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2017-07-21  7:08 UTC (permalink / raw)


On 21/07/2017 06:46, Georg Bauhaus wrote:

> Do you really need 'Length?

Sure, when for example the result depends on the number of elements. 
'Length is a general property of any container (set).

> It seems an implementation detail whenever the language doesn't have forall
> or exists.

Enumeration requires some additional assumptions, stronger than length.

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


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-20 23:58 ` Matt Borchers
@ 2017-07-21  7:14   ` Simon Wright
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Wright @ 2017-07-21  7:14 UTC (permalink / raw)


Matt Borchers <mattborchers@gmail.com> writes:

> I'm a little bit disappointed that when you do overload the 'Read,
> 'Write, 'Input, and 'Output attributes on a tagged type that the
> functions have to be visible in the package specification giving the
> user of the package the option to use the attributes or just call the
> functions themselves.  This seems unfortunate since it gives the user
> the ability to be inconsistent.  If this is not true, please let me
> know.

They can be in the private part. For example, see the end of this from
the Booch Components:

https://sourceforge.net/p/booch95/code/ci/default/tree/src/bc-support-bounded.ads


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-21  7:08       ` Dmitry A. Kazakov
@ 2017-07-21 17:11         ` Georg Bauhaus
  2017-07-21 19:39           ` Dmitry A. Kazakov
  0 siblings, 1 reply; 15+ messages in thread
From: Georg Bauhaus @ 2017-07-21 17:11 UTC (permalink / raw)


Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
> On 21/07/2017 06:46, Georg Bauhaus wrote:
> 
>> Do you really need 'Length?
> 
> Sure, when for example the result depends on the number of elements. 

Count is computed easily, albeit inefficiently, or even efficiently
whenever a collection type caches its number of elements.
So, is 'Length, if not a static property, more than a prim op?

> 'Length is a general property of any container (set).
> 
>> It seems an implementation detail whenever the language doesn't have forall
>> or exists.
> 
> Enumeration requires some additional assumptions, stronger than length.

What real thing can be counted yet not one by one?


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-21 17:11         ` Georg Bauhaus
@ 2017-07-21 19:39           ` Dmitry A. Kazakov
  2017-07-22 16:33             ` G.B.
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2017-07-21 19:39 UTC (permalink / raw)


On 2017-07-21 19:11, Georg Bauhaus wrote:
> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>> On 21/07/2017 06:46, Georg Bauhaus wrote:
>>
>>> Do you really need 'Length?
>>
>> Sure, when for example the result depends on the number of elements.
> 
> Count is computed easily, albeit inefficiently, or even efficiently
> whenever a collection type caches its number of elements.
> So, is 'Length, if not a static property, more than a prim op?
> 
>> 'Length is a general property of any container (set).
>>
>>> It seems an implementation detail whenever the language doesn't have forall
>>> or exists.
>>
>> Enumeration requires some additional assumptions, stronger than length.
> 
> What real thing can be counted yet not one by one?

Unordered set cannot be enumerated, should have no operations for it. 
Lots of external things cannot be, e.g. a file you have no permission to 
read. Lots of volatile things, e.g. a result set, a stream with its 
length in front of it etc, things you can traverse only once.

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

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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-21 19:39           ` Dmitry A. Kazakov
@ 2017-07-22 16:33             ` G.B.
  2017-07-22 20:12               ` Dmitry A. Kazakov
  0 siblings, 1 reply; 15+ messages in thread
From: G.B. @ 2017-07-22 16:33 UTC (permalink / raw)


On 21.07.17 21:39, Dmitry A. Kazakov wrote:
> On 2017-07-21 19:11, Georg Bauhaus wrote:
>> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>>> On 21/07/2017 06:46, Georg Bauhaus wrote:
>>>
>>>> Do you really need 'Length?
>>>
>>> Sure, when for example the result depends on the number of elements.
>>
>> Count is computed easily, albeit inefficiently, or even efficiently
>> whenever a collection type caches its number of elements.
>> So, is 'Length, if not a static property, more than a prim op?
>>
>>> 'Length is a general property of any container (set).
>>>
>>>> It seems an implementation detail whenever the language doesn't have forall
>>>> or exists.
>>>
>>> Enumeration requires some additional assumptions, stronger than length.
>>
>> What real thing can be counted yet not one by one?
>
> Unordered set cannot be enumerated,

https://en.wikipedia.org/wiki/Enumeration

> Lots of external things cannot be, e.g. a file you have no permission to read.

A file needs to have been _counted_ byte by byte,
or allocated using a known _count_ of bytes, etc.
in order to have this length.
Permissions don't change this state of affairs.


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-22 16:33             ` G.B.
@ 2017-07-22 20:12               ` Dmitry A. Kazakov
  2017-07-23  6:41                 ` G.B.
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2017-07-22 20:12 UTC (permalink / raw)


On 2017-07-22 18:33, G.B. wrote:
> On 21.07.17 21:39, Dmitry A. Kazakov wrote:
>> On 2017-07-21 19:11, Georg Bauhaus wrote:
>>> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>>>> On 21/07/2017 06:46, Georg Bauhaus wrote:
>>>>
>>>>> Do you really need 'Length?
>>>>
>>>> Sure, when for example the result depends on the number of elements.
>>>
>>> Count is computed easily, albeit inefficiently, or even efficiently
>>> whenever a collection type caches its number of elements.
>>> So, is 'Length, if not a static property, more than a prim op?
>>>
>>>> 'Length is a general property of any container (set).
>>>>
>>>>> It seems an implementation detail whenever the language doesn't 
>>>>> have forall
>>>>> or exists.
>>>>
>>>> Enumeration requires some additional assumptions, stronger than length.
>>>
>>> What real thing can be counted yet not one by one?
>>
>> Unordered set cannot be enumerated,
> 
> https://en.wikipedia.org/wiki/Enumeration

The sixth word there.

>> Lots of external things cannot be, e.g. a file you have no permission 
>> to read.
> 
> A file needs to have been _counted_ byte by byte,
> or allocated using a known _count_ of bytes, etc.
> in order to have this length.

No. File length is an attribute of a file. You don't need to read file 
or to allocate it. You can try it yourself, take an uncompressed movie 
file. Reading 4GB takes a *lot* of time, yet file manager shows its size 
instantly.

> Permissions don't change this state of affairs.

They prevent reading the file.

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

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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-22 20:12               ` Dmitry A. Kazakov
@ 2017-07-23  6:41                 ` G.B.
  2017-07-23  8:22                   ` Dmitry A. Kazakov
  0 siblings, 1 reply; 15+ messages in thread
From: G.B. @ 2017-07-23  6:41 UTC (permalink / raw)


On 22.07.17 22:12, Dmitry A. Kazakov wrote:
> On 2017-07-22 18:33, G.B. wrote:
>> On 21.07.17 21:39, Dmitry A. Kazakov wrote:
>>> On 2017-07-21 19:11, Georg Bauhaus wrote:
>>>> Dmitry A. Kazakov <mailbox@dmitry-kazakov.de> wrote:
>>>>> On 21/07/2017 06:46, Georg Bauhaus wrote:
>>>>>
>>>>>> Do you really need 'Length?
>>>>>
>>>>> Sure, when for example the result depends on the number of elements.
>>>>
>>>> Count is computed easily, albeit inefficiently, or even efficiently
>>>> whenever a collection type caches its number of elements.
>>>> So, is 'Length, if not a static property, more than a prim op?
>>>>
>>>>> 'Length is a general property of any container (set).
>>>>>
>>>>>> It seems an implementation detail whenever the language doesn't have forall
>>>>>> or exists.
>>>>>
>>>>> Enumeration requires some additional assumptions, stronger than length.
>>>>
>>>> What real thing can be counted yet not one by one?
>>>
>>> Unordered set cannot be enumerated,
>>
>> https://en.wikipedia.org/wiki/Enumeration
>
> The sixth word there.

A set's listing is different from the set---it's a name.
But a count of a set's listing also happens to return
the set's number of elements.
An order established by counting is not a property of the set it self,
but may involve listing it somehow. A specific ordering is not needed
for counting.

>>> Lots of external things cannot be, e.g. a file you have no permission to read.
>>
>> A file needs to have been _counted_ byte by byte,
>> or allocated using a known _count_ of bytes, etc.
>> in order to have this length.
>
> No. File length is an attribute of a file. You don't need to read file or to allocate it.

Someone or something must have established the count by,
well, counting. Otherwise no file can meaningfully have
that attribute (length) in the first place!


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-23  6:41                 ` G.B.
@ 2017-07-23  8:22                   ` Dmitry A. Kazakov
  2017-07-24 17:52                     ` G.B.
  0 siblings, 1 reply; 15+ messages in thread
From: Dmitry A. Kazakov @ 2017-07-23  8:22 UTC (permalink / raw)


On 2017-07-23 08:41, G.B. wrote:

> An order established by counting is not a property of the set it self,
> but may involve listing it somehow.

How exactly.

> A specific ordering is not needed for counting.

Not specific but some, any ordering is required. There is none. Full stop.

>>>> Lots of external things cannot be, e.g. a file you have no 
>>>> permission to read.
>>>
>>> A file needs to have been _counted_ byte by byte,
>>> or allocated using a known _count_ of bytes, etc.
>>> in order to have this length.
>>
>> No. File length is an attribute of a file. You don't need to read file 
>> or to allocate it.
> 
> Someone or something must have established the count by,
> well, counting.

It does not matter (even if it were true).

> Otherwise no file can meaningfully have
> that attribute (length) in the first place!

Surely it can. There is a system call "set file length". Get sources, 
look at the implementation. No counting there.

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


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

* Re: Why doesn't Ada allow user-defined attributes?
  2017-07-23  8:22                   ` Dmitry A. Kazakov
@ 2017-07-24 17:52                     ` G.B.
  0 siblings, 0 replies; 15+ messages in thread
From: G.B. @ 2017-07-24 17:52 UTC (permalink / raw)


On 23.07.17 10:22, Dmitry A. Kazakov wrote:
> is required

is established

No woman is of any age, because no one is allowed
to tell.  So, having user defined 'Length is ...



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

end of thread, other threads:[~2017-07-24 17:52 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-20  0:02 Why doesn't Ada allow user-defined attributes? Shark8
2017-07-20  9:34 ` Brian Drummond
2017-07-20 16:07   ` Shark8
2017-07-21  4:46     ` Georg Bauhaus
2017-07-21  7:08       ` Dmitry A. Kazakov
2017-07-21 17:11         ` Georg Bauhaus
2017-07-21 19:39           ` Dmitry A. Kazakov
2017-07-22 16:33             ` G.B.
2017-07-22 20:12               ` Dmitry A. Kazakov
2017-07-23  6:41                 ` G.B.
2017-07-23  8:22                   ` Dmitry A. Kazakov
2017-07-24 17:52                     ` G.B.
2017-07-20 18:53 ` Randy Brukardt
2017-07-20 23:58 ` Matt Borchers
2017-07-21  7:14   ` Simon Wright

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