merits of Lisp vs Python

André Thieme address.good.until.2006.dec.22 at justmail.de
Fri Dec 15 13:42:34 EST 2006


William James schrieb:

I suppose that is Ruby code.
So my statement was correct when I said:
"In some languages it would look a bit cleaner, for example Ruby."

This is because it has a minimal syntax for "lambda".


> def p
>   puts "very positive"
>   "positive"
> end
> def z
>   puts "no no"
>   "zero"
> end
> def n
>   puts "very negative"
>   "negative"
> end
> def nif num, pos, zero, neg
>   send( num>0 ? pos : (num==0 ? zero : neg) )
> end

This code would work


> [0, 2.5, -8].map{|x| nif x, :p, :z, :n}

See how you move away from the idea of an if.
Here you need to say :p, :z, :n.
That is not much better as Lisps #'


> ###  Another way #####
> 
> p = proc {
>   puts "very positive"
>   "positive" }
> z = proc {
>   puts "no no"
>   "zero" }
> n = proc {
>   puts "very negative"
>   "negative" }
> def nif num, pos, zero, neg
>   ( num>0 ? pos : (num==0 ? zero : neg) ).call
> end
> 
> [0, 2.5, -8].map{|x| nif x, p, z, n}


But will this version also work this way:
[0, 2.5, -8].map{|x| nif x, "p", "z", "n"}

You can't express it like an "if" in Ruby.
In Lisp it is like an IF and represents exactly what
we think.
IF in Lisp:
(if expr
     (then-part)
     (else-part))

nif in Lisp:
(nif expr
      (positive-part)
      (zero-part)
      (negative-part))

It looks as if it were a construct directly built into Lisp.
If one wants one could even add some additional syntax, so
that it looks like:
(nif expr
      positive:
        (foo1)
        (foo2)
      zero:
        (foo3)
      negative:
        (foo4))

If you regard that idea nonsense then I suggest you to not
use Rubys if-statement anymore. But instead program your
own version "RubyIF" so that in future you have to pass all code
inside blocks to your RubyIF function. If you *really* think
that the Lisp savings are not worth it, then you would begin
with my suggestion today.


André
-- 



More information about the Python-list mailing list