Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21078

Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp

Path csiph.com!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <driscoll@cs.wisc.edu>
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; 'languages,': 0.03; 'perl,': 0.05; 'subject:Python': 0.05; 'content- type:multipart/signed': 0.09; 'filename:fname piece:signature': 0.09; 'backwards.': 0.16; 'content-type:application/pgp- signature': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname:signature.asc': 0.16; 'reversed': 0.16; 'subject: \n ': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'cc:no real name:2**0': 0.21; "aren't": 0.21; 'tells': 0.21; 'subject:list': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'feb': 0.22; 'code': 0.26; 'function': 0.27; 'cc:addr:gmail.com': 0.28; 'temporary': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'least': 0.30; 'pretty': 0.31; 'pure': 0.32; 'break': 0.32; 'list': 0.32; 'there': 0.33; 'header:User-Agent:1': 0.33; 'lee': 0.34; 'rather': 0.34; 'function.': 0.34; 'occurs': 0.34; 'external': 0.35; 'list,': 0.36; 'cc:2**1': 0.36; 'page': 0.37; 'but': 0.37; 'using': 0.37; 'received:128': 0.38; 'received:192': 0.38; 'being': 0.40; 'view': 0.61; 'scheme.': 0.67; 'natural': 0.67; '29,': 0.73; 'fresh,': 0.84; 'idiom': 0.84; 'idiomatic': 0.84; 'xah': 0.84; 'subject:place': 0.91; 'subject:lang': 0.95
Date Thu, 01 Mar 2012 00:07:21 -0600
From Evan Driscoll <driscoll@cs.wisc.edu>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
MIME-Version 1.0
To Dan Stromberg <drsalists@gmail.com>
Subject Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp
References <85fa5760-68c8-41a2-9116-2489165f7ca1@j5g2000yqm.googlegroups.com> <CAGGBd_ppMdmf4OaEPp_ZAkkzGt+Y23sh3U6oUMAMGnnqLeH1Kg@mail.gmail.com>
In-Reply-To <CAGGBd_ppMdmf4OaEPp_ZAkkzGt+Y23sh3U6oUMAMGnnqLeH1Kg@mail.gmail.com>
X-Enigmail-Version 1.3.5
Content-Type multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enigEA4BABAE2B566630D4143EAF"
Cc python-list@python.org, Xah Lee <xahlee@gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.318.1330582525.3037.python-list@python.org> (permalink)
Lines 50
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1330582525 news.xs4all.nl 6962 [2001:888:2000:d::a6]:52763
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21078

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On 2/29/2012 23:05, Dan Stromberg wrote:
> 
> On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee <xahlee@gmail.com
> <mailto:xahlee@gmail.com>> wrote:
> 
>     This page tells you what's “In-place algorithm”, using {python, perl,
>     emacs lisp} code to illustrate.
> 
> Aren't in-place reversals rather non-functional?

There is one place where they're reasonably idiomatic in Lispy
languages, at least by my understanding. That occurs when you are
writing a function that returns a list and there is a natural recursive
way to build up the answer -- but backwards. The idiom then is to build
up a temporary list up backwards, then call an in-place reversal
function. (NREVERSE in Common Lisp. I thought there was a reverse! in
Scheme, but apparently not.)

This doesn't break the external view of a pure function because the list
that's being reversed is a fresh, temporary list, which is why this
idiom would even fit in pretty well in Scheme.

Evan

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp Xah Lee <xahlee@gmail.com> - 2012-02-29 20:07 -0800
  Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-01 05:01 +0000
    Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp Xah Lee <xahlee@gmail.com> - 2012-02-29 21:39 -0800
  Re: Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp Evan Driscoll <driscoll@cs.wisc.edu> - 2012-03-01 00:07 -0600
  Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp "WJ" <w_a_x_man@yahoo.com> - 2012-03-01 06:37 +0000
    Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-01 22:14 +0000
    Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp Xah Lee <xahlee@gmail.com> - 2012-03-01 14:04 -0800
      Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp Chris Angelico <rosuav@gmail.com> - 2012-03-02 18:11 +1100
        Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp Xah Lee <xahlee@gmail.com> - 2012-03-02 03:30 -0800
  Re: lang comparison: in-place algorithm for reversing a list in Perl, Python, Lisp Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-01 14:39 +0000
  Re: lang comparison: in-place algorithm for reversing a list in Perl,Python, Lisp "WJ" <w_a_x_man@yahoo.com> - 2012-03-02 07:17 +0000

csiph-web