add define-nested-lenses example
This commit is contained in:
parent
5c413bd1b3
commit
f6158cce91
|
@ -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)
|
||||
]}
|
||||
|
|
Loading…
Reference in New Issue
Block a user