Re: Integral and non-integral

From: Alf P. Steinbach (alfps_at_start.no)
Date: 03/09/04


Date: Tue, 09 Mar 2004 05:08:08 GMT


* alfps@start.no (Alf P. Steinbach) schriebt:
> * Rob Williscroft <rtw@freenet.REMOVE.co.uk> schriebt:
> >
> > #include <iostream>
> >
> > struct X
> > {
> > static int const value = 2;
> > };

An example of what the concept of general language rules (no special
cases), I think this is known as orthogonality, dictates is that one
should be allowed to write, in a header file,

   struct X
   {
       static double const value = 2.0;
   };

that is, one should be able to provide complete class definition in a
header file.

The question is why this is actively prohibited by the language.

Here is one in principle way the compiler could transform a fully inlined
class to something allowed by the current arbitrarily restricted language.

Except for the use of underscores this is also a transformation the
programmer can use, although a function for producing the constant
value would be much more practical for the programmer.

1) Moving definition out of class, solving syntactic problem, yielding

   struct X
   {
       static double const value;
   };

   double const value = 2.0;

2) Templatization, solving multiple definition problem, yielding

   struct __Concrete {}; // Underscores means defined by compiler.

   template< class __Dummy >
   struct __X
   {
       static double const value;
   };

   template< class __Dummy >
   double const __X<__Dummy>::value = 2.0; // Multiple defs OK, §3.2/5.

   typedef __X<__Concrete> X;

(Note: it's possible there are language details that prevent this exact
transformation for classes that are not fully inline, e.g. further rules
could have to be used for out-of-class member function definitions, but
that does not matter -- it's not as if the in-principle transformation
which demonstrates technical doability is the best practical way.)

Having performed these mechanical transformations, (1) and (2), class X is
ready for use, being defined in full in a header file, which shows that

* There seems to be no sound _technical_ reason why in-class definitions
  of arbitrarily typed static constants couldn't be or can not be allowed.

* Also, there seems to be nothing that the current arbitrary rules _prevent_
  regarding final functionality, they just make things very awkward.

And the effect could conceivably be defined by such a transformation.

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


Relevant Pages

  • Re: Source-to-source transformation: best approach?
    ... I don't know why TXL would be especially suited for source to source ... this for wide classes of language (in the sense that I have looked at ... its derivative, Stratego), and my tool, DMS. ... RecDescent for my long-term source to source transformation needs. ...
    (comp.compilers)
  • Re: SQL for presentation
    ... transformation could be done using SQL select statements. ... that you mean some language consistent with relational theory. ... HTML is a markup language. ...
    (comp.databases.theory)
  • Re: [OT] code is data
    ... it would be the best to cache the result of the transformation. ... classes using this metaclass, then both the class statement and the ... first relationship) someday, just for fun. ... Still a programming language. ...
    (comp.lang.python)
  • Re: What was Noam Chomskys contribution to *LINGUISTICS*?
    ... We have a universal grammar ... > defining a universal language U, and all real language R can be produced ... > by a transformation, one for each language, that maps sentences of U into ... A transformation takes you from "Mary kissed John" to "John was kissed ...
    (sci.lang)
  • Re: OOP and C++ and C (was Re: Dennis Ritchie -- An Appreciation)
    ... It's been said that there is a bias in C that favors arrays of structs ... struct record ... memory model, but that these are not issues specific in any way to C. ... a major overhaul of the language. ...
    (comp.lang.c)