Guide corrections

This commit is contained in:
Matthew Flatt 2011-08-26 10:01:28 -06:00
parent 85790b6611
commit bedd7b1671
3 changed files with 22 additions and 12 deletions

View File

@ -41,7 +41,7 @@
(namespace-require '(for-syntax racket/base)) (namespace-require '(for-syntax racket/base))
(define (literal-string style s) (define (literal-string style s)
(let ([m (regexp-match #rx"^(.*)( +)(.*)$" s)]) (let ([m (regexp-match #rx"^(.*)( +|^ )(.*)$" s)])
(if m (if m
(make-element #f (list (literal-string style (cadr m)) (make-element #f (list (literal-string style (cadr m))
(hspace (string-length (caddr m))) (hspace (string-length (caddr m)))

View File

@ -47,12 +47,10 @@ y)]. The environment of @racket[(+ x y)] includes bindings for
@racketmodname[racket]. @racketmodname[racket].
A module-level @racket[define] can bind only identifiers that are not A module-level @racket[define] can bind only identifiers that are not
already bound within the module. For example, @racket[(define cons 1)] already defined or @racket[require]s into the module. A local
is a syntax error in a @racketmodname[racket] module, since @racket[cons] @racket[define] or other binding forms, however, can give a new local
is provided by @racketmodname[racket]. A local @racket[define] or other binding for an identifier that already has a binding; such a binding
binding forms, however, can give a new local binding for an identifier @deftech{shadows} the existing binding.
that already has a binding; such a binding @defterm{shadows} the
existing binding.
@defexamples[ @defexamples[
(define f (define f
@ -63,6 +61,14 @@ existing binding.
(f list) (f list)
] ]
Similarly, a module-level @racket[define] can @tech{shadow} a binding
from the module's language. For example, @racket[(define cons 1)] in a
@racketmodname[racket] module shadows the @racket[cons] that is
provided by @racketmodname[racket]. Intentionally shadowing a language
binding is rarely a good idea---especially for widely used bindings
like @racket[cons]---but shadowing relieves a programmer from having
to avoid every obscure binding that is provided by a language.
Even identifiers like @racket[define] and @racket[lambda] get their Even identifiers like @racket[define] and @racket[lambda] get their
meanings from bindings, though they have @defterm{transformer} meanings from bindings, though they have @defterm{transformer}
bindings (which means that they indicate syntactic forms) instead of bindings (which means that they indicate syntactic forms) instead of
@ -76,5 +82,5 @@ define
(eval:alts (let ([@#,racketidfont{define} 5]) @#,racketidfont{define}) (let ([define 5]) define)) (eval:alts (let ([@#,racketidfont{define} 5]) @#,racketidfont{define}) (let ([define 5]) define))
] ]
Shadowing standard bindings in this way is rarely a good idea, but the Again, shadowing standard bindings in this way is rarely a good idea, but the
possibility is an inherent part of Racket's flexibility. possibility is an inherent part of Racket's flexibility.

View File

@ -49,10 +49,14 @@ For example, the @filepath{cake.rkt} example of the
(provide print-cake) (provide print-cake)
(define (print-cake n) (define (print-cake n)
(printf " ~a \n" (make-string n #\.)) (show " ~a " n #\.)
(printf " .-~a-.\n" (make-string n #\|)) (show " .-~a-. " n #\|)
(printf " | ~a |\n" (make-string n #\space)) (show " | ~a | " n #\space)
(printf "---~a---\n" (make-string n #\-)))) (show "---~a---" n #\-))
(define (show fmt n ch)
(printf fmt (make-string n ch))
(newline)))
] ]
Furthermore, this @racket[module] form can be evaluated in a Furthermore, this @racket[module] form can be evaluated in a