scm.mes: add last-pair.
This commit is contained in:
parent
119c2fef1f
commit
27ec11474b
6
scm.mes
6
scm.mes
|
@ -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)))))
|
||||
|
|
14
test.mes
14
test.mes
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue