Polish macro stepper section, including screen shot.

This commit is contained in:
Greg Hendershott 2012-10-26 08:24:46 -04:00
parent 5245f6d48a
commit 26c6cb2b84
3 changed files with 27 additions and 25 deletions

File diff suppressed because one or more lines are too long

BIN
macro-stepper.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 131 KiB

View File

@ -600,7 +600,9 @@ This is where the Macro Stepper in DrRacket is invaluable. Even if you
prefer to work in Emacs (like I do), this is a situation where it's prefer to work in Emacs (like I do), this is a situation where it's
worth using DrRacket temporarily for its Macro Stepper. worth using DrRacket temporarily for its Macro Stepper.
The Macro Stepper says that: @image[#:scale 0.5 "macro-stepper.png"]
The Macro Stepper says that the use of our macro:
@codeblock{ @codeblock{
(hyphen-define/wrong1.1 foo bar () #t) (hyphen-define/wrong1.1 foo bar () #t)
@ -612,15 +614,18 @@ expanded to:
(define (name) #t) (define (name) #t)
} }
We're expanding to @racket[(define (name) #t)], but we wanted to Well that explains it. Instead, we wanted to expand to:
expand to @racket[(define (foo-bar) #t)].
So the problem is we're getting @racket[name] when we wanted its @codeblock{
value, @racket[foo-bar]. (define (foo-bar) #t)
}
The thing to reach for here is @racket[with-syntax]. This will let us Our template is using the symbol @racket[name] but we wanted its
say that @racket[name] is in effect another pattern variable, the value, such as @racket[foo-bar] in this use of our macro.
value of which we want to use in our main output template.
A solution here is @racket[with-syntax], which lets us say that
@racket[name] is something whose value can be used in our output
template:
@i[ @i[
(define-syntax (hyphen-define/wrong1.3 stx) (define-syntax (hyphen-define/wrong1.3 stx)
@ -643,11 +648,10 @@ Stepper. It says now we're expanding to:
(define (|#<syntax:11:24foo>-#<syntax:11:28 bar>|) #t) (define (|#<syntax:11:24foo>-#<syntax:11:28 bar>|) #t)
} }
Ah, that's right. @racket[#'a] and @racket[#'b] are syntax Oh right: @racket[#'a] and @racket[#'b] are syntax objects, and
objects. @racket[format] is printing a representation of them as syntax @racket[format] is printing them as such. Instead we want the datum
objects. What we want is the datum inside the syntax object, the inside the syntax object, the symbol @racket[foo] and
symbols @racket[foo] and @racket[bar]. So we should use @racket[bar]. To get that, we use @racket[syntax->datum]:
@racket[syntax->datum] on them:
@i[ @i[
(define-syntax (hyphen-define/ok1 stx) (define-syntax (hyphen-define/ok1 stx)