scm.mes: add last-pair.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-23 08:17:49 +02:00
parent 119c2fef1f
commit 27ec11474b
2 changed files with 18 additions and 2 deletions

View file

@ -198,3 +198,9 @@
(let ((value (number->string counter)))
(set! counter (+ counter 1))
(string->symbol (string-append "g" value))))))
;; srfi-1
(define (last-pair lst)
(let loop ((lst lst))
(if (or (null? lst) (null? (cdr lst))) lst
(loop (cdr lst)))))

View file

@ -33,8 +33,9 @@
(#t (display ": fail") (newline) (set! fail (+ fail 1)))))))
(define (guile?) (defined? 'gc))
(if (guile?)
(module-define! (current-module) 'builtin? (lambda (. x) #t)))
(when (guile?)
(module-define! (current-module) 'builtin? (lambda (. x) #t))
(use-modules (srfi srfi-1)))
(define (seq? a b)
(or (eq? a b)
@ -224,6 +225,15 @@
((foo)))
#t))
(pass-if "last-pair " (sequal? (last-pair '(1 2 3 4)) '(4)))
(pass-if "last-pair 2" (eq? (last-pair '()) '()))
;; (pass-if "circular-list? "
;; (seq?
;; (let ((x (list 1 2 3 4)))
;; (set-cdr! (last-pair x) (cddr x))
;; (circular-list? x))
;; #t))
(newline)
(display "passed: ") (display (car (result))) (newline)
(display "failed: ") (display (cadr (result))) (newline)