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: 103376,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!feeder1-2.proxad.net!newsfeed.straub-nv.de!noris.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: S-expression I/O in Ada Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <46866b8yq8nn$.151lqiwa0y2k6.dlg@40tude.net> <13b07f2c-2f35-43e0-83c5-1b572c65d323@y11g2000yqm.googlegroups.com> <13tpf7ya3evig$.h05p3x08059s$.dlg@40tude.net> <1omt2srxtpsga$.c3hbxthzo6cf.dlg@40tude.net> <1e4cch2df5uyb.18brqdd16dhv8.dlg@40tude.net> <14y70ke8am9qw$.2csc9eflvigg.dlg@40tude.net> <1y1c8zzqmcer5.po56hkesa968.dlg@40tude.net> <1o6jah15584x1$.1arrrgog9jdk7.dlg@40tude.net> Date: Wed, 11 Aug 2010 10:02:00 +0200 Message-ID: NNTP-Posting-Date: 11 Aug 2010 10:01:58 CEST NNTP-Posting-Host: 493c89b7.newsspool2.arcor-online.net X-Trace: DXC=V7VGemO?6VT X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:13109 Date: 2010-08-11T10:01:58+02:00 List-Id: On Tue, 10 Aug 2010 16:42:08 -0500, Randy Brukardt wrote: > "Dmitry A. Kazakov" wrote in message > news:1o6jah15584x1$.1arrrgog9jdk7.dlg@40tude.net... >> On Mon, 9 Aug 2010 20:17:40 -0500, Randy Brukardt wrote: >> >>> "Dmitry A. Kazakov" wrote in message >>> news:1y1c8zzqmcer5.po56hkesa968.dlg@40tude.net... >>> ... >>>>> For these, you don't want modular semantics -- you just want >>>>> a data type whose representation matches what you're >>>>> interfacing/communicating with, such as "type Octet is >>>>> range 0..2**8-1;" >>>> >>>> The problem is that these things require both array-of-Boolean view and >>>> arithmetic. I agree that when arithmetic is used, then it has to be >>>> wide. >>>> E.g. when interpreting sequences of octets as little/big endian numbers, >>>> we >>>> never use modular arithmetic. But integer arithmetic is incompatible >>>> with >>>> array/set view. >>> >>> What have you done with Dmitry?? You can't be the *real* Dmitry! :-) >> >> Brainwashed me? (:-)) >> >>> Array-of-bytes views and arithmetic views are of clearly different types, >>> with different sets of operations. These shouldn't be mixed, logically or >>> any other way. If you need to go between these views, you need some sort >>> of >>> type conversion (or Unchecked_Conversion or Stream'Read or...). Thus, it >>> is >>> *never* necessary to do operations on both views at once, and it is >>> irrelevant what the "math" operations for octets is. If Ada gets anything >>> wrong about this, it is that it has math operations at all for >>> stream_elements. >> >> Right, but there is no contradiction because it is more than one type >> involved. What I meant is: >> >> type Octet is ...; >> >> -- Array interface to access bits of the octet (not Ada) >> type Bit_Index is range 1..8; >> function "()" (Unit : Octet; Bit : Bit_Index) return Boolean; >> procedure "()" (Unit : in out Octet; Bit : Bit_Index; Value : Boolean); >> >> -- Arithmetic interface, immediately leads out of octets (not Ada) >> function "+" (Left, Right : Octet) return Universal_Integer; >> function "-" (Left, Right : Octet) return Universal_Integer; >> ... >> So when you write: >> >> Little_Endian_Value := Octet_1 + Octet_2 * 256; >> >> There result is not an octet, as it would be with a modular type. >> Presently >> it is just broken. > > I wouldn't mess with mixed "+" routines that return other types. I'd just > convert the Octets to a suitable type and add them. That is, any mess should > be in type conversions, not in operators. Conversion mess is what we already have right now. The point is that "+" is well-defined and meaningful for octets, but it is not closed in there. Why function "**" (Left : T; Right : Natural) return T; function S'Pos(Arg : S'Base) return universal_integer; ... are OK and "+" is not? > Since we're inventing things, I would suggest: > > -- Conversion function (Not Ada): > function "#" (Right : Octet) return Universal_Integer; > > Little_Endian_Value := #Octet_1 + #Octet_2 * 256; > > And now you don't need any Octet math. 1. What is this else? 2. I see no advantage over Little_Endian_Value := Integer (Octet_1) + Integer (Octet_2) * 256; > BTW, the "#" operator was suggested by Jean Ichbiah and others back during > the design of Ada 83, to be used for conversions between types. It's a pity > that it or something like it never made it into Ada. (It comes up each time > and still is rejected.) It would be nice to have more operators than now ("^", "|", "..", "in", ":=", "<>", "()", "[]", "{}", "<=>", "@", "~" and so on. Ah, Ada is Unicode now, here is the list: http://www.unicode.org/charts/PDF/U2200.pdf ). But what is so special in type conversions, aren't they just functions? -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de