Fixing PR12881
This commit is contained in:
parent
1685952b9b
commit
a7ea79040d
|
@ -468,20 +468,23 @@ in a new browser window. What happens when you try this?
|
||||||
@section{Share and Share Alike}
|
@section{Share and Share Alike}
|
||||||
@declare-exporting[#:use-sources (web-server/scribblings/tutorial/examples/iteration-4)]
|
@declare-exporting[#:use-sources (web-server/scribblings/tutorial/examples/iteration-4)]
|
||||||
|
|
||||||
The problem with our application is that each browser
|
The problem with our application is that each browser window keeps
|
||||||
window keeps track of its own distinct blog. For most people, this defeats
|
track of its own distinct blog. For most people, this defeats the
|
||||||
the purpose of a blog, which is to share with others! When we insert a
|
purpose of a blog, which is to share with others! When we insert a
|
||||||
new post, rather than creating a new blog value, we'd like to make a
|
new post, rather than creating a new blog value, we'd like to modify
|
||||||
structural change to the existing
|
@emph{the} blog. In other words, we'd like to make a structural
|
||||||
blog. (@italic{@link["http://www.htdp.org/"]{How to Design Programs}},
|
change. (@italic{@link["http://www.htdp.org/"]{How to Design
|
||||||
Chapter 41). So let's add mutation to the mix.
|
Programs}}, Chapter 41). So let's switch from just the @racket[BLOG]
|
||||||
|
binding to a list and instead bind it to a mutable structure. If we
|
||||||
|
were to just use a structure, we'd write the following:
|
||||||
|
|
||||||
There's one small detail we need to touch on: by default, structures in the
|
@racketblock[(struct blog (posts))]
|
||||||
@racket[web-server] language are immutable. To gain access to structure
|
|
||||||
mutators, we'll need to override this default, by adding the @racket[#:mutable]
|
But, by default, structures in Racket are immutable. To gain access
|
||||||
keyword to some of our structure definitions. In particular, if we want to
|
to structure mutators, we'll need to override this default, by adding
|
||||||
allow changes to a blog, we must change our definition of the blog structure to
|
the @racket[#:mutable] keyword to some of our structure
|
||||||
the following:
|
definitions. In particular, if we want to allow changes to a blog, we
|
||||||
|
must change our definition of the blog structure to the following:
|
||||||
|
|
||||||
@racketblock[(struct blog (posts) #:mutable)]
|
@racketblock[(struct blog (posts) #:mutable)]
|
||||||
|
|
||||||
|
@ -499,7 +502,7 @@ which allows us to change the posts of a blog:
|
||||||
|
|
||||||
@defthing[blog-insert-post! (blog? post? . -> . void)]
|
@defthing[blog-insert-post! (blog? post? . -> . void)]
|
||||||
|
|
||||||
whose intended side effect is to extend a blog's post.
|
whose intended side effect is to extend a blog's posts.
|
||||||
|
|
||||||
@centerline{------------}
|
@centerline{------------}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user