From f6158cce9183b866cefd1b874245251ae8253784 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Thu, 3 Dec 2015 20:29:03 -0500 Subject: [PATCH] add define-nested-lenses example --- unstable/lens/define-nested.scrbl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/unstable/lens/define-nested.scrbl b/unstable/lens/define-nested.scrbl index d4155b5..ebf75fc 100644 --- a/unstable/lens/define-nested.scrbl +++ b/unstable/lens/define-nested.scrbl @@ -20,4 +20,17 @@ For example, if there is a @racket[top] struct containing a Will define @racket[top-middle-x-lens] and @racket[top-middle-y-lens] as @racket[(lens-thrush top-middle-lens middle-x-lens)] and @racket[(lens-thrush top-middle-lens middle-y-lens)]. -} + +@lens-unstable-examples[ + (struct/lens ball (mass position velocity) #:transparent) + (struct/lens position (x y) #:transparent) + (struct/lens velocity (x y) #:transparent) + (define-nested-lenses [ball-pos ball-position-lens] + [x position-x-lens] + [y position-y-lens]) + (define-nested-lenses [ball-vel ball-velocity-lens] + [x velocity-x-lens] + [y velocity-y-lens]) + (lens-view ball-vel-x-lens (ball 1 (position 2 3) (velocity 4 5))) + (lens-set ball-vel-x-lens (ball 1 (position 2 3) (velocity 4 5)) 1004) +]}