Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77830ba
commit 2e30163
Showing
9 changed files
with
68 additions
and
32 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
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
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
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#lang racket | ||
|
||
(provide | ||
=> | ||
when* | ||
unless* | ||
and*) | ||
|
||
;; TODO make them more like the real thing | ||
|
||
;; --------------------------------------------------------------------------------------------------- | ||
(require syntax/parse/define (for-syntax syntax/parse)) | ||
(module+ test (require rackunit)) | ||
|
||
;; --------------------------------------------------------------------------------------------------- | ||
(define-syntax => (lambda (stx) (raise-syntax-error '=> "used out of context"))) | ||
|
||
(define-simple-macro | ||
(when* condition:expr (~literal =>) body:expr) | ||
(let ([it condition]) (when it (body it)))) | ||
|
||
(define-simple-macro | ||
(unless* condition:expr (~literal =>) body:expr) | ||
(let ([it condition]) (unless it (body it)))) | ||
|
||
(define-syntax (and* stx) | ||
(syntax-parse stx | ||
[(_) #'(and)] | ||
[(_ e1:expr) #'(and e1)] | ||
[(_ e1:expr (~literal =>) e-next:expr e2:expr ...) | ||
#'(let ([it e1]) (and it (e-next it) (and* e2 ...)))] | ||
[(_ e1:expr e2:expr ...) #'(and e1 (and* e2 ...))])) | ||
|
||
(module+ test | ||
(check-equal? (when* (sin (/ pi 2)) => (λ (it) (- it 1.0))) 0.0) ;; ok ok | ||
(check-equal? (unless* (sin (/ pi 2)) => (λ (it) (- it 1.0))) (void)) | ||
|
||
(check-true (and*)) | ||
(check-true (and* #t)) | ||
(check-true (and* (+ 1 1) => (λ (it) (> 3 it)))) | ||
(check-false (and* (+ 1 1) => (λ (it) (> 3 it)) #f))) |
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