* added last-pair primitive

This commit is contained in:
Abdulaziz Ghuloum 2007-01-31 17:23:49 -05:00
parent 126b7aa8fa
commit 3c4986ff89
3 changed files with 20 additions and 0 deletions

Binary file not shown.

View File

@ -871,6 +871,23 @@ reference-implementation:
(lambda (x) (lambda (x)
(race x x x '())))) (race x x x '()))))
(primitive-set! 'last-pair
(letrec ([race
(lambda (h t ls last)
(if (pair? h)
(let ([h ($cdr h)] [last h])
(if (pair? h)
(if (not (eq? h t))
(race ($cdr h) ($cdr t) ls h)
(error 'last-pair "~s is a circular list" ls))
last))
last))])
(lambda (x)
(if (pair? x)
(let ([d (cdr x)])
(race d d x x))
(error 'last-pair "~s is not a pair" x)))))
(primitive-set! 'memq (primitive-set! 'memq
(letrec ([race (letrec ([race
(lambda (h t ls x) (lambda (h t ls x)
@ -1604,6 +1621,8 @@ reference-implementation:
(append ls ls*)]))) (append ls ls*)])))
(primitive-set! 'list->vector (primitive-set! 'list->vector
(letrec ([race (letrec ([race
(lambda (h t ls n) (lambda (h t ls n)

View File

@ -85,6 +85,7 @@
file-exists? delete-file + - add1 sub1 * / expt file-exists? delete-file + - add1 sub1 * / expt
quotient+remainder quotient remainder modulo number? positive? quotient+remainder quotient remainder modulo number? positive?
negative? zero? number->string logand = < > <= >= negative? zero? number->string logand = < > <= >=
last-pair
make-guardian weak-cons collect make-guardian weak-cons collect
interrupt-handler interrupt-handler
time-it time-it