merits of Lisp vs Python
André Thieme
address.good.until.2006.dec.22 at justmail.de
Fri Dec 15 16:06:31 EST 2006
William James schrieb:
> André Thieme wrote:
>> William James schrieb:
>>
>>> def nif num, pos, zero, neg
>>> send( num>0 ? pos : (num==0 ? zero : neg) )
>>> end
>> btw, your nif body is built out of 13 tokens, so more
>> complicated than the Python version.
>>
>>
>> André
>> --
>
> def nif num, *args
> send args[ 1 + (0 <=> num) ]
> end
send
|
|
[ ]
/ \
/ \
/ \
args +
/ \
/ \
1 ()
|
|
<=>
/ \
/ \
0 num
Okay, 9. Now it is at the complexity level of the Lisp
and Python example.
But how would a call to nif look like?
I hope it doesn't involve an extra operator to group the
args into a list or tuple. That would add more complexity to
each call - so one should better have a slightly more complex
nif because that exists only one time.
And can this nif now handle any input values, such as strings
or function objects?
The <=> is called cmp in Python.
In Lisp it is called signum. The Lisp function has in general the
advantage that it keeps type information.
While Pythons cmp returns either -1, 0 or 1 the Lisp version can
also return -1.0 and 1.0 and also complex numbers:
(signum #C(10 4)) => #C(0.9284767 0.37139067)
André
--
More information about the Python-list
mailing list