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!.POSTED!not-for-mail From: Ben Bacarisse Newsgroups: comp.lang.ada Subject: Re: How to get Ada to ?cross the chasm?? Date: Sat, 05 May 2018 10:50:23 +0100 Organization: A noiseless patient Spider Message-ID: <87fu362zz4.fsf@bsb.me.uk> References: <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> <87zi1gz3kl.fsf@nightsong.com> <08bqedde7vu8h7clp2seqdrvafaobrakcl@4ax.com> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: reader02.eternal-september.org; posting-host="06cc3fb99e225248981f73482e02de52"; logging-data="8342"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Tovew07YO9nM1ti9oJe7HpXI2DmIhRwY=" Cancel-Lock: sha1:9uLVb2FZUsY91FBW42wq49id2tg= sha1:sRBGeZ3wxyA6O9nYgpCCEv/EgMM= X-BSB-Auth: 1.d9c1865061e516380820.20180505105023BST.87fu362zz4.fsf@bsb.me.uk Xref: reader02.eternal-september.org comp.lang.ada:52004 Date: 2018-05-05T10:50:23+01:00 List-Id: Dennis Lee Bieber writes: > On Fri, 4 May 2018 18:29:17 -0500, "Randy Brukardt" > declaimed the following: > >>"Paul Rubin" wrote in message >>news:87zi1gz3kl.fsf@nightsong.com... > >>> This list contains a reference to itself: >>> >>> x = 1 : 2 : 3 : x >> >>And is illegal in any reasonable programming language... ;-) >> >>> If you try to print it, you'll see "1,2,3,1,2,3,1,2,3,1,2,3..." ad >>> infinitum until you interrupt the program. It is infinitely long, but >>> occupies a finite amount of memory. >> >>If you say so. I can't see any sensible way to implement such a thing; >>indeed I would have said it was impossible to implement but apparently you >>have an example to the contrary. > > Not as a one-liner... but... > > PythonWin 2.7.13 (default, Jun 26 2017, 14:28:43) [MSC v.1500 64 bit > (AMD64)] on win32. > Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for > further copyright information. >>>> x = [1, 2, 3] >>>> x.append(x) >>>> print x > [1, 2, 3, [...]] >>>> > > Slight difference is that the entire list becomes an element, it is not > a one level sequence of repeating entities I'd say that's more than a slight difference! If you needed this in Python you could get close with >>> import itertools >>> x=[1,2,3] >>> x=itertools.cycle(x) but the result is not a list thought it is, of course, an "iterable". In Ada: type Node; type List is access Node; type Node is record N: Integer; Next: List; end record; ... H : List := new Node'(1, new Node'(2, new Node'(3, null))); ... H.Next.Next.Next := H; In C: typedef struct node { int n; struct node *next; } node; ... node *x = &(node){ 1, &(node){ 2, &(node){ 3 } } }; x->next->next->next = x; My Ada is very rusty, so there may well be much better ways to do this. -- Ben.