Why is Python popular, while Lisp and Scheme aren't?
Pascal Costanza
costanza at web.de
Mon Nov 11 11:44:42 EST 2002
Andreas Leitgeb wrote:
> Maybe it's not the lisp-syntax itself, that is so ugly, but
> rather the (seemingly typical) coding-style.
>
> I quote one function from AisleRiot (game Kansas):
> " (define (button-pressed slot-id card-list)
> " (and (not (= (length card-list) 0))
> " (is-visible? (car card-list))
> " (or (= slot-id 1)
> " (> slot-id 5))))
If you are used to this kind of syntax, it's very simple. I don't know
enough Python (yet) in order to translate this, but in Java it would
look as follows.
1 boolean buttonPressed (int slotId, Vector cardList) {
2 return !(cardList.size() == 0) &&
3 cardList.get(0).isVisible() &&
4 ((slotId == 1) || (slotId > 5));
5 }
(In Java, you would need a cast in line 3 but that's not important here.)
* Here, you don't need an if-statement either.
* The complexity of understanding the two boolean expressions is the
same when you're familiar with the respective language. A Lisper would
have similar difficulties understanding the Java version.
* The expression in line 2 is odd but so it is in the Scheme version.
Line 2 should read "(cardList.size() != 0)" or better "(cardList.size()
> 0)".
Here is a slightly better version in Common Lisp. (I am more familiar
with Common Lisp than with Scheme.)
(defun button-pressed-p (slot-id card-list)
(and (not (null card-list))
(is-visible-p (first card-list))
(or (= slot-id 1)
(> slot-id 5))))
However, in Common Lisp it is very likely that is-visible-p returns nil
when passed nil as argument. Furthermore, in Common Lisp (first nil)
returns nil as well. So you could actually write the following (after
having checked that is-visible-p behaves like we expect ;).
(defun button-pressed-p (slot-id card-list)
(and (is-visible-p (first card-list))
(or (= slot-id 1)
(> slot-id 5))))
In Common Lisp, nil is used to represent both the empty list and the
boolean value false. The boolean value true is typically represented as
t, but everything else is also considered true. Scheme strictly
distinguishes between boolean values and list literals, and this makes a
lot of code more complicated than necessary.
My basic message here is that you might like Common Lisp more than
Scheme. *nudge, nudge*
Pascal
--
Pascal Costanza University of Bonn
mailto:costanza at web.de Institute of Computer Science III
http://www.pascalcostanza.de Römerstr. 164, D-53117 Bonn (Germany)
More information about the Python-list
mailing list