-
-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for negated predicates in assert
and with-asserts
.
#1324
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resyntax analyzed 2 files in this pull request and has added suggestions.
(define pred-parser | ||
(λ (stx) | ||
(syntax-parse stx | ||
#:datum-literals (not/p) | ||
[(not/p (not/p p)) (pred-parser #'p)] | ||
[_ stx]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define-lambda-to-define
: The define
form supports a shorthand for defining functions (including function-returning functions).
(define pred-parser | |
(λ (stx) | |
(syntax-parse stx | |
#:datum-literals (not/p) | |
[(not/p (not/p p)) (pred-parser #'p)] | |
[_ stx]))) | |
(define (pred-parser stx) | |
(syntax-parse stx | |
#:datum-literals (not/p) | |
[(not/p (not/p p)) (pred-parser #'p)] | |
[_ stx])) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (define (pred-parser stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [(not/p (not/p p)) (pred-parser #'p)]"
" [_ stx]))")
#:original-lines
'#(" (define pred-parser"
" (λ (stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [(not/p (not/p p)) (pred-parser #'p)]"
" [_ stx])))")
#:start-line 734)
Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:do-make-syntax-introducer>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/snapshot/pkgs/resyntax/default-recommendations/function-definition-shortcuts.rkt:87:3 (define (pred-parser (ORIGINAL-SPLICE stx)) (ORIGINAL-GAP (stx) (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser (syntax p))) (_ stx))) (ORIGINAL-SPLICE (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser...>
#:original-syntax
#<syntax:typed-racket-lib/typed-racket/base-env/prims.rkt:734:4 (define pred-parser (λ (stx) (syntax-parse stx #:datum-literals (not/p) ((not/p (not/p p)) (pred-parser (syntax p))) (_ stx))))>)
(define assert-parser | ||
(λ (stx) | ||
(syntax-parse stx | ||
#:datum-literals (not/p) | ||
[[x (not/p p)] #'(p x)] | ||
[[x p] #'(not (p x))]))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define-lambda-to-define
: The define
form supports a shorthand for defining functions (including function-returning functions).
(define assert-parser | |
(λ (stx) | |
(syntax-parse stx | |
#:datum-literals (not/p) | |
[[x (not/p p)] #'(p x)] | |
[[x p] #'(not (p x))]))) | |
(define (assert-parser stx) | |
(syntax-parse stx | |
#:datum-literals (not/p) | |
[[x (not/p p)] #'(p x)] | |
[[x p] #'(not (p x))])) |
Debugging details
Textual replacement
(line-replacement
#:new-lines
'#(" (define (assert-parser stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [[x (not/p p)] #'(p x)]"
" [[x p] #'(not (p x))]))")
#:original-lines
'#(" (define assert-parser"
" (λ (stx)"
" (syntax-parse stx"
" #:datum-literals (not/p)"
" [[x (not/p p)] #'(p x)]"
" [[x p] #'(not (p x))])))")
#:start-line 740)
Syntactic replacement
(syntax-replacement
#:introduction-scope #<procedure:do-make-syntax-introducer>
#:new-syntax
#<syntax:/home/runner/.local/share/racket/snapshot/pkgs/resyntax/default-recommendations/function-definition-shortcuts.rkt:87:3 (define (assert-parser (ORIGINAL-SPLICE stx)) (ORIGINAL-GAP (stx) (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax (p x))) ((x p) (syntax (not (p x)))))) (ORIGINAL-SPLICE (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax...>
#:original-syntax
#<syntax:typed-racket-lib/typed-racket/base-env/prims.rkt:740:4 (define assert-parser (λ (stx) (syntax-parse stx #:datum-literals (not/p) ((x (not/p p)) (syntax (p x))) ((x p) (syntax (not (p x)))))))>)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resyntax analyzed 2 files in this pull request and found no issues.
This PR adds support for negated predicates in
assert
andwith-asserts
in Typed Racket. With this change, programmers can use(not/p pred)
to assert that a value does not satisfy the given predicatepred
.And before this change, if a value failed an assertion in
assert
orwith-asserts
, the error message did not show which assertion failed.Here are some examples:
Before:
After: