This commit is contained in:
Georges Dupéron 2018-01-27 11:55:34 +01:00
parent 8cec548ea7
commit 4bb11cb8f6
4 changed files with 43 additions and 7 deletions

14
aand.rkt Normal file
View File

@ -0,0 +1,14 @@
#lang racket/base
(provide aand it)
(require anaphoric/it
anaphoric/aif
syntax/parse/define
(for-syntax racket/base))
(define-syntax aand
(syntax-parser
[(_) #'#true]
[(_ body:expr) #'body]
[(_ [variable:id condition:expr] rest ...+)
#'(aif condition (and-let rest ...) #false)]))

View File

@ -2,7 +2,9 @@
(provide and-let)
(require syntax/parse/define "if-let.rkt" (for-syntax racket/base))
(require syntax/parse/define
anaphoric/if-let
(for-syntax racket/base))
(define-syntax and-let
(syntax-parser

View File

@ -14,6 +14,7 @@
anaphoric/aif
anaphoric/awhen
anaphoric/acond
anaphoric/aand
anaphoric/if-let
anaphoric/when-let
anaphoric/cond-let
@ -23,6 +24,7 @@
anaphoric/aif
anaphoric/awhen
anaphoric/acond
anaphoric/aand
anaphoric/if-let
anaphoric/when-let
anaphoric/cond-let

View File

@ -90,6 +90,24 @@ using @racket[it].
at most once (evaluation stops at the first successful
@racket[conditionᵢ]).}
@defform[(aand conditionᵢ ... body)]{
Variant of @racket[and] which binds @racket[it]
to the value of each @racket[conditionᵢ], in scope within the
next @racket[conditionᵢ] or @racket[body]. More precisely, the value
of each @racket[conditionᵢ] can be referred to as @racket[it] in
the following @racketvarfont{conditionᵢ₊₁}, and the value of the last
@racket[conditionᵢ] can be referred to as @racket[it] in the
@racket[body]. If there are no @racket[conditionᵢ], i.e. when
writing, @racket[(aand body)], then @racket[it] retains its original
binding (which means that @racket[it] could be unbound, e.g. if no
other @racketmodname[anaphoric] form wraps this one).
Each @racket[condition] is evaluated at most once, and
evaluation stops at the first false condition. The
@racket[body] is only evaluated when every
@racket[conditionᵢ] is successful.
}
@section{The hygienic versions @racket[if-let],
@racket[when-let] and @racket[cond-let]}
@ -124,14 +142,14 @@ using @racket[it].
(evaluation stops at the first successful
@racket[conditionᵢ]).}
@defform[(and-let [identifier condition] ... body)]{
@defform[(and-let [identifier condition] ... body)]{
Variant of @racket[and] which binds each @racket[identifier]
to the value of its @racket[condition], in scope within all
@racket[condition]s afterwards as well as in @racket[body].
to the value of its @racket[conditionᵢ], in scope within every
@racket[condition] afterwards as well as in @racket[body].
Each @racket[condition] is evaluated at most once, and
Each @racket[condition] is evaluated at most once, and
evaluation stops at the first false condition. The
@racket[body] is only evaluated when all
@racket[conditions] are successful.
@racket[body] is only evaluated when every
@racket[conditionᵢ] is successful.
}