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=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a3471634bf10bf8d X-Google-Attributes: gid103376,public From: eachus@spectre.mitre.org (Robert I. Eachus) Subject: Re: private type discriminants ignored? Date: 1998/05/06 Message-ID: #1/1 X-Deja-AN: 350972722 References: <35468F93.C371940@hso.link.com> <199804301352.PAA20159@basement.replay.com> <6ib6t4$63f$1@goanna.cs.rmit.edu.au> Distribution: world Organization: The Mitre Corp., Bedford, MA. Newsgroups: comp.lang.ada Date: 1998-05-06T00:00:00+00:00 List-Id: In article <6ib6t4$63f$1@goanna.cs.rmit.edu.au> Dale Stanbrough writes: > It seems from the preceeding set of rules about discriminants that > they too are a complicated morrass. Are discriminants really that > useful to be worth the effort? I look at all the rules (in the LRM) > for them, and the code in Gnat, and it seems there is a lot of work > trying to get them right. Perhaps I don't write the sort of code > that they were intended to make simple, but I've rarely found them > that useful. There are several different cases that individually very useful. For example, record types containing arrays whose bounds depend on a discriminant with defaults. (Whew!) We really need a name for those. They allow you to create types which correspond to char(N) varying in PL/I: subtype Index is Integer range 0..100; type VString(Size: Index := 0) is record Value: String(1..Size); end record; Objects of type VString can contain strings of different sizes: V: VString; ... V := (6,"String"); V := (27, "This is a test of VStrings.") Of course, instead of counting and using aggregates, you provide operations for the type that do all that for you: V := + "This is a much longer string to assign to V."; By the way, in Ada 95, there is a package for varying strings. But 1) the above allows the package body to be written in Ada. and 2) you occaisionally need this feature for types other than strings. -- Robert I. Eachus with Standard_Disclaimer; use Standard_Disclaimer; function Message (Text: in Clever_Ideas) return Better_Ideas is...