Re: [Tutor] primes (Cautious remark on Python and Scheme)

2005-03-18 Thread Gregor Lingl
Hi Danny!
Preliminary remark: I know that beautiful and beauty
are concepts very seldom applied to computer programs or
programming languages. I suppose mainly because they are
to a large extent a matter of taste ...
Nevertheless: regardeless of the fact that I'm not a very
skilled scheme-programmer, for me Scheme is the most beautiful
programming language I know, mainly because of the clear
and simple concepts which are purely realized. (I do *not* want
to discuss here questions like functional versus object-oriented
languages etc...)
However - Python - for me - is a programming language for
the pragmatic lover. Do you consider this expression as
self explanatory? Lover -- because it makes so much fun
to use it. Pragmatic -- because it is a language for the
real world ;-)
im*h*o the primes - examples we are just discussing shows,
that going *the Python way* may well be more successful
or rewarding than trying to translate, traduce, ...er ..
adapt Scheme-concepts quasi trying to show that Python is
at least as good as Scheme. This is not the question. (I
suppose that this also was not your goal?) A deeper
question perhaps would be to what degree the content of
cs texts depends on the choice of the mainly used language
therein.
On the contrary - we may learn from this example that Python
is a *very* good language in its own right - with carefully chosen
concepts and syntax and a very slow, serious and publicly
controlled development process resulting in a more and more
easily and efficiently usable language.
Finally I'd like to stress that your contribution for me
was very valuable and constructive - as are most of your
innumerable contributions to the discussions on this list.
Thanks an regards,
Gregor
post scriptum: as always when writing not only about technical
facts but about opinions and values in English, I'm a bit axious
if I was able to express correctly what I wanted to say. Hmmm.
Hope that I didn't create any misunderstandings 
Danny Yoo schrieb:
On Thu, 17 Mar 2005, Gregor Lingl wrote:

Hi!
Who knows a more concise or equally concise but more efficient
expression, which returns the same result as
[x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]]

Hi Gregor,
Here is one that's traduced... er... adapted from material from the
classic textbook Structure and Interpretation of Computer Programs:
##
from itertools import ifilter, count
def notDivisibleBy(n):
... def f(x):
... return x % n != 0
... return f
...
def sieve(iterable):
... nextPrime = iterable.next()
... yield nextPrime
... restOfPrimes = sieve(ifilter(notDivisibleBy(nextPrime), iterable))
... for prime in restOfPrimes:
... yield prime
...
primes = sieve(count(2))
primes.next()
2
primes.next()
3
primes.next()
5
primes.next()
7
primes.next()
11
primes.next()
13
primes.next()
17
primes.next()
19
primes.next()
23
##
The neat thing about this code is that it produces an infinite iterator of
prime numbers.  The original code in Scheme is itself quite concise and
quite nice.  It is described here:
http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html#call_footnote_Temp_455
Best of wishes to you!

--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil:   +43 664 140 35 27
Autor von Python für Kids
Website: python4kids.net
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] primes (Cautious remark on Python and Scheme)

2005-03-18 Thread Gregor Lingl

Concerning my previous posting - perhaps it
would suffice to summarize:
While Python is a language for the pragmatic lover,
Scheme is much more fundamentalistic.
(thought-) *PROVOKING*?
Gregor
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[OT] Re: [Tutor] primes (Cautious remark on Python and Scheme)

2005-03-18 Thread Brian van den Broek
Gregor Lingl said unto the world upon 2005-03-18 19:57:
Hi Danny!
Preliminary remark: I know that beautiful and beauty
are concepts very seldom applied to computer programs or
programming languages. I suppose mainly because they are
to a large extent a matter of taste ...
Hi Gregor and all,
Though I've not had the time to follow the details of the thread 
closely, it's stored for future perusal -- I'm really glad you started 
it, Gregor.

But, your comment above caught my eye. import this to see that beauty 
is embraced by the zen :-)

It's been a long day, so I don't feel I am saying this well, but:
When not trying to learn Python, I'm a (grad student) philosopher of 
logic and mathematics. I've thought some about beauty in proof, and 
hope to think seriously about it one day. Beauty in maths is like what 
the judge said about pornography -- I can't define it, but I know it 
when I see it. I've never met a philosopher or a mathematician who 
could give a compelling (and robust) account of what makes for beauty, 
but there is widespread convergence of judgements about which proofs 
are beautiful and which ugly. (This even though taste does enter into 
it, too.)

I think the same is true of (at least academic) computer science. The 
comp sci people I know at my uni all work in automated-theorem 
proving, and I know they use their perceptions of beauty as a design 
guide. And, with my much more limited experience with programming, my 
judgements that this code is ugly have been pretty reliable in 
identifying the problematic parts. If it is beautiful, it might be 
right. If it is ugly, it is likely wrong seems a safe claim.

Anyway, all this is to say that I think that what you know above is 
wrong :-)

SNIP
post scriptum: as always when writing not only about technical
facts but about opinions and values in English, I'm a bit axious
if I was able to express correctly what I wanted to say. Hmmm.
Hope that I didn't create any misunderstandings 
Ich kann Deutsch, aber nur ein bischen. I think I'd be a very happy 
fellow if my German were half as good as your English :-)

Best to all,
Brian vdB
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor