Skip to content

Commit

Permalink
add vector-for-each function from R7RS #269
Browse files Browse the repository at this point in the history
  • Loading branch information
jcubic committed Jan 21, 2024
1 parent 74b8199 commit 479295e
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 1.0.0-beta.19
### Features
* add `vector-for-each` function from R7RS
### Bugfix
* fix `let-values` to allow binding to list [#281](https://github.com/jcubic/lips/issues/281)


## 1.0.0-beta.18
### Breaking
* change undocumented arguments to `lips.exec` into an object
Expand Down
1 change: 1 addition & 0 deletions dist/std.min.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions dist/std.scm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified dist/std.xcb
Binary file not shown.
17 changes: 17 additions & 0 deletions lib/R7RS.scm
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,23 @@
(value (apply fn args)))
(--> result (push value)))))))


;; -----------------------------------------------------------------------------
(define (vector-for-each fn . rest)
"(vector-for-each fn vector1 vector2 ...)

Invokes every Returns new vector from applying function fn to each element
of the vectors, similar to map for lists."
(typecheck "vector-for-each" fn "function" 1)
(if (or (= (length rest) 0) (not (every vector? rest)))
(error "vector-for-each: function require at least 1 vector")
(let ((len (apply min (map vector-length rest)))
(result (vector)))
(do ((i 0 (+ i 1)))
((= i len) undefined)
(let* ((args (map (lambda (v) (vector-ref v i)) rest)))
(apply fn args))))))

;; -----------------------------------------------------------------------------
(define (string-map fn . rest)
"(string-map fn string1 stringr2 ...)
Expand Down

0 comments on commit 479295e

Please sign in to comment.