Add iota.

* module/mes/scm.mes: (iota): New function.
* tests/scm.test (iota, iota 0, iota -1): New tests.
This commit is contained in:
Jan Nieuwenhuizen 2016-12-20 19:25:26 +01:00
parent 641653563d
commit 8e1b25368b
3 changed files with 15 additions and 2 deletions

View File

@ -219,6 +219,10 @@
(if (= 0 k) (car lst)
(loop (cdr lst) (- k 1)))))
(define (iota n)
(if (<= n 0) '()
(append2 (iota (- n 1)) (list (- n 1)))))
;; srfi-1
(define (last-pair lst)
(let loop ((lst lst))

View File

@ -25,7 +25,7 @@
;;; Code:
(define (vector-map f v)
(list->vector (map f (vector->list v) (iota (vector-length v)))))
(list->vector (map f (iota (vector-length v)) (vector->list v))))
(define (vector-for-each f v)
(for-each f (vector->list v) (iota (vector-length v))))
(for-each f (iota (vector-length v)) (vector->list v)))

View File

@ -115,6 +115,15 @@ exit $?
;; (circular-list? x))
;; #t))
(pass-if-equal "iota"
'(0 1 2) (iota 3))
(pass-if-equal "iota 0"
'() (iota 0))
(pass-if-equal "iota -1"
'() (iota -1))
(pass-if "reverse" (sequal? (reverse '(1 2 3)) '(3 2 1)))
(pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))