Add iota.
* module/mes/scm.mes: (iota): New function. * tests/scm.test (iota, iota 0, iota -1): New tests.
This commit is contained in:
parent
641653563d
commit
8e1b25368b
|
@ -219,6 +219,10 @@
|
||||||
(if (= 0 k) (car lst)
|
(if (= 0 k) (car lst)
|
||||||
(loop (cdr lst) (- k 1)))))
|
(loop (cdr lst) (- k 1)))))
|
||||||
|
|
||||||
|
(define (iota n)
|
||||||
|
(if (<= n 0) '()
|
||||||
|
(append2 (iota (- n 1)) (list (- n 1)))))
|
||||||
|
|
||||||
;; srfi-1
|
;; srfi-1
|
||||||
(define (last-pair lst)
|
(define (last-pair lst)
|
||||||
(let loop ((lst lst))
|
(let loop ((lst lst))
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
;;; Code:
|
;;; Code:
|
||||||
|
|
||||||
(define (vector-map f v)
|
(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)
|
(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)))
|
||||||
|
|
|
@ -115,6 +115,15 @@ exit $?
|
||||||
;; (circular-list? x))
|
;; (circular-list? x))
|
||||||
;; #t))
|
;; #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 "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))
|
(pass-if "cond-expand" (sequal? (cond-expand (foobar #f) (mes (display ": pass: *YAY*") 'mes) (guile (display ": pass: *GUILE*") 'mes)) 'mes))
|
||||||
|
|
Loading…
Reference in a new issue