Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; '21,': 0.07; 'python3': 0.07; 'append': 0.09; 'literal': 0.09; 'python': 0.11; 'itself.': 0.14; 'all?': 0.16; 'crashed': 0.16; 'itertools': 0.16; 'pointers.': 0.16; 'syntax,': 0.16; 'tuple': 0.16; 'tuples,': 0.16; 'wrote:': 0.18; 'import': 0.22; 'least': 0.26; 'header:In- Reply-To:1': 0.27; 'tried': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'depth': 0.31; 'fault': 0.31; 'fri,': 0.33; 'implemented': 0.33; "can't": 0.35; 'no,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'doing': 0.36; 'list': 0.37; 'nov': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'simply': 0.61; 'protection': 0.63; 'special': 0.74; 'behavior': 0.77; '2014,': 0.84; 'whereas': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=S0s205L6h1FBWyn6HgvBk6STcqD4Jub1m04KmY/x2bo=; b=vsP5wEVLtGZyK546OnTUDM3wnwb1YzdK0h0E5Ha5R6mpIe6Nc5yIDxrws5CpVlH8+u jAzhfI6gXgtAmahYt0jv4bKA5/x4sGwztIlp7lFT2i2R1vFL6RYXGsrQ7Jv+pxVgdt7Q pd4X2V7JmPZaMWWJ4lshOysfPZVPgUkBTHMhkF5CcOtL+g8f8xoVO5tglTQeBcmUeuAc PTbJiWKtLFohEcdZp9MHUY4do2Z3WQajY2tliIAXmjHiB9f7DkoPtHA1GnNo4wqgeu9C JiTywDA3WZuHS6SeIp2zMsmizQYX5GpRfZaTi+51tK1psihwhmcz+Lsk1sWD8cKH0rUi U+QA== X-Received: by 10.70.47.195 with SMTP id f3mr9724779pdn.156.1416595089833; Fri, 21 Nov 2014 10:38:09 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <1416591555.652129.193873581.54A97BD7@webmail.messagingengine.com> References: <931d12c0-12b3-4278-a9b9-1e2c32f138b3@googlegroups.com> <87bno16nsw.fsf@elektro.pacujo.net> <1416591555.652129.193873581.54A97BD7@webmail.messagingengine.com> From: Ian Kelly Date: Fri, 21 Nov 2014 11:37:29 -0700 Subject: Re: Infinitely nested containers To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1416595105 news.xs4all.nl 2836 [2001:888:2000:d::a6]:41326 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:81236 On Fri, Nov 21, 2014 at 10:39 AM, wrote: > On Fri, Nov 21, 2014, at 02:00, Marko Rauhamaa wrote: >> Gill Shen : >> >> > How is this [nesting] behavior implemented under the hood? >> >> Pointers. >> >> > And why is this allowed at all? >> >> There's no reason not to. > > There's no reason not to allow it with tuples, but you can't do it. > Mainly because doing it in a single literal would require special > syntax, whereas you can simply append to a list a reference to itself. > > I think I tried on at least one python version and printing the tuple > crashed with a recursion depth error, since it had no special protection > for this case the way list printing does. Here's a nice crash. I thought this might similarly produce a recursion depth error, but no, it's a seg fault! $ cat test.py import itertools l = [] it = itertools.chain.from_iterable(l) l.append(it) next(it) $ python3 test.py Segmentation fault (core dumped)