-
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add let-values and let*-values syntax macros
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,43 @@ | |
(typecheck "values-ref" values "values" 1) | ||
(typecheck "values-ref" n "number" 1) | ||
(--> values (valueOf) n)) | ||
|
||
;; ----------------------------------------------------------------------------- | ||
(define-syntax let-values | ||
(syntax-rules () | ||
((_ ()) nil) | ||
((_ () body ...) (begin body ...)) | ||
((_ (((x ...) values) ...) body ...) | ||
(apply (lambda (x ... ...) | ||
body ...) | ||
(vector->list (apply %vector-concat (map (lambda (x) ((. x "valueOf"))) | ||
(list values ...))))))) | ||
"(let-values binding body ...) | ||
The macro work similar to let but variable is list of values and value | ||
need to evaluate to result of calling values.") | ||
|
||
;; ----------------------------------------------------------------------------- | ||
(define (%vector-concat . args) | ||
(if (null? args) | ||
#() | ||
(begin | ||
(typecheck "%vector-concat" (car args) "array") | ||
(--> (car args) (concat (apply %vector-concat (cdr args))))))) | ||
|
||
;; ----------------------------------------------------------------------------- | ||
(define-syntax let*-values | ||
(syntax-rules () | ||
((_ ()) nil) | ||
((_ () body ...) (begin body ...)) | ||
((_ ((bind values) rest ...) . body) | ||
(apply (lambda bind | ||
(let*-values (rest ...) . body)) | ||
(vector->list ((. values "valueOf")))))) | ||
"(let*-values binding body ...) | ||
The macro work similar to let* but variable is list of values and value | ||
need to evaluate to result of calling values.") | ||
;; ----------------------------------------------------------------------------- | ||
;; R7RS division operators (Gauche Scheme) BSD license | ||
;; Copyright (c) 2000-2020 Shiro Kawai <[email protected]> | ||
|
@@ -237,3 +274,4 @@ | |
(define raise throw) | ||
|
||
;; ----------------------------------------------------------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters