kzccm1d4if10m2xaz1wqy3xar821pp1r-my-site-anaphoric-git.test.suzanne.soy-0.0.1

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4bb11cb8f68f6307f1cbdb8578593a4733d53032
parent 8cec548ea745ef8f6c2f69c75de189283e98f1d5
Author: Georges Dupéron <georges.duperon@gmail.com>
Date:   Sat, 27 Jan 2018 11:55:34 +0100

Add aand

Diffstat:
Aaand.rkt | 14++++++++++++++
Mand-let.rkt | 4+++-
Mmain.rkt | 2++
Mscribblings/anaphoric.scrbl | 30++++++++++++++++++++++++------
4 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/aand.rkt b/aand.rkt @@ -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)])) diff --git a/and-let.rkt b/and-let.rkt @@ -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 diff --git a/main.rkt b/main.rkt @@ -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 diff --git a/scribblings/anaphoric.scrbl b/scribblings/anaphoric.scrbl @@ -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. }