[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Why don't people like lisp?

William James

2/29/2016 9:24:00 PM

Alan Crowe wrote:

> There is a better way. For example, your dream language does
> pattern matching on the arguments. Add this to CL with a
> macro
>
> (defmacro def-fun-pat (name (&rest arg-pattern) &body code)
> `(defun ,name (structured-argument)
> (destructuring-bind ,arg-pattern
> structured-argument
> ,@code)))
>
> Then you can say
>
> (def-fun-pat test1 (a (b (c d) e (f)))
> (print (list a (+ c d)(funcall f b e))))


SML:

val test1 = fn (a,(b,(c,d),e,(f))) => [a,b,c,d,e,f];

test1 (0,(1,(2,3),4,(5)));
===>
[0, 1, 2, 3, 4, 5]


>
> (test1 '(foo (bar (5 7) "string" (cons))))
> => (FOO 12 (BAR . "string"))
>
> or
>
> (def-fun-pat test2 (first second third . rest)
> (print (+ first second third))
> (if (consp rest)
> (test2 rest)))
>
> (test2 '(0 1 2 3 4 5 6 7 8))
> =>
> 3
> 12
> 21
> NIL
>
> This doesn't really work. The point of having patterns in
> the argument list is to have a /different/ pattern in each
> of several definitions of the function and have the matching
> pattern invoked. destructing-bind is a bit of a let down
> here. So there is a lot of work to really add this to CL,

fun prn n = (print (Int.toString n); print "\n");

val rec test2 = fn
a::b::c::rest => (prn (a+b+c); test2 rest)
| [a,b] => prn (a*b)
| [a] => prn (a*1000)
| [] => ();

test2 [2,3,4,5];
===>
9
5000

test2 [2,3,4,8,9];
===>
9
72


--
[A]n unholy alliance of leftists, capitalists, and Zionist supremacists has
schemed to promote immigration and miscegenation with the deliberate aim of
breeding us out of existence in our own homelands.... [T]he real aim stays the
same: the biggest genocide in human history.... --- Nick Griffin
(https://www.youtube.com/watch?v=K...)