mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Added for-each functions
This commit is contained in:
parent
772fcc24f9
commit
bef1f7141c
2 changed files with 11 additions and 0 deletions
|
@ -48,6 +48,7 @@
|
||||||
vector->list
|
vector->list
|
||||||
vector->string
|
vector->string
|
||||||
vector-map
|
vector-map
|
||||||
|
vector-for-each
|
||||||
make-string
|
make-string
|
||||||
string
|
string
|
||||||
string-copy
|
string-copy
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
string->list
|
string->list
|
||||||
string->vector
|
string->vector
|
||||||
string-map
|
string-map
|
||||||
|
string-for-each
|
||||||
make-parameter
|
make-parameter
|
||||||
current-output-port
|
current-output-port
|
||||||
current-input-port
|
current-input-port
|
||||||
|
@ -266,8 +268,12 @@
|
||||||
(loop start)))
|
(loop start)))
|
||||||
(define (string-map func str)
|
(define (string-map func str)
|
||||||
(list->string (map func (string->list str))))
|
(list->string (map func (string->list str))))
|
||||||
|
(define (string-for-each func str)
|
||||||
|
(for-each func (string->list str)))
|
||||||
(define (vector-map func vec)
|
(define (vector-map func vec)
|
||||||
(list->vector (map func (vector->list vec))))
|
(list->vector (map func (vector->list vec))))
|
||||||
|
(define (vector-for-each func vec)
|
||||||
|
(for-each func (vector->list vec)))
|
||||||
(define (vector-append . vecs)
|
(define (vector-append . vecs)
|
||||||
(list->vector
|
(list->vector
|
||||||
(apply append (map vector->list vecs))))
|
(apply append (map vector->list vecs))))
|
||||||
|
|
|
@ -148,6 +148,11 @@
|
||||||
(define a "12345")
|
(define a "12345")
|
||||||
(define b (string-copy "abcde"))
|
(define b (string-copy "abcde"))
|
||||||
(assert:equal "string-copy!" (string-copy! b 1 a 0 2) "a12de")
|
(assert:equal "string-copy!" (string-copy! b 1 a 0 2) "a12de")
|
||||||
|
(let ((v '()))
|
||||||
|
(string-for-each
|
||||||
|
(lambda (c) (set! v (cons (char->integer c) v)))
|
||||||
|
"abcde")
|
||||||
|
(assert:equal "string-for-each" v '(101 100 99 98 97)))
|
||||||
|
|
||||||
;; Recursion example:
|
;; Recursion example:
|
||||||
(letrec ((fnc (lambda (i)
|
(letrec ((fnc (lambda (i)
|
||||||
|
|
Loading…
Add table
Reference in a new issue