[Edu-sig] Re: Lisp vs Scheme vs Python
Kirby Urner
pdx4d@teleport.com
Mon, 28 May 2001 09:51:03 -0700
> That's it. Your basic functions in a program should match the data defs.
> The only way to match induction is to use recursion. The kind of recursion
> that you know (e.g. quicksort, fractals) has little to do with data. It's
> an algorithmic technique beyond basic programming.
So in these cases (quicksort and fractals) perhaps recursion is
gratuitious, as it isn't justified by data defs. Certainly factorial
(not fractals) is just as well implemented in Python with
reduce(mul, range(1,n+1)) as with any recursive syntax.
> Loops are short-hands for linear recursions. But because there is an
> infinite way of doing linear mutual recursions among data defs, you can't
> get away with a finite number of looping constructs -- if you want to match
> data defs and program defs. You need recursion.
>
> Read HtDP (http://www.htdp.org).
I'll check into it (have before but it's been some time -- very cool
to have this book on the web). Another asset in the same category is:
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-4.html -- also
Scheme-heavy.
On the other hand I don't think computer science should be too inward-
looking. If my analogy is a conveyor belt, and/or things (objects)
moving along through a channel (pipe), and each getting operations
applied to it, then so be it. I don't require further theory to
justify using this metaphor in a program. And in the cut'n paste from
IDLE below, I vastly prefer loopit2. If theory says I should use
loopit instead, then I say we should fix the theory.
>>> def f(x): return x + 2
>>> f(3)
5
>>> mylist = range(15)
>>> def loopit(f,mylist):
if len(mylist)==0: return []
return [f(mylist[0])] + loopit(f,mylist[1:])
>>> loopit(f,mylist)
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>> loopit(f,[])
[]
>>> loopit(f,[1])
[3]
>>> def loopit2(f,mylist): return map(f,mylist)
>>> loopit2(f,mylist)
[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]
>>> loopit2(f,[])
[]
>>> loopit2(f,[1])
[3]
Kirby