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

Comments on SRFI-1.

This page is part of the web mail archives of SRFI 1 from before July 7th, 2015. The new archives for SRFI 1 contain all messages, not just those from before July 7th, 2015.



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