From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,73cb216d191f0fef X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII-7-bit X-Received: by 10.68.129.38 with SMTP id nt6mr2036322pbb.8.1364265804205; Mon, 25 Mar 2013 19:43:24 -0700 (PDT) Path: q9ni25771pba.1!nntp.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!exi-in1.telstra.net!news.telstra.net!newsgate.cuhk.edu.hk!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Is this expected behavior or not Date: Thu, 21 Mar 2013 11:30:54 +0100 Organization: cbb software GmbH Message-ID: References: <11rcs3gg4taww$.bylek8fsshyz$.dlg@40tude.net> <99929f93-b80f-47c3-8a37-c81002733754@googlegroups.com> <87ec4b1d-f7cd-49a4-8cff-d44aeb76a1ad@googlegroups.com> <78103a2f-5d19-4378-b211-1917175d5694@googlegroups.com> <3p6p8k0yfly7.ctazdw7fc5so$.dlg@40tude.net> <1jtvzi1v65aqm.1k5ejsveno59f.dlg@40tude.net> <1hvv2kd9smnfx.6spgz9thd1mh$.dlg@40tude.net> <1raubw1sk48ca$.69rdgczvnnf.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Received-Bytes: 11842 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Date: 2013-03-21T11:30:54+01:00 List-Id: On Wed, 20 Mar 2013 18:57:58 -0500, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:1raubw1sk48ca$.69rdgczvnnf.dlg@40tude.net... >> On Tue, 19 Mar 2013 16:19:54 -0500, Randy Brukardt wrote: >> >>> "Dmitry A. Kazakov" wrote in message >>> news:vo941i7imo8t$.1jjjox9r1hkqa.dlg@40tude.net... >> >>>> It is well possible. Consider tag a constraint as array bounds are. Allow >>>> constraints (=discriminants) passed independently as compilers already >>>> do for array bounds. This gives you array interfaces while keeping arrays >>>> as they are, plain arrays. >>> >>> No, it's not possible. In order to solve the string problem, we have to >>> decouple the representation and the interface. But for slices, you have >>> to know the representation in order to be able to pass it meaningfully. >> >> You pass dope and reference. > > You have to know the representation of what you reference in order to access > it, even after the "dope and reference". Why? So long the dope contains the type tag, the string object is class-wide. For a class-wide object I should not care about representations. Representations to be handled after ultimate dispatch happens. The specific body will know the representation statically. >>> Moreover, the representation is not necessarily an array (UTF-8 encoding is >>> not a normal array if you are using the character interface). >> >> In the dope you have type tag to handle class-wide instances. You will >> dispatch to the body which implements indexing for UTF-8 encoded arrays of >> characters. > > If any dispatching is involved, the syntax ought to be that of a function > call. That allows indexing but not slicing. Depends on whether slicing to produce a class-wide slice object or a specific type object. I cannot tell what would be better, but in both cases slicing should be a proper operation (two operations, actually, for l- and r-values). > Even if you are willing to confuse users with implicit dispatching, you're > also talking about turning every slice reference into a loop. I don't see why. When the slice object happens to be class-wide, you have a dope with a tag, bounds and a reference to some yet-to-be-discovered representation. When the slice is specific, you have a dope with bounds and a reference to some statically known representation. >>>>> My rough proposed Root_String_Type would be an abstract tagged type, >>>> >>>> I definitely don't want strings tagged. >>> >>> Then forget it. All composite types ought to be tagged; the root of the >>> existing problem is that arrays aren't tagged. >> >> If you use "tagged" in RM sense as a class of types which a tag embedded >> into the representation, then no. That is not the problem and I don't want >> arrays to have tag. I want array interfaces and an ability to have objects >> of the type A'Class where A is an array type. The representation of >> A'Class will have tag. The representation of A will not. > > Why do you care? String objects are a lot bigger than a tag, so it can't be > a memory usage concern. The only other place it could possibly matter is > I/O. But for package like Text_IO, a tag and dispatching is exactly what you > want, and for 98% of strings, that's what they ultimately get used for. For > streaming and the like, the representation does not include the tag if you > stream a specific type. So what's the problem?? The problem is slicing and interfacing to other languages. Tagged string will require copying in and/or out each time you pass a slice to a subprogram. On top of that tagged types are by-reference which contradicts to copying. > Removing a tag from an object is an optimization; I believe every object > should have a tag and it's up to the compiler how to implement it. It's > really none of your (the programmer's) business (in the absence of > representation clauses). Only class-wide objects, you mean. Specific object need no tags and those with representation aspects shall not have it. As for considering it optimization, I really want this rather in the contract. Because the mechanism of adding some information to a class-wide object looks very promising beyond tags. We could use it on so many other cases: 1. Dimensioned values 2. Array bounds 3. Matrix dimensions 4. Storage pool reference in a pointer object ... >>> I don't think we >>> need 'Class for access types, >> >> You need them because access types shall implement "access interface." We >> need access interface for user-defined referential types. > > Ada 2012 has user-defined referential types. You can do everything you need > with plain-old tagged types. Like having it 16-bit long? I don't like when the language mandates representation of use-defined types. It looks more like a discount center. > But in any case, this is a bad idea. You don't want to explicitly handle > memory management in modern programs. Do it under the covers somewhere (like > in the containers packages); do *not* expose access types. Container libraries need to be implemented as well. I don't want to expose access type, I want referential semantics. >> And I >> want to be able to write a class-wide subprogram which would take both >> Handle and some plain access type as a parameter. > > As I said, no new code should be exposing raw access types. Something like > the container Cursor type is a much better way to handle the need for > referential semantics. But 4.1.5 does not hide access types. On the contrary it mandates access type as the discriminant. > ... >>> For someone that hates generics, why would you have so many? >> >> I have: >> >> 1. I/O modes of input, output, duplex; > > Seems like a runtime parameter, not a compile-time one. (i.e. Mode in the > I/O packages). No, it is intended for static checks. E.g. you cannot apply certain operations to an input object. >> 2. Specific values of types: Integer_n, Unsigned_n, String, Wide_String, >> IEEE_Float_n; > > Yes, of course, this is the problem that requires generics, mainly building > things like the Ada containers. > >> 3. Devices responsible to handle "registers" holding values; > > I don't see how a generic would help here. Each device instantiates its own register object types. The pattern looks like generic type Base_Type is new ... -- Some device specific base package Generic_Input_Scalar_Dimensioned_Whatever is type Device_Register_Type is new Base_Type and Input_Interface and Scalar_Interface ... with private; It is only needed because there is no MI. It also introduces some run-time overhead as it is turned upside down. Actually the device-specific stuff should have been added to some type/mode specific implementation. But that is a minor nuisance comparing to geometric explosion of packages and their instances. >> 4. Handles to registers; > > Pretty much the same as the previous. The package involved would be so small > and there would be so few of them (one for each kind of native register > type) that I'd just copy the text and do a block substitution to make a new > one. Generics would just get in the way (and add overhead on a compiler that > does sharing, like Janus/Ada). It is not so small, because it has to implement a number of operations. The problem is that there are hundreds of such generic packages containing meaningless cut-and-paste code like function Get_Name (Register : Register_Handle) return String is begin return Register.Ptr.Get_Name; end Get_Name; >> 5. Publishing value change events and monitors of; > > Maybe, if you need them to work on multiple types. Seems like a sort of > container, to me. But, again, more than one. It a multiplicator. For an input Integer_16 handle I need a monitor object which spits an Integer_16 values. Once a single generic comes inside it explodes like a particle in the collider. >> 6. Much whished, but practically impossible to do, bounded values. > > Seems like that fits under #2 (it's not possible to do these without knowing > the underlying representation, unless you're willing to make them very > expensive with tons of barely necessary exception handlers). Here again, I'd > make a package for each such type that I needed. (That's precisely how this > issue is handled in the Janus/Ada compiler -- no generics in sight.) I cannot write so many packages manually. It will be many thousands. Generics offer at least some help with code reuse. > > Here you are. On top of that there exist immense problems with explicit >> conversions which needed between, say, a handle to a duplex register, when >> an output one is expected. It is not just N instances it is also 2**N >> combinations of cross operations. > > Again, I don't see any good reason to try to separate these things. For type safety. I want that a program that tries to send a string value to a digital analogue input would not compile rather than fail at run-time [which could be extremely expensive]. It turned much harder than I thought it initially. >>> Maybe you're trying too hard to be Object-Oriented; >> >> I am trying to have it type-safe. It would be just impossible to do in Ada >> 95. In Ada 2005, which has Java interfaces, it gives what I described. Lack >> of MI, which is worked around using generics. I guess that MI would slash >> the amount of code by ten. MD would do another tenth. > > It's not worth it to be type-safe in this way. Especially as > preconditions/postconditions combined with static analysis give the same > effect (compile time checking) with 10% of the work. Even if it were compile-time it would require same representation for all involved objects. How would I do it for Unsigned_1 and String? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de