[Edu-sig] Re: Lisp vs Scheme vs Python
Tim Peters
tim.one@home.com
Mon, 28 May 2001 16:23:28 -0400
[Kirby Urner, to Matthias]
> Yes, map(lambda x: x*2, range(10)) also works in Python.
>
> So if you prefer it, would you teach students to write it this
> way?
I'm sure he does, but not at first: if you view lists as inductively
defined recursive data structures (which he does), then you really need to
teach what all those big words <wink> *mean* first. Then map is a simple
application of those ideas, and students can implement it themselves with
full confidence in what they're doing. Once they reach that stage, cool,
just use "map" directly.
Python views lists as sequences instead, and is more concerned about making
operations transparent "at a glance" than in building them from the ground
up. From that view, in current Python the preferred way to write the above
is
[x**2 for x in range(10)]
a variant of set-builder notation borrowed from SETL via Haskell.
> I've suspicious of curricula in which the most "formally correct" way
> to do something is out of sync with the practical way of doing it.
There's nothing formally suspect about "map" in Python or Scheme --
although, strictly speaking, Scheme's "map" doesn't define the order in
which the function is applied, so there's a bunch of artificial complexity
there catering to optimized implementations. Python doesn't have anything
like that: every Python expression is exactly as slow as it looks <wink>.