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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,c406e0c4a6eb74ed X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!proxad.net!news.cs.univ-paris8.fr!informatik.uni-bremen.de!cs.tu-berlin.de!uni-duisburg.de!not-for-mail From: Georg Bauhaus Newsgroups: comp.lang.ada Subject: Re: ADA Popularity Discussion Request Date: Thu, 9 Sep 2004 03:01:59 +0000 (UTC) Organization: GMUGHDU Message-ID: References: <49dc98cf.0408110556.18ae7df@posting.google.com> <6F2Yc.848$8d1.621@newsread2.news.pas.earthlink.net> <413e2fbd$0$30586$626a14ce@news.free.fr> NNTP-Posting-Host: l1-hrz.uni-duisburg.de X-Trace: a1-hrz.uni-duisburg.de 1094698919 8777 134.91.1.34 (9 Sep 2004 03:01:59 GMT) X-Complaints-To: usenet@news.uni-duisburg.de NNTP-Posting-Date: Thu, 9 Sep 2004 03:01:59 +0000 (UTC) User-Agent: tin/1.5.8-20010221 ("Blue Water") (UNIX) (HP-UX/B.11.00 (9000/800)) Xref: g2news1.google.com comp.lang.ada:3525 Date: 2004-09-09T03:01:59+00:00 List-Id: Kevin Cline wrote: : If you want bounded types in C++ it's easy enough to write a template : class: True, but it is not quite the same thing, is it? You can write bounded types in C. Yet, they don't become C language types, with ISO definded semantics beyond what you'd expect for any user defined type. Does the C++ standard directly address the behavior of handwritten bounded numbers? How many lines of template code will it take to get the effect of type A is array(Some_Index_Type) of Foo;? #include struct _bint { long v; int up, lo; }; typedef struct _bint bint; // int with bounds checking static inline void throw_C_overflow() { assert(0); } bint range_checked(bint val) { if (val.lo > val.v || val.v > val.up) throw_C_overflow(); return val; } bint make_bound(int lower, int upper, int val) { return range_checked((bint){ .v = val, .up = upper, .lo = lower }); } bint multiply(bint a, bint b, bint res) { return range_checked((bint){ .v = a.v * b.v, .lo = res.lo, .up = res.up }); } void set(bint* old, int new) { (*old).v = new; range_checked(*old); } int main() { bint x = make_bound(1, 10, 3); // set(&x, 14); // try this to see the effect return multiply(x, x, x).v; } : In LISP-y languages, you would just write something like: : (defun random-index () (bound 1 10 ... ) OTOneH people complain that large C programs mimic half of Lisp. (C being a compiled language with little support for anything.) OTOtherH people suggest that Ada features be implemented in Lisp. (Ada being just a compiled language with a few nice features.) Adjust for C++ and other combinations. Now what? -- Georg