Nicer way to write folding? (list reversal?)

andrew at acooke.org andrew at acooke.org
Thu Jan 3 07:22:23 EST 2002


Michael Hudson <mwh at python.net> wrote:
[...]
> Now for some content <wink>: why are you writing these functions?
> It's not really a sensible way to program in Python.

There's two answers:

Superficial: I was manipulating paths - ended up writing an
explodePath function that calls os.path.split again and again and then
wanted to reassemble the result after processing.  Realised I needed
to fold os.path.join and started wondering about folds.

Slightly deeper: I use Python only for odds n sods, but am learning ML
with a particular (larger) task in mind.  Realised that playing with
this would hammer home the difference between the two folds and was
also curious about whether 2/2.2 was any more functional than 1.5.  I
know that Python wasn't (and apparently still isn't) intended to be
used "functionally".

Actually, Python is quite nice for playing around learning things like
this (especially now in 2.2 that scope seems to work like you'd
expect).  It's fun being able to swap between imperative and
declarative code and compare them.  Actually, after writing up to the
end of the last sentence I just rewrote that pathExplode function that
I mentioned above so that it's recursive - see what you're making me
do with your silly questions! :-)

Andrew

-- 
http://www.acooke.org



More information about the Python-list mailing list