[Style] old fixes, can't recall source
This commit is contained in:
parent
97c9ec023f
commit
99fee6ec0e
|
@ -21,3 +21,67 @@ If your module is intended as a library, stick to @rkt/base[]. That way
|
|||
Conversely, you should use @rkt[] (or even @rkt/gui[]) when you just want a
|
||||
convenient language to write some program. The @rkt[] language comes with
|
||||
almost all the batteries, and @rkt/gui[] adds the rest of the GUI base.
|
||||
|
||||
@; -----------------------------------------------------------------------------
|
||||
@section{Macros: Space and Performance}
|
||||
|
||||
Macro copy code. Also, Racket is really a tower of macro-implemented
|
||||
languages. Hence, a single line of source code may expand into a rather
|
||||
large core expression. As you and others keep adding macros, even the
|
||||
smallest functions generate huge expressions and consume a lot of space.
|
||||
This kind of space consumption may affect the performance of your project
|
||||
and is therefore to be avoided.
|
||||
|
||||
When you design your own macro with a large expansion, try to factor it
|
||||
into a function call that consumes small thunks or procedures.
|
||||
|
||||
@compare[
|
||||
@racketmod[#:file
|
||||
@tt{good}
|
||||
racket
|
||||
...
|
||||
(define-syntax (search->run s)
|
||||
(syntax-parse s
|
||||
[(_ x (e:expr ...)
|
||||
(~datum in)
|
||||
b:expr)
|
||||
#'(sar/λ (list e ...)
|
||||
(λ (x) b))]))
|
||||
|
||||
(define (sar/λ l p)
|
||||
(for ((a '())) ((y l))
|
||||
(unless (bad? y)
|
||||
(cons (p y) a))))
|
||||
|
||||
(define (bad? x)
|
||||
... many lines ...)
|
||||
...
|
||||
]
|
||||
@; -----------------------------------------------------------------------------
|
||||
@(begin
|
||||
#reader scribble/comment-reader
|
||||
[racketmod #:file
|
||||
@tt{bad}
|
||||
racket
|
||||
...
|
||||
(define-syntax (search->run s)
|
||||
(syntax-parse s
|
||||
[(_ x (e:expr ...)
|
||||
(~datum in)
|
||||
b:expr)
|
||||
#'(begin
|
||||
(define (bad? x)
|
||||
... many lines ...)
|
||||
(define l
|
||||
(list e ...))
|
||||
(for ((a '())) ((x l))
|
||||
(unless (bad? x)
|
||||
(cons b a))))]))
|
||||
]
|
||||
)
|
||||
]
|
||||
|
||||
As you can see, the macro on the left calls a function with a list of the
|
||||
searchable values and a function that encapsulates the body. Every
|
||||
expansion is a single function call. In contrast, the macro on the right
|
||||
expands to many nested definitions and expressions every time it is used.
|
||||
|
|
|
@ -363,7 +363,12 @@ may relax this constraint.
|
|||
|
||||
@section{Spaces}
|
||||
|
||||
Don't pollute your code with spaces at the end of lines and extraneous blank lines.
|
||||
Don't pollute your code with spaces at the end of lines.
|
||||
|
||||
If you find yourself breaking long blocks of code with blank lines to aid
|
||||
readability, consider refactoring your program to introduce auxiliary
|
||||
functions so that you can shorten these long blocks of code. If nothing
|
||||
else helps, consider using (potentially) empty comment lines.
|
||||
|
||||
@; -----------------------------------------------------------------------------
|
||||
@section{End of File}
|
||||
|
|
Loading…
Reference in New Issue
Block a user