[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Comments on SRFI-1.



I wrote:

> (define (list-split n l)
>   (define (helper index before after)
>     (cond
>       ((null? after) (error 'list-split
> 		       "list ~s too small to be split at position ~s"
> 		       l n))
>       ((= index 0) (values (reverse before) after))
>       (else (helper (sub1 index) (cons (car after) before) (cdr after)))))
>   (cond
>     ((< n 0) (error 'list-split "index ~s must be >= 0" n))
>     (else (helper n '() l))))

Oh, I just noticed that this demands a non-empty list argument.  I
guess you could define things either way, but a more forgiving
implementation would swap the first two clauses of the cond.

'shriram