Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21078
| Date | 2012-03-01 00:07 -0600 |
|---|---|
| From | Evan Driscoll <driscoll@cs.wisc.edu> |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.318.1330582525.3037.python-list@python.org> (permalink) |
[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 | Next — Previous in thread | Next in thread | Find similar | Unroll 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