scm.mes: add list-ref.

This commit is contained in:
Jan Nieuwenhuizen 2016-07-24 17:25:03 +02:00
parent 2983578531
commit 82a89c680f
2 changed files with 7 additions and 0 deletions

View file

@ -246,6 +246,11 @@
(display rest)
(newline))
(define (list-ref lst k)
(let loop ((lst lst) (k k))
(if (= 0 k) (car lst)
(loop (cdr lst) (- k 1)))))
;; srfi-1
(define (last-pair lst)
(let loop ((lst lst))

View file

@ -290,6 +290,8 @@
(pass-if "min 1" (seq? (min 0 1) 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)))
(newline)