diff --git a/and-let.rkt b/and-let.rkt new file mode 100644 index 0000000..4a07159 --- /dev/null +++ b/and-let.rkt @@ -0,0 +1,13 @@ +#lang racket/base + +(provide and-let) + +(require syntax/parse/define "if-let.rkt" (for-syntax racket/base)) + +(define-syntax and-let + (syntax-parser + [(_) #'#true] + [(_ body:expr) #'body] + [(_ [variable:id condition:expr] rest ...+) + #'(if-let [variable condition] (and-let rest ...) #false)])) + diff --git a/main.rkt b/main.rkt index 7299073..6ce9350 100644 --- a/main.rkt +++ b/main.rkt @@ -16,7 +16,8 @@ anaphoric/acond anaphoric/if-let anaphoric/when-let - anaphoric/cond-let)) + anaphoric/cond-let + anaphoric/and-let)) (require anaphoric/it anaphoric/aif @@ -24,4 +25,5 @@ anaphoric/acond anaphoric/if-let anaphoric/when-let - anaphoric/cond-let) + anaphoric/cond-let + anaphoric/and-let) diff --git a/scribblings/anaphoric.scrbl b/scribblings/anaphoric.scrbl index c1f62de..bbebf5d 100644 --- a/scribblings/anaphoric.scrbl +++ b/scribblings/anaphoric.scrbl @@ -122,4 +122,16 @@ using @racket[it]. Each @racket[conditionᵢ] is evaluated at most once (evaluation stops at the first successful - @racket[conditionᵢ]).} \ No newline at end of file + @racket[conditionᵢ]).} + +@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]. + + 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. +} +