From: Hoehle, Joerg-C. <Joe...@t-...> - 2002-06-19 09:03:17
|
Hi, >>(define list* (lambda R (if (null? (rest R)) (first R) (cons (first = R)=20 >>(apply list* (rest R))))))) >>BTW, Tim, your definition of list* relies on (null? (rest '()) -> #t >>which it is in Jscheme, but it is an error in Scheme in general. >I think the only time you will get (null? (rest R)) throwing=20 >an error is if >you call this as (list*) which maybe should throw an error??? I feel it would be The Right Thing when adding list* is to implement = the Common Lisp behaviour: http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_list_.h= tm#listST o list* takes at least one argument. o The last one need not be a list, i.e. (list* x y) =3D=3D (cons x y) That means, null? is not the correct end-iteration test for list*. = pair? is the correct test to continue iteration (there doesn't seem to = be the equivalent of the ATOM predicate in Scheme, which would be = needed here). I therefore propose: (define (list* elt . more) (if (pair? more) (cons elt (apply list* more)) elt)) {jsint.Closure list*[1,n] (elt . more)} : documents it needs at least = one element. > (list* 1 2 '(3 4 5)) (1 2 3 4 5) > (list* 1 3) (1 . 3) > (list* 1) 1 >But, I wonder if we should make (rest '()) and (first '()) throw = errors >instead of returning ()???? I wouldn't object. I thought the Scheme standard mandated this ("it is = an error in R5RS"). I was surprised to discover that it works in = Jscheme (I believe some of the elf/ code uses this). Regards, J=F6rg H=F6hle. BTW, I didn't check whether list* is in some SRFI on list = manipulations. |