* Added list-tail.

This commit is contained in:
Abdulaziz Ghuloum 2007-06-13 17:42:04 +03:00
parent 0c62d5bee8
commit e76047cb47
4 changed files with 20 additions and 3 deletions

Binary file not shown.

View File

@ -5,7 +5,7 @@
(import
(ikarus system $stack)
(except (ikarus) call/cf call/cc call-with-current-continuation
dynamic-wind exit))
dynamic-wind exit list-tail))
(define primitive-call/cf
(lambda (f)

View File

@ -2,13 +2,13 @@
(library (ikarus lists)
(export $memq list? list list* make-list append length list-ref reverse
last-pair memq memv member assq assv assoc
map for-each andmap ormap)
map for-each andmap ormap list-tail)
(import
(ikarus system $fx)
(ikarus system $pairs)
(except (ikarus) list? list list* make-list append reverse
last-pair length list-ref memq memv member assq assv
assoc map for-each andmap ormap))
assoc map for-each andmap ormap list-tail))
(define $memq
(lambda (x ls)
@ -96,6 +96,22 @@
(error 'list-ref "~s is not a valid index" index))
(f list index)))
(define list-tail
(lambda (list index)
(define f
(lambda (ls i)
(cond
[($fxzero? i) ls]
[(pair? ls)
(f ($cdr ls) ($fxsub1 i))]
[(null? ls)
(error 'list-tail "index ~s is out of range for ~s" index list)]
[else (error 'list-tail "~s is not a list" list)])))
(unless (and (fixnum? index) ($fx>= index 0))
(error 'list-tail "~s is not a valid index" index))
(f list index)))
(module (append)
(define reverse
(lambda (h t ls ac)

View File

@ -273,6 +273,7 @@
[cddddr i r]
[list i r]
[list-ref i r]
[list-tail i r]
[make-list i r]
[list* i]
[list? i r]