add define-nested-lenses example

This commit is contained in:
AlexKnauth 2015-12-03 20:29:03 -05:00
parent 5c413bd1b3
commit f6158cce91

View File

@ -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] Will define @racket[top-middle-x-lens] and @racket[top-middle-y-lens]
as @racket[(lens-thrush top-middle-lens middle-x-lens)] and as @racket[(lens-thrush top-middle-lens middle-x-lens)] and
@racket[(lens-thrush top-middle-lens middle-y-lens)]. @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)
]}