Typed Python?
Ville Vainio
ville at spammers.com
Mon Jul 5 14:08:35 EDT 2004
>>>>> "Jacek" == Jacek Generowicz <jacek.generowicz at cern.ch> writes:
Jacek> Ville Vainio <ville at spammers.com> writes:
>> Only the academics seem to think Scheme is easier to learn
>> than, say Python or even C. Students often disagree.
Jacek> Sounds great; I bet it makes a lot of Python fans feel warm
Jacek> and fuzzy inside. Unfortunately the claim is completely
Jacek> unfounded.
Jacek> You should take a look at what the TeachScheme people have
Jacek> been doing, and what they seem to be achieving.
I took a look at the TeachScheme website. One example program in
particular caught my eye in http://www.teach-scheme.org/Talks/.
the Scheme version:
( define ( guest name list )
( cond
( ( empty? list ) ?no )
( ( equal? name ( first list )) ?yes )
( else ( guest name ( rest list )) ) ))
C/C++:
------
#include <stdio.h>
typedef struct listCell * list;
struct listCell {
int first;
list rest;
};
bool guest (int x, list l) {
if (l == NULL)
return false;
else if (x == (l -> first))
return true;
else
return guest (x, l -> rest);
}
int main (int argc, char ** argv) {
list l1, l2, l3 = NULL; int x;
l1 = (list) malloc (sizeof (struct listCell));
l2 = (list) malloc (sizeof (struct listCell));
l2 -> first = 3; l2 -> rest = l3;
l1 -> first = 2; l1 -> rest = l2;
scanf ("%d", &x);
printf ("%d\n", member (x, l1));
}
----------
So they implement a linked list data type in C/C++ version, and use
the native/natural linked list (i.e. just a list) in Scheme. That's
kinda weasely road to take, don't you think? Especially if they use
this as marketing material for non-techies...
And here's the equally weaselish Python version, which they
unsurprisingly don't include:
-----------
def guest(name, list):
return name in list
-----------
I'd like to see an example program, targeted at, say, 12 year olds,
where Scheme beats Python in simplicity (one that is not a compiler,
mind you ;-).
--
Ville Vainio http://tinyurl.com/2prnb
More information about the Python-list
mailing list