minor guide edits (ok to merge to 4.2)
svn: r14879
This commit is contained in:
parent
de5bbaff40
commit
94116052da
|
@ -12,7 +12,7 @@ natural-language character or piece of a character. Technically, a
|
|||
scalar value is a simpler notion than the concept called a
|
||||
``character'' in the Unicode standard, but it's an approximation that
|
||||
works well for many purposes. For example, any accented Roman letter
|
||||
can be represented as a scalar value, as can any Chinese character.
|
||||
can be represented as a scalar value, as can any common Chinese character.
|
||||
|
||||
Although each Scheme character corresponds to an integer, the
|
||||
character datatype is separate from numbers. The
|
||||
|
|
|
@ -35,12 +35,12 @@ parentheses for expressions are brown.
|
|||
Many predefined functions operate on lists. Here are a few examples:
|
||||
|
||||
@interaction[
|
||||
(code:line (length (list "a" "b" "c")) (code:comment #, @t{count the elements}))
|
||||
(code:line (list-ref (list "a" "b" "c") 0) (code:comment #, @t{extract by position}))
|
||||
(list-ref (list "a" "b" "c") 1)
|
||||
(code:line (append (list "a" "b") (list "c")) (code:comment #, @t{combine lists}))
|
||||
(code:line (reverse (list "a" "b" "c")) (code:comment #, @t{reverse order}))
|
||||
(code:line (member "d" (list "a" "b" "c")) (code:comment #, @t{check for an element}))
|
||||
(code:line (length (list "hop" "skip" "jump")) (code:comment #, @t{count the elements}))
|
||||
(code:line (list-ref (list "hop" "skip" "jump") 0) (code:comment #, @t{extract by position}))
|
||||
(list-ref (list "hop" "skip" "jump") 1)
|
||||
(code:line (append (list "hop" "skip") (list "jump")) (code:comment #, @t{combine lists}))
|
||||
(code:line (reverse (list "hop" "skip" "jump")) (code:comment #, @t{reverse order}))
|
||||
(code:line (member "fall" (list "hop" "skip" "jump")) (code:comment #, @t{check for an element}))
|
||||
]
|
||||
|
||||
@;------------------------------------------------------------------------
|
||||
|
@ -260,6 +260,9 @@ reasonable, since it has to generate a result of size
|
|||
accumulating the result list. The only catch is that the accumulated
|
||||
list will be backwards, so you'll have to reverse it at the very end:
|
||||
|
||||
@margin-note{Attempting to reduce a constant factor like this is
|
||||
usually not worthwhile, as discussed below.}
|
||||
|
||||
@schemeblock[
|
||||
(define (my-map f lst)
|
||||
(define (iter lst backward-result)
|
||||
|
@ -291,7 +294,7 @@ iteration is just a special case of recursion. In many languages, it's
|
|||
important to try to fit as many computations as possible into
|
||||
iteration form. Otherwise, performance will be bad, and moderately
|
||||
large inputs can lead to stack overflow. Similarly, in Scheme, it is
|
||||
often important to make sure that tail recursion is used to avoid
|
||||
sometimes important to make sure that tail recursion is used to avoid
|
||||
@math{O(n)} space consumption when the computation is easily performed
|
||||
in constant space.
|
||||
|
||||
|
|
|
@ -113,7 +113,8 @@ evaluated only for some side-effect, such as printing.
|
|||
(bake "apple")
|
||||
]
|
||||
|
||||
Scheme programmers prefer to avoid side-effects. It's
|
||||
Scheme programmers prefer to avoid side-effects, so a definition usually
|
||||
has just one expression in its body. It's
|
||||
important, though, to understand that multiple expressions are allowed
|
||||
in a definition body, because it explains why the following
|
||||
@scheme[nobake] function simply returns its argument:
|
||||
|
@ -165,7 +166,7 @@ next line under the first argument, instead of under the
|
|||
|
||||
In this case, indentation helps highlight the mistake. In other cases,
|
||||
where the indentation may be normal while an open parenthesis has no
|
||||
matching close parenthesis; both @exec{mzscheme} and DrScheme use the
|
||||
matching close parenthesis, both @exec{mzscheme} and DrScheme use the
|
||||
source's indentation to suggest where a parenthesis might be missing.
|
||||
|
||||
@;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
|
|
|
@ -121,7 +121,7 @@ expressions, a printed symbol should not be confused with an
|
|||
identifier. In particular, the symbol @scheme[(#, @scheme[quote] #,
|
||||
@schemeidfont{map})] has nothing to do with the @schemeidfont{map}
|
||||
identifier or the predefined function that is bound to
|
||||
@schemeidfont{map}, except that the symbol and the identifier happen
|
||||
@scheme[map], except that the symbol and the identifier happen
|
||||
to be made up of the same letters.
|
||||
|
||||
Indeed, the intrinsic value of a symbol is nothing more than its
|
||||
|
|
Loading…
Reference in New Issue
Block a user