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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!newsfeed.xs3.de!io.xs3.de!news.jacob-sparre.dk!franka.jacob-sparre.dk!pnx.dk!.POSTED.rrsoftware.com!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: How to get Ada to ?cross the chasm?? Date: Thu, 3 May 2018 18:14:35 -0500 Organization: JSA Research & Innovation Message-ID: References: <1c73f159-eae4-4ae7-a348-03964b007197@googlegroups.com> <87k1su7nag.fsf@nightsong.com> <87po2la2qt.fsf@nightsong.com><87in8buttb.fsf@jacob-sparre.dk> <87wowqpowu.fsf@nightsong.com><16406268-83df-4564-8855-9bd0fe9caac0@googlegroups.com><87o9i2pkcr.fsf@nightsong.com> <87in88m43h.fsf@nightsong.com><87efiuope8.fsf@nightsong.com> <87lgd1heva.fsf@nightsong.com> Injection-Date: Thu, 3 May 2018 23:14:37 -0000 (UTC) Injection-Info: franka.jacob-sparre.dk; posting-host="rrsoftware.com:24.196.82.226"; logging-data="17365"; mail-complaints-to="news@jacob-sparre.dk" X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-RFC2646: Format=Flowed; Original X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 Xref: reader02.eternal-september.org comp.lang.ada:51957 Date: 2018-05-03T18:14:35-05:00 List-Id: "Paul Rubin" wrote in message news:87lgd1heva.fsf@nightsong.com... > "Randy Brukardt" writes: >> Right: "spaghetti data". Again, why is spaghetti data acceptable but >> spaghetti code not acceptable? Data with random references to other data >> is >> no more structured than code full of gotos. We never allow the latter, >> why >> allow the former?? > > Here's a complete Haskell program for printing the first 20 prime > numbers, using cyclic data (what you call "spaghetti"): > > main = print . take 20 . sieve $ [2..] where > sieve (p:xs) = p : sieve [a | a <- xs, a`rem`p /= 0] > > The idea is that sieve is a self-referential list, created by taking the > infinite list [2,3,4,5...], and yielding its first element followed by > what you get by (recursively) sieving the result of filtering out > multiples of the first element from the rest of the list. So the sieve > output is prime numbers. The program then just takes 20 elements of the > sieve output and prints them. I don't see anything "cyclic" or "self-referential" here. This is just a set of lists, and there is nothing particularly interesting about them (in partcular, there are *no* references involved in a list unless you need to keep a reference to a particular element, certainly doesn't happen here). There's no particular problem implementing an infinite list in Ada; there isn't such a container predefined but it would be relatively easy to write one. We did spend some time looking at how the Ada iteration constructs would work with such a container and we were pretty certain that they would work fine. I don't think an infinite list would do much memory allocation/deallocation -- there wouldn't be much reason to actually materialize nodes (you have to materialize the elements of course, but those are usually copied into/out of a container, so the materialization would be short-lived and local). Ada might be hamstrung here by not having useful lambas, meaning that this particular implementation probably wouldn't work. But it's hard to tell... > Obviously there are more efficient algorithms and you could code > something like the above with arrays and loops and whatnot, but the > above was very easy to write. Of course, only a high priest of programming could possibly understand what it does. (Even with your explanation, I can't quite figure how it is supposed to actually execute.) ... >... Instead it just counts upwards and tests each number. ... > > Despite that, the Ada code is still about 5x longer than the Haskell > code. Fixing the algorithm would likely bloat it by another 2x or so. I cannot imagine a sane way to implement an infinite list that would have any other effect. (For that matter, any insane way, either.) Ergo, the underlying implementation of the Haskell code has to do something like that in order to figure out the answers. (There's no free lunch. :-) > So basically it's not "spaghetti", it's having power tools and the > ability to use them. A lot of power tools should never be used by the untrained. (Think of all of the chainsaw accidents.) No one should try writing code like you have shown here - it's essentially write-only code, and virtually all code is read much more than it is written. (Assuming that your code actually gets used at all.) Ada, of course, is about readability and maintainability of the code -- the need to use tricks is always a bad thing (even when it happens in Ada.) Randy.