Re: User-defined type attributes (replacing genericity)



On Fri, 14 Mar 2008 17:58:46 +0100, Georg Bauhaus wrote:

On Fri, 2008-03-14 at 15:48 +0100, Dmitry A. Kazakov wrote:

I assume your answer to what follows will be that Ada semantics
should be put under programmer control,

What's wrong with having control over the semantics?

(Control over the semantics of the language. I'm not a compiler,
and I'm not imagining I am as good as someone who can routinely
master the advanced parts of implementing Ada in user programs.
That is what I think will be wrong.

But the compiler is in an even worse position. It cannot know your intent
when you introduce a new operation, type, object etc. It is up to you to
define the semantics of.

It is certainly possible to imagine some meta-flavoring for
Ada. But I don't want to inspect such pieces of sophistication
when they come out of the hands of ordinary programmers
and have errors. There will be at least one more
level of linguistic indirection between me and the LRM:
the programmer's language interpretation as implemented in
his semantics control.)

Sorry, but it is generics which constitute a meta language, so this
argument you should address to yourself.

Further, it seems that you believe that Ada defines some meta-level
semantics of attributes and operations like "+", "-", etc. But, it does
not. You can define "+" to perform multiplication or to act on tasks.

BUT, if you wanted to do that (I don't), then again the first step should
be away from generics, towards proper classes. For example, to define a
class of additive objects and to forbid use of "+" for anything outside the
class.

No, what you need is an interface implemented by both. You need to declare
Simple implementing Ordered. That will tell the compiler that the
predefined "<=" is an implementation of Ordered's "<=".

Actually, it doesn't matter whether "<=" is predefined. It could
just as well have been a user defined "<=". The Foo(...'Class) would
have had one one general ("generic"?) implementation of Is_Highest,
as described. This Is_Highest will have no specialization, but
it will feature highly stylized indirection, dispatching to the
implementing code for the respective "<=".

In fact, your code will not compile. It should be:

function Is_Highest (V: T'Class) return Boolean is
begin
return X <= V and then Y <= V and then Z <= V;
end Is_Highest;

So what was the problem?

Without generics, there is only one Is_Highest, as might be
expected.

Why there have to be two? The whole idea of generics was to have *one*
generic body. This is why it is called generic [programming].

I *can* have and I *did* have just one body in *source* code.

Yes this is what I meant.

We both know that Ada does not anywhere require that generics
must not yield more than one lists of object code per
generic. This would seem like a stupid restriction, one that
I think no one has wanted to put in the minds of the language
makers.

I didn't meant the implementation. Semantically there is one body even if
instantiations expand it.

If you want to constrain the dispatching table to the diagonal

I don't want that language to inflict a dispatching table
on me when that offers no advantage at all!

Dispatching table is not a physical object. It is a formal model to
describe operations defined on a class. Such polymorphic operations have
type-specific implementations (because the language is strongly typed). The
dispatching table lists them according to the order relation (subtyping) of
the types of the arguments. How and if to implement it is up to the
compiler.

- I don't need any dispatching here,

You have to. Dispatch is a selection of a type-specific body responsible
for the implementation of a generic (polymorphic) one for the given
combination of argument types. When you instantiate a generic body it is an
act of dispatching, performed manually.

- My code is more efficient without it,

It is not Ada's objective. Then with statically known types and inlined
bodies you could have the same code GNAT generics produce.

- Review of the generated code is simpler because
there are fewer indirections.

I never review generated code. I wrote large (then) programs about 20K
SLOC, now I am using Ada, I don't want back.

- There still is abstraction.

Where? In the object code?

Do not sell a limitation of generics to a
certain type of constraint as genuine advantage.

From looking at generated code, the genuine advantage seems
to be the total absence of dispatching code.

You don't need any code when dispatch is static.

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



Relevant Pages

  • Re: WaitForSingleObject() will not deadlock
    ... represent an incorrect implementation of the language. ... the *compiler* does not guarantee this. ... but to state it in terms of the execution instead of the formal semantics of the language ... as long as the optimizations do not change the semantics of the language). ...
    (microsoft.public.vc.mfc)
  • Re: User-defined type attributes (replacing genericity)
    ... What's wrong with having control over the semantics? ... (Control over the semantics of the language. ... We both know that Ada does not anywhere require that generics ...
    (comp.lang.ada)
  • lang thoughts...
    ... scripting language (largely for my own uses, but I had figured it "could" ... based, external compiler); ... language will be a mix of static and dynamic typing. ... much more confined as to what semantics can be implemented. ...
    (comp.lang.misc)
  • Re: Memory location for local C variables
    ... Yes: modify the compiler source. ... of intent", represented in some source-code language, and turning ... sequence" oriented languages like C, Pascal, Fortran, Ada, etc., ... analyzing the semantics of the sequence of "do this, ...
    (comp.lang.c)
  • Re: Compiler Correctness
    ... compiler whose correctness needs to be proved. ... correctness of the formal semantics of the source language and target ...
    (comp.compilers)