Python syntax in Lisp and Scheme

Grzegorz Chrupala grzegorz at pithekos.net
Sat Oct 4 03:17:30 EDT 2003


jcb at iteris.com (MetalOne) wrote in message news:<92c59a2c.0310031345.57d20631 at posting.google.com>...
> Scheme
> (define vector-fill!
>   (lambda (v x)
>     (let ((n (vector-length v)))
>       (do ((i 0 (+ i 1)))
>           ((= i n))
>           (vector-set! v i x)))))
> 
> Python
> def vector_fill(v, x):
>     for i in range(len(v)):
>         v[i] = x
> 
> To me the Python code is easier to read, and I can't possibly fathom
> how somebody could think the Scheme code is easier to read.  It truly
> boggles my mind.

Pick a construct your pet language has specialized support, write an
ugly equivalent in a language that does not specifically support it
and you have proved your pet language to be superior to the other
language. (I myself have never used the "do" macro in Scheme and my
impression is few people do. I prefer "for-each", named "let" or the
CL-like "dotimes" for looping).
The point is if you want you can easily implement something like
"range" in Scheme (as shown by other posters). It would be more
illustrative choose an area where one of the languages is inherently
underpowered. For example I was shocked at how awkward Paul Graham's
"accumulator generator" snippet is in Python:

class foo:
                        def __init__(self, n):
                            self.n = n
                        def __call__(self, i):
                            self.n += i
                            return self.n


> If a set of macros could be written to improve LISP syntax, then I
> think that might be an amazing thing.  An interesting question to me
> is why hasn't this already been done.

There are libraries that let you write Scheme in Python-like
indentation syntax (<URL:http://cliki.tunes.org/Scheme>, look for
Alternative Syntaxes). However, they are not widely used.

Cheers,
--
Grzegorz




More information about the Python-list mailing list