define-struct/derived and doc improvements
svn: r7844
This commit is contained in:
parent
ad7c2e16a1
commit
cbf636442b
|
@ -10,6 +10,7 @@
|
|||
"struct-info.ss"))
|
||||
|
||||
(#%provide define-struct*
|
||||
define-struct/derived
|
||||
struct-field-index)
|
||||
|
||||
(define-syntax-parameter struct-field-index
|
||||
|
@ -29,6 +30,12 @@
|
|||
what)
|
||||
|
||||
(define-syntax (define-struct* stx)
|
||||
(syntax-case stx ()
|
||||
[(_ . rest)
|
||||
(with-syntax ([stx stx])
|
||||
#'(define-struct/derived stx . rest))]))
|
||||
|
||||
(define-syntax (define-struct/derived full-stx)
|
||||
(define make-field list)
|
||||
(define field-id car)
|
||||
(define field-default-value cadr)
|
||||
|
@ -183,9 +190,12 @@
|
|||
"expected a struct-spefication keyword")
|
||||
stx
|
||||
(car p))])))
|
||||
|
||||
(define stx (syntax-case full-stx ()
|
||||
[(_ stx . _) #'stx]))
|
||||
|
||||
(syntax-case stx ()
|
||||
[(fm id (field ...) prop ...)
|
||||
(syntax-case full-stx ()
|
||||
[(_ (fm . _) id (field ...) prop ...)
|
||||
(let-values ([(id super-id)
|
||||
(if (identifier? #'id)
|
||||
(values #'id #f)
|
||||
|
@ -197,10 +207,9 @@
|
|||
[else
|
||||
(raise-syntax-error
|
||||
#f
|
||||
(string-append
|
||||
"expected an identifier for the struct type name, or a parenthesized sequence"
|
||||
" with an identifier followed by the struct supertype identifier")
|
||||
stx)]))])
|
||||
"bad syntax; expected <id> for structure-type name or (<id> <id>) for name and supertype name"
|
||||
stx
|
||||
#'id)]))])
|
||||
(let ([super-info
|
||||
(and super-id
|
||||
(let ([v (syntax-local-value super-id (lambda () #f))])
|
||||
|
@ -400,5 +409,38 @@
|
|||
(syntax-property result
|
||||
'disappeared-use
|
||||
(syntax-local-introduce super-id))
|
||||
result)))))))))])))
|
||||
result)))))))))]
|
||||
[(_ _ id . _)
|
||||
(not (or (identifier? #'id)
|
||||
(and (syntax->list #'id)
|
||||
(= 2 (length (syntax->list #'id)))
|
||||
(andmap identifier? (syntax->list #'id)))))
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"bad syntax; expected <id> for structure-type name or (<id> <id>) for name and supertype name"
|
||||
stx
|
||||
#'id)]
|
||||
[(_ _ id (field ...) . _)
|
||||
(begin
|
||||
(for-each parse-field (syntax->list #'(field ...)))
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"bad syntax after field sequence"
|
||||
stx))]
|
||||
[(_ _ id fields . _)
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"bad syntax; expected a parenthesized sequence of field descriptions"
|
||||
stx
|
||||
#'fields)]
|
||||
[(_ _ id)
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"bad syntax; missing fields"
|
||||
stx)]
|
||||
[_
|
||||
(raise-syntax-error
|
||||
#f
|
||||
"bad syntax"
|
||||
stx)])))
|
||||
|
||||
|
|
|
@ -46,4 +46,5 @@
|
|||
keyword-apply
|
||||
procedure-keywords
|
||||
(rename define-struct* define-struct)
|
||||
define-struct/derived
|
||||
struct-field-index))
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#lang scribble/doc
|
||||
@require["mz.ss"]
|
||||
@(require "mz.ss"
|
||||
(for-syntax scheme/base))
|
||||
|
||||
@title[#:tag "define-struct"]{Defining Structure Types: @scheme[define-struct]}
|
||||
|
||||
|
@ -144,3 +145,26 @@ This form can only appear as an expression within a
|
|||
(happy+ 2)
|
||||
(mood-procedure-rating happy+)
|
||||
]}
|
||||
|
||||
@defform[(define-struct/derived (id . rest-form)
|
||||
id-maybe-super (field ...) struct-option ...)]{
|
||||
|
||||
Like @scheme[define-struct], but intended for use by macros that
|
||||
expand to @scheme[define-struct]. The form immediately after
|
||||
@scheme[define-struct/derived] is used for all syntax-error reporting,
|
||||
and the only constraint on the form is that it starts with some
|
||||
@scheme[id].
|
||||
|
||||
@defexamples[
|
||||
(define-syntax (define-xy-struct stx)
|
||||
(syntax-case stx ()
|
||||
[(ds name . rest)
|
||||
(with-syntax ([orig stx])
|
||||
#'(define-struct/derived orig name (x y) . rest))]))
|
||||
|
||||
(define-xy-struct posn)
|
||||
(posn-x (make-posn 1 2))
|
||||
(define-xy-struct posn #:mutable)
|
||||
(set-posn-x! (make-posn 1 2) 0)
|
||||
(define-xy-struct posn #:bad-option)
|
||||
]}
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
|
||||
@title[#:tag "basic"]{Basic Document Forms}
|
||||
|
||||
@declare-exporting[scribble/basic]
|
||||
|
||||
The @filepath{basic.ss} libraryprovides functions and forms that can be
|
||||
used from code written either in Scheme or with @elem["@"]
|
||||
expressions. For example, the @scheme[title] and @scheme[italic]
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
@title[#:tag "decode"]{Text Decoder}
|
||||
|
||||
@declare-exporting[scribble/decode]
|
||||
|
||||
The @filepath{decode.ss} library helps you write document content in a
|
||||
natural way---more like plain text, except for @litchar["@"] escapes.
|
||||
Roughly, it processes a stream of strings to produces instances of the
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
@title[#:tag "eval"]{Evaluation and Examples}
|
||||
|
||||
@declare-exporting[scribble/eval]
|
||||
|
||||
The @filepath{eval.ss} library provides utilities for evaluating code at
|
||||
document-build time and incorporating the results in the document,
|
||||
especially to show example uses of defined procedures and syntax.
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
@title[#:tag "manual"]{PLT Manual Forms}
|
||||
|
||||
@declare-exporting[scribble/manual]
|
||||
|
||||
The @filepath{manual.ss} module provides all of @filepath{basic.ss}, and
|
||||
more...
|
||||
|
||||
|
@ -36,7 +38,7 @@ because that's the way it is idented the use of @scheme[schemeblock].
|
|||
Furthermore, @scheme[define] is typeset as a keyword (bold and black)
|
||||
and as a hyperlink to @scheme[define]'s definition in the reference
|
||||
manual, because this document was built using a for-label binding of
|
||||
@scheme[define] (in the source) that match the for-label binding of
|
||||
@scheme[define] (in the source) that matches the for-label binding of
|
||||
the definition in the reference manual. Similarly, @scheme[not] is a
|
||||
hyperlink to the its definition in the reference manual.
|
||||
|
||||
|
|
|
@ -721,6 +721,8 @@ an example of this.
|
|||
@;--------------------------------------------------------------------
|
||||
@section{Interface}
|
||||
|
||||
@declare-exporting[scribble/reader]
|
||||
|
||||
The @filepath{reader.ss} module provides functionality for advanced needs.
|
||||
|
||||
@; The `with-scribble-read' trick below shadows `read' and
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
@title[#:tag "struct"]{Document Structures And Processing}
|
||||
|
||||
@declare-exporting[scribble/struct]
|
||||
|
||||
A document is represented as a @techlink{part}, as described in
|
||||
@secref["parts"]. This representation is intended to
|
||||
independent of its eventual rendering, and it is intended to be
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
@title[#:style 'toc]{Making Slides}
|
||||
|
||||
@declare-exporting[slideshow/base slideshow]
|
||||
|
||||
@local-table-of-contents[]
|
||||
|
||||
@; ----------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue
Block a user