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

2012-03-02 Thread Xah Lee
Xah Lee wrote: «… One easy way to measure it is whether a programer can read and understand a program without having to delve into its idiosyncrasies. …» Chris Angelico wrote: «Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". …» they are com

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

2012-03-01 Thread WJ
Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-place Algorithm”? > > Xah Lee, 2012-02-29 > > This page tells you w

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

2012-03-01 Thread Chris Angelico
On Fri, Mar 2, 2012 at 9:04 AM, Xah Lee wrote: > One easy > way to measure it is whether a programer can read and understand a > program without having to delve into its idiosyncrasies. Neither the behavior of ints nor the behavior of IEEE floating point is a "quirk" or an "idiosyncracy". These a

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

2012-03-01 Thread Rainer Weikusat
Xah Lee writes: [...] > similarly, in perl, either one > require POSIX; floor(x/y); > the require POSIX instead of Math is a quirk. But even, floor should > really be builtin. > or > using a perl hack > int(x/y) > > all of the above are quirks. They rely on computer engineering by- > products (s

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

2012-03-01 Thread Xah Lee
On Mar 1, 7:04 am, Kaz Kylheku wrote: lisp: (floor (/ x y)) --[rewrite]--> (floor x y) Thanks for this interesting point. I don't think it's a good lang design, more of a lang quirk. similarly, in Python 2.x, x/y will work when both x and y are integers. Also, x//y works too, but that // is j

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

2012-03-01 Thread Rainer Weikusat
Xah Lee writes: [...] > # perl > # in-place algorithm for reversing a list. > > use strict; > use Data::Dumper; > use POSIX; # for “floor” > > my @listA = qw(a b c d e f g); > > my $listLength = scalar @listA; > > for ( my $i = 0; $i < floor($listLength/2); $i++ ) { > my $x = $listA[$i]; >

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

2012-02-29 Thread WJ
Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-place Algorithm”? > > Xah Lee, 2012-02-29 > > This page tells you w

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

2012-02-29 Thread Evan Driscoll
On 2/29/2012 23:05, Dan Stromberg wrote: > > On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee > 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

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

2012-02-29 Thread Xah Lee
On Feb 29, 9:01 pm, Steven D'Aprano wrote: > You don't need a temporary variable to swap two values in > Python. A better way to reverse a list using more Pythonic idioms is: > > for i in range(len(list_a)//2): >     list_a[i], list_a[-i-1] = list_a[-i-1], list_a[i] forgive me sir, but i haven't

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

2012-02-29 Thread Dan Stromberg
On Wed, Feb 29, 2012 at 8:07 PM, Xah Lee wrote: > fun example. > > in-place algorithm for reversing a list in Perl, Python, Lisp > http://xahlee.org/comp/in-place_algorithm.html > > plain text follows > > > What's “In-place Algorithm”? > > Xah Lee, 2012-02

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

2012-02-29 Thread Steven D'Aprano
On Wed, 29 Feb 2012 20:07:49 -0800, Xah Lee wrote: > Here's in-place algorithm for reversing a list: > > # python > # in-place algorithm for reversing a list > > list_a = ["a", "b", "c", "d", "e", "f", "g"] > list_length = len(list_a) > for i in range(list_length/2): > x = list_a[i] > li

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

2012-02-29 Thread Xah Lee
fun example. in-place algorithm for reversing a list in Perl, Python, Lisp http://xahlee.org/comp/in-place_algorithm.html plain text follows What's “In-place Algorithm”? Xah Lee, 2012-02-29 This page tells you what's “In-place algorithm”, using {python,