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!news4.google.com!proxad.net!feeder1-2.proxad.net!weretis.net!feeder4.news.weretis.net!news.teledata-fn.de!newsfeed.arcor.de!newsspool2.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> <1qk2k63kzh7yv$.3jgc403xcqdw$.dlg@40tude.net> <8ae8e899-9eef-4c8c-982e-bfdfc10072f1@h17g2000pri.googlegroups.com> <258zlxrv4fn6.1vszho1rtmf48$.dlg@40tude.net> <984db477-973c-4a66-9bf6-e5348c9b95f2@n19g2000prf.googlegroups.com> <5d0747cf-3226-4048-beb4-78b617fc19c9@v15g2000yqe.googlegroups.com> Date: Sun, 8 Aug 2010 13:44:48 +0200 Message-ID: NNTP-Posting-Date: 08 Aug 2010 13:44:48 CEST NNTP-Posting-Host: b5f09389.newsspool4.arcor-online.net X-Trace: DXC=`n09SK7Ege4i6K;>iZ]7634IUK[ On Sun, 08 Aug 2010 11:26:11 +0100, Simon Wright wrote: > The only caution I'd add is that, at some point, when you're reading an > S-expression from an external file and you expect the next 4 bytes to > contain an integer in binary little-endian format, S-expressions are bad, but not that bad. They have binary data encoded as hexadecimal strings. > you're going to have > to trust _something_ to have got it right; if you wrote "*(struct foo > **)((char *)whatever + bar.offset)" in C you will have to write the > equivalent in Ada. Luckily, Ada makes it difficult to write C equivalents. In Ada a "non-equivalent" could be: with Ada.Streams; use Ada.Streams; with Interfaces; use Interfaces; with Ada.Exceptions; use Ada.Exceptions; function Get (Stream : access Root_Stream_Type'Class) return Unsigned_16 is Result : Unsigned_16 := 0; begin if '#' /= Character'Input (Stream) then Raise_Exception (Syntax_Error'Identity, "Opening '#' is expected"); end if; for Octet in 0..3 loop Result := Result + Character'Pos (Character'Input (Stream)) * 2**Octet; end loop; if '#' /= Character'Input (Stream) then Raise_Exception (Syntax_Error'Identity, "Closing '#' is expected"); end if; return Result; end Get; > Unless you were going to invent a sort of checked > S-expression? (I don't get that impression!) I don't think that were an invention. The program in C or Ada that does not check the format of the input is broken to me. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de