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,24d7acf9b853aac8 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!nntp.club.cc.cmu.edu!micro-heart-of-gold.mit.edu!newsswitch.lcs.mit.edu!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Structural unification (pattern matching) in Ada [was: Re: S-expression I/O in Ada] Date: Wed, 11 Aug 2010 15:43:03 -0400 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <547afa6b-731e-475f-a7f2-eaefefb25861@k8g2000prh.googlegroups.com> <1omt2srxtpsga$.c3hbxthzo6cf.dlg@40tude.net> <1e4cch2df5uyb.18brqdd16dhv8.dlg@40tude.net> <14y70ke8am9qw$.2csc9eflvigg.dlg@40tude.net> <4c601b5c$0$7665$9b4e6d93@newsspool1.arcor-online.net> <9czktq4ntzq7.fhbsnocx0x4w$.dlg@40tude.net> <4c6078f9$0$12500$426a74cc@news.free.fr> <4c6132d2$0$8378$426a74cc@news.free.fr> <4c61dafd$0$14549$426a74cc@news.free.fr> <4oebq9a8m8et$.gvv6eyo3umfh$.dlg@40tude.net> <4c62e31a$0$10493$426a34cc@news.free.fr> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1281555768 19432 192.74.137.71 (11 Aug 2010 19:42:48 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Wed, 11 Aug 2010 19:42:48 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:SWcNKJwC1CIA4uh7b4sbz/gdwPg= Xref: g2news1.google.com comp.lang.ada:13143 Date: 2010-08-11T15:43:03-04:00 List-Id: _FrnchFrgg_ writes: >...Just to be sure we are talking about the same thing, I read > one of you wishing Ada had a more powerful/generic "switch" construct, > and I noticed that the description of such a "switch" looked like a > subset of structural unification as you can find in most functionnal > languages. Yes, generalizing Ada case statements pushes them roughly in the direction of OCaml pattern matching, which is much more powerful. But one of my favorite features of Ada is that case statements are checked at compile time to make sure they cover all possible cases ("full coverage") and don't overlap. If I remember OCaml correctly, it doesn't do either. OCaml compilers typically warn about full coverage violations, but the language doesn't require full coverage. And overlapping is not warned about, and is commonly used (the alternatives are checked in order, and the first one wins, like an Ada if/elsif/elsif.../else chain). My problem with OCaml is that to understand a pattern, you have to understand all the preceding ones simultaneously, and negate them in your head. I don't think it's easy to get the best of both worlds (powerful pattern matching with full coverage and overlap rules). Note that "when others" in Ada turns off the full coverage rule. Similar to "_" in OCaml -- it means "none of the above". > Perhaps the current Ada is powerful enough to write some function/code > doing this switch machinery, ... Well, one could write an OCaml compiler or interpreter in Ada. ;-) >...but I was thinking it would be a new > language construct (or an extension of "switch"). "case", please. This isn't comp.lang.c. ;-) - Bob