scm.mes: add list-ref.
This commit is contained in:
parent
2983578531
commit
82a89c680f
5
scm.mes
5
scm.mes
|
@ -246,6 +246,11 @@
|
||||||
(display rest)
|
(display rest)
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
|
(define (list-ref lst k)
|
||||||
|
(let loop ((lst lst) (k k))
|
||||||
|
(if (= 0 k) (car lst)
|
||||||
|
(loop (cdr lst) (- k 1)))))
|
||||||
|
|
||||||
;; srfi-1
|
;; srfi-1
|
||||||
(define (last-pair lst)
|
(define (last-pair lst)
|
||||||
(let loop ((lst lst))
|
(let loop ((lst lst))
|
||||||
|
|
2
test.mes
2
test.mes
|
@ -290,6 +290,8 @@
|
||||||
(pass-if "min 1" (seq? (min 0 1) 0))
|
(pass-if "min 1" (seq? (min 0 1) 0))
|
||||||
(pass-if "min 2" (seq? (min 1 0 2) 0))
|
(pass-if "min 2" (seq? (min 1 0 2) 0))
|
||||||
|
|
||||||
|
(pass-if "list-ref" (seq? (list-ref '(0 1 2) 1) 1))
|
||||||
|
|
||||||
(pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
|
(pass-if "do" (sequal? (let ((acc '())) (do ((i 0 (+ i 1))) ((>= i 3)) (set! acc (cons i acc))) acc) '(2 1 0)))
|
||||||
|
|
||||||
(newline)
|
(newline)
|
||||||
|
|
Loading…
Reference in a new issue