fix doc mistakes related to struct guards
svn: r11368
This commit is contained in:
parent
c2e9a78ea9
commit
e507d9a1a3
|
@ -406,13 +406,16 @@ A @scheme[_struct-option] always starts with a keyword:
|
||||||
@;-- FIXME:
|
@;-- FIXME:
|
||||||
@;-- Explain when to use guards instead of contracts, and vice-versa
|
@;-- Explain when to use guards instead of contracts, and vice-versa
|
||||||
|
|
||||||
@specspecsubform[(code:line #:guard guard-expr)]{
|
@specspecsubform[(code:line #:guard guard-expr)]{ Specifies a
|
||||||
Specifies a @deftech{constructor guard} procedure to be called
|
@deftech{constructor guard} procedure to be called whenever an
|
||||||
whenever an instance of the structure type is created. The guard
|
instance of the structure type is created. The guard takes as many
|
||||||
takes as many arguments as non-automatic fields in the structure
|
arguments as non-automatic fields in the structure type, plus one
|
||||||
type, and it should return the same number of values. The guard can
|
more for the name of the instantiated type (in case a sub-type is
|
||||||
raise an exception if one of the given arguments is unacceptable, or
|
instantiated, in which case it's best to report an error using the
|
||||||
it can convert an argument.
|
sub-type's name). The guard should return the same number of values
|
||||||
|
as given, minus the name argument. The guard can raise an exception
|
||||||
|
if one of the given arguments is unacceptable, or it can convert an
|
||||||
|
argument.
|
||||||
|
|
||||||
@defexamples[
|
@defexamples[
|
||||||
#:eval posn-eval
|
#:eval posn-eval
|
||||||
|
@ -421,12 +424,14 @@ A @scheme[_struct-option] always starts with a keyword:
|
||||||
#:guard (lambda (name type-name)
|
#:guard (lambda (name type-name)
|
||||||
(cond
|
(cond
|
||||||
[(string? name) name]
|
[(string? name) name]
|
||||||
[(number? name)
|
[(symbol? name) (symbol->string name)]
|
||||||
(number->string name)]
|
[else (error type-name
|
||||||
[else (error "bad name" name)])))
|
"bad name: ~e"
|
||||||
|
name)])))
|
||||||
(make-thing "apple")
|
(make-thing "apple")
|
||||||
|
(make-thing 'apple)
|
||||||
(make-thing 1/2)
|
(make-thing 1/2)
|
||||||
(make-thing #f)]
|
]
|
||||||
|
|
||||||
The guard is called even when subtype instances are created. In that
|
The guard is called even when subtype instances are created. In that
|
||||||
case, only the fields accepted by the constructor are provided to
|
case, only the fields accepted by the constructor are provided to
|
||||||
|
@ -439,11 +444,11 @@ A @scheme[_struct-option] always starts with a keyword:
|
||||||
#:transparent
|
#:transparent
|
||||||
#:guard (lambda (name age type-name)
|
#:guard (lambda (name age type-name)
|
||||||
(if (negative? age)
|
(if (negative? age)
|
||||||
(error "bad age" age)
|
(error type-name "bad age: ~e" age)
|
||||||
(values name age))))
|
(values name age))))
|
||||||
(make-person "John" 10)
|
(make-person "John" 10)
|
||||||
(make-person "Mary" -1)
|
(make-person "Mary" -1)
|
||||||
(make-person #f 10)]}
|
(make-person 10 10)]}
|
||||||
|
|
||||||
@specspecsubform[(code:line #:property prop-expr val-expr)]{
|
@specspecsubform[(code:line #:property prop-expr val-expr)]{
|
||||||
Associates a @deftech{property} and value with the structure type.
|
Associates a @deftech{property} and value with the structure type.
|
||||||
|
|
|
@ -105,7 +105,7 @@ structures depends on the current inspector.)
|
||||||
|
|
||||||
Creates a new structure type, unless @scheme[inspector] is
|
Creates a new structure type, unless @scheme[inspector] is
|
||||||
@scheme['prefab], in which case @scheme[make-struct-type] accesses a
|
@scheme['prefab], in which case @scheme[make-struct-type] accesses a
|
||||||
@techlink{prefab} structre type. The @scheme[name] argument is used
|
@techlink{prefab} structure type. The @scheme[name] argument is used
|
||||||
as the type name. If @scheme[super-type] is not @scheme[#f], the
|
as the type name. If @scheme[super-type] is not @scheme[#f], the
|
||||||
resulting type is a subtype of the corresponding structure type.
|
resulting type is a subtype of the corresponding structure type.
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ positions. Each element in the list must be unique, otherwise
|
||||||
@scheme[0] (inclusive) to @scheme[init-field-cnt] (exclusive), otherwise
|
@scheme[0] (inclusive) to @scheme[init-field-cnt] (exclusive), otherwise
|
||||||
@exnraise[exn:fail:contract].
|
@exnraise[exn:fail:contract].
|
||||||
|
|
||||||
The @scheme[guard] argument is either a procedure of @math{n}
|
The @scheme[guard] argument is either a procedure of @math{n+1}
|
||||||
arguments or @scheme[#f], where @math{n} is the number of arguments
|
arguments or @scheme[#f], where @math{n} is the number of arguments
|
||||||
for the new structure type's constructor (i.e.,
|
for the new structure type's constructor (i.e.,
|
||||||
@scheme[init-field-cnt] plus constructor arguments implied by
|
@scheme[init-field-cnt] plus constructor arguments implied by
|
||||||
|
|
Loading…
Reference in New Issue
Block a user