Why is Python popular, while Lisp and Scheme aren't?
Michael Hudson
mwh at python.net
Thu Nov 14 07:09:41 EST 2002
maney at pobox.com writes:
> Michael Hudson <mwh at python.net> wrote:
> > come up with it. Isn't there a pithy quote along the lines of
> > "constraints spark creativity"?
>
> Form is liberating? Though a slightly mangled old saw like "desperation is
> the mother of invention" seems more like what you're looking for. :-)
Yeah, I thought about that one, but I sem to remember another
one... oh well, doesn't matter.
> > The only biggy for me is the lack of Lisp style (with-... ) macros;
> > which of these do you prefer:
> >
> > def
>
> You got cutoff here, or the article got truncated on its way. Want to try
> again? I expect I'd enjoy seeing what you were going to say.
Ah yes, I went away to try and come up with a good example, got
distracted, and so on.
Consider this code from Python's getpass module:
old = termios.tcgetattr(fd) # a copy to save
new = old[:]
new[3] = new[3] & ~termios.ECHO # 3 == 'lflags'
try:
termios.tcsetattr(fd, termios.TCSADRAIN, new)
passwd = _raw_input(prompt)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old)
In CL if you wanted to do this sort of thing often you'd write
something like (making up interface names as I go):
(defmacro with-invisible-input (fd &body body)
(let ((old-state (gensym))
(new-state (gensym)
(fd-var (gensym)))
`(let* ((,old-state (termios:tcgetattr ,fd))
(,new-state (termios:copy-state ,old-state))
(,fd-var ,fd))
(setf (termios:lflags ,new-state)
(logior (termios:lflags ,new-state) termios:echo))
(termios:tcsetattr ,fd-var ,new-state)
(unwind-protect
,body
(termios:tcsetattr ,fd-var ,old-state))))))
which isn't exactly pretty, but now the above Python becomes:
(with-invisible-input
(funcall input-func prompt))
which *is* better.
Cheers,
M.
--
But since your post didn't lay out your assumptions, your goals,
or how you view language characteristics as fitting in with
either, you're not a *natural* candidate for embracing Design by
Contract <0.6 wink>. -- Tim Peters, giving Eiffel adoption advice
More information about the Python-list
mailing list