Why is Python popular, while Lisp and Scheme aren't?

Neil Schemenauer nas at python.ca
Mon Nov 11 19:49:35 EST 2002


Pascal Costanza wrote:
> > (let ((*read-eval* nil))
>     (with-input-from-string (s "3.1415927")
>       (read s)))
> 3.1415927

I didn't know about *read-eval*.  Thanks for the tip.  Still:

    (defun parse-float (s)
      (let ((*read-eval* nil))
        (read-from-string s)))

    (defun doit ()
      (dotimes (i 100000)
        (parse-float "3.1415927")))

    (time (doit))

takes 1.507 seconds on my machine using SBCL.  The corresponding Python
code takes 0.19.

> (defun escape (s)
>   (with-output-to-string (out)
>     (with-input-from-string (in s)
>       (loop while (listen in)
>             do (let ((char (read-char in)))
>                  (case char
>                    (#\& (write-string "&" out))
>                    (#\< (write-string "<" out))
>                    (#\> (write-string ">" out))
>                    (#\" (write-string """ out))
>                    (otherwise (write-char char out))))))))

> * This solution is inherently more efficient because it traverses the 
> input exactly once, whereas your solution traverses the input four times.

I wouldn't say inherently.  With a 26 character string I measure the
speed of the Python code to be the same as compiled Lisp code.  Still, I
like your solution.  Obviously I need to learn more about treating
strings as streams.  Thanks.

  Neil




More information about the Python-list mailing list