3.99.0.10: immutable vector and box literals
svn: r8465
This commit is contained in:
parent
8fe96fd23b
commit
6e2e7d9447
|
@ -13,14 +13,14 @@ render the character/byte content directly to the output port.
|
|||
|
||||
When the @scheme[print-graph] parameter is set to @scheme[#t], then
|
||||
the printer first scans an object to detect cycles. The scan traverses
|
||||
the components of pairs, vectors, boxes (when @scheme[print-box] is
|
||||
@scheme[#t]), hash tables (when @scheme[print-hash-table] is
|
||||
@scheme[#t]), and fields of structures exposed by
|
||||
@scheme[struct->vector] (when @scheme[print-struct] is
|
||||
the components of pairs, mutable pairs, vectors, boxes (when
|
||||
@scheme[print-box] is @scheme[#t]), hash tables (when
|
||||
@scheme[print-hash-table] is @scheme[#t]), and fields of structures
|
||||
exposed by @scheme[struct->vector] (when @scheme[print-struct] is
|
||||
@scheme[#t]). If @scheme[print-graph] is @scheme[#t], then this
|
||||
information is used to display sharing by printing graph definitions
|
||||
and references (see @secref["parse-graph"]). If a cycle is detected
|
||||
in the initial scan, then @scheme[print-graph] is effectively set to
|
||||
and references (see @secref["parse-graph"]). If a cycle is detected in
|
||||
the initial scan, then @scheme[print-graph] is effectively set to
|
||||
@scheme[#t] automatically.
|
||||
|
||||
With the exception of displaying byte strings, printing is defined in
|
||||
|
|
|
@ -10,7 +10,7 @@ otherwise. See also @secref["stxobj-model"].}
|
|||
|
||||
@defproc[(syntax-source [stx syntax?]) any]{
|
||||
|
||||
Returns the source for the syntax object @scheme[stx], or @scheme[#f]
|
||||
Returns the source for the @tech{syntax object} @scheme[stx], or @scheme[#f]
|
||||
if none is known. The source is represented by an arbitrary value
|
||||
(e.g., one passed to @scheme[read-syntax]), but it is typically a file
|
||||
path string. Source-location information is dropped for a syntax
|
||||
|
@ -23,23 +23,23 @@ object that is marshaled as part of compiled code; see also
|
|||
false/c)]{
|
||||
|
||||
Returns the line number (positive exact integer) for the start of the
|
||||
syntax object in its source, or @scheme[#f] if the line number or
|
||||
@tech{syntax object} in its source, or @scheme[#f] if the line number or
|
||||
source is unknown. The result is @scheme[#f] if and only if
|
||||
@scheme[(syntax-column stx)] produces @scheme[#f]. See also
|
||||
@secref["linecol"], and see @scheme[syntax-source] for information
|
||||
about marshaling compiled syntax objects.}
|
||||
about marshaling compiled @tech{syntax object}s.}
|
||||
|
||||
|
||||
@defproc[(syntax-column [stx syntax?])
|
||||
(or/c nonnegative-exact-integer?
|
||||
(or/c exact-nonnegative-integer?
|
||||
false/c)]{
|
||||
|
||||
Returns the column number (non-negative exact integer) for the start
|
||||
of the syntax object in its source, or @scheme[#f] if the source
|
||||
of the @tech{syntax object} in its source, or @scheme[#f] if the source
|
||||
column is unknown. The result is @scheme[#f] if and only if
|
||||
@scheme[(syntax-line stx)] produces @scheme[#f]. See also
|
||||
@secref["linecol"], and see @scheme[syntax-source] for information
|
||||
about marshaling compiled syntax objects.}
|
||||
about marshaling compiled @tech{syntax object}s.}
|
||||
|
||||
|
||||
@defproc[(syntax-position [stx syntax?])
|
||||
|
@ -47,33 +47,33 @@ about marshaling compiled syntax objects.}
|
|||
false/c)]{
|
||||
|
||||
Returns the character position (positive exact integer) for the start
|
||||
of the syntax object in its source, or @scheme[#f] if the source
|
||||
of the @tech{syntax object} in its source, or @scheme[#f] if the source
|
||||
position is unknown. See also @secref["linecol"], and see
|
||||
@scheme[syntax-source] for information about marshaling compiled
|
||||
syntax objects.}
|
||||
@tech{syntax object}s.}
|
||||
|
||||
|
||||
@defproc[(syntax-span [stx syntax?])
|
||||
(or/c nonnegative-exact-integer?
|
||||
(or/c exact-nonnegative-integer?
|
||||
false/c)]{
|
||||
|
||||
Returns the span (non-negative exact integer) in characters of the
|
||||
syntax object in its source, or @scheme[#f] if the span is
|
||||
@tech{syntax object} in its source, or @scheme[#f] if the span is
|
||||
unknown. See also @scheme[syntax-source] for information about
|
||||
marshaling compiled syntax objects.}
|
||||
marshaling compiled @tech{syntax object}s.}
|
||||
|
||||
|
||||
@defproc[(syntax-original? [stx syntax?]) boolean?]{
|
||||
|
||||
Returns @scheme[#t] if @scheme[stx] has the property that
|
||||
@scheme[read-syntax] and @scheme[read-honu-syntax] attach to the
|
||||
syntax objects that they generate (see @secref["stxprops"]), and if
|
||||
@tech{syntax object}s that they generate (see @secref["stxprops"]), and if
|
||||
@scheme[stx]'s @tech{lexical information} does not indicate that the
|
||||
object was introduced by a syntax transformer (see
|
||||
@secref["stxobj-model"]). The result is @scheme[#f] otherwise. This
|
||||
predicate can be used to distinguish syntax objects in an expanded
|
||||
predicate can be used to distinguish @tech{syntax object}s in an expanded
|
||||
expression that were directly present in the original expression, as
|
||||
opposed to syntax objects inserted by macros.}
|
||||
opposed to @tech{syntax object}s inserted by macros.}
|
||||
|
||||
|
||||
@defproc[(syntax-source-module [stx syntax?])
|
||||
|
@ -86,7 +86,7 @@ for the module whose source contains @scheme[stx], or @scheme[#f] if
|
|||
|
||||
@defproc[(syntax-e [stx syntax?]) any]{
|
||||
|
||||
Unwraps the immediate datum structure from a syntax object,
|
||||
Unwraps the immediate datum structure from a @tech{syntax object},
|
||||
leaving nested syntax structure (if any) in place. The result of
|
||||
@scheme[(syntax-e @scheme[stx])] is one of the following:
|
||||
|
||||
|
@ -98,64 +98,81 @@ leaving nested syntax structure (if any) in place. The result of
|
|||
|
||||
@item{the empty list}
|
||||
|
||||
@item{a vector containing syntax objects}
|
||||
@item{an immutable vector containing @tech{syntax object}s}
|
||||
|
||||
@item{an immutable box containing @tech{syntax object}s}
|
||||
|
||||
@item{some other kind of datum---usually a number, boolean, or string}
|
||||
|
||||
}
|
||||
|
||||
A @deftech{syntax pair} is a pair containing a syntax object as its
|
||||
A @deftech{syntax pair} is a pair containing a @tech{syntax object} as its
|
||||
first element, and either the empty list, a syntax pair, or a syntax
|
||||
object as its second element.
|
||||
|
||||
A syntax object that is the result of @scheme[read-syntax] reflects
|
||||
A @tech{syntax object} that is the result of @scheme[read-syntax] reflects
|
||||
the use of delimited @litchar{.} in the input by creating a syntax
|
||||
object for every pair of parentheses in the source, and by creating a
|
||||
pair-valued syntax object @italic{only} for parentheses in the
|
||||
pair-valued @tech{syntax object} @italic{only} for parentheses in the
|
||||
source. See @secref["parse-pair"] for more information.}
|
||||
|
||||
|
||||
@defproc[(syntax->list [stx syntax?])
|
||||
(or/c list? false/c)]{
|
||||
|
||||
Returns an immutable list of syntax objects or @scheme[#f]. The result
|
||||
is a list of syntax objects when @scheme[(syntax->datum stx)]
|
||||
would produce a list. In other words, @tech{syntax pairs} in
|
||||
@scheme[(syntax-e @scheme[stx])] are flattened.}
|
||||
Returns a list of @tech{syntax object}s or @scheme[#f]. The result is a list
|
||||
of @tech{syntax object}s when @scheme[(syntax->datum stx)] would produce a
|
||||
list. In other words, @tech{syntax pairs} in @scheme[(syntax-e stx)]
|
||||
are flattened.}
|
||||
|
||||
|
||||
@defproc[(syntax->datum ...) any]{
|
||||
@defproc[(syntax->datum [stx syntax?]) any]{
|
||||
|
||||
Returns a datum by stripping the lexical and source-location
|
||||
information from @scheme[stx]. Graph structure is preserved by the
|
||||
conversion.}
|
||||
Returns a datum by stripping the lexical information, source-location
|
||||
information, properties, and certificates from @scheme[stx]. Inside of
|
||||
pairs, (immutable) vectors, and (immutable) boxes, @tech{syntax object}s are
|
||||
recursively stripped.
|
||||
|
||||
The stripping operation does not mutate @scheme[stx]; it creates new
|
||||
pairs, vectors, and boxes as needed to strip lexical and
|
||||
source-location information recursively.}
|
||||
|
||||
@defproc[(datum->syntax [ctxt (or/c syntax? false/c)]
|
||||
[v any/c]
|
||||
[srcloc (or/c syntax? false/c
|
||||
(list/c any/c
|
||||
(or/c positive-exact-integer? false/c)
|
||||
(or/c nonnegative-exact-integer? false/c)
|
||||
(or/c nonnegative-exact-integer? false/c)
|
||||
(or/c positive-exact-integer? false/c)))]
|
||||
(or/c exact-positive-integer? false/c)
|
||||
(or/c exact-nonnegative-integer? false/c)
|
||||
(or/c exact-nonnegative-integer? false/c)
|
||||
(or/c exact-positive-integer? false/c)))]
|
||||
[prop (or/c syntax? false/c) #f]
|
||||
[cert (or/c syntax? false/c) #f])
|
||||
syntax?]{
|
||||
|
||||
Converts the @tech{datum} @scheme[v] to a @tech{syntax object}, using
|
||||
syntax objects already in @scheme[v] in the result. Converted objects
|
||||
in @scheme[v] are given the lexical context information of
|
||||
@scheme[ctxt] and the source-location information of
|
||||
@scheme[srcloc]. If @scheme[v] is not already a syntax object, then
|
||||
the resulting immediate syntax object it is given the properties (see
|
||||
@secref["stxprops"]) of @scheme[prop] and the @tech{inactive certificates}
|
||||
(see @secref["stxcerts"]) of @scheme[cert]. Any of
|
||||
@scheme[ctxt], @scheme[srcloc], @scheme[prop], or @scheme[cert] can be
|
||||
@scheme[#f], in which case the resulting syntax has no lexical
|
||||
Converts the @tech{datum} @scheme[v] to a @tech{syntax object}. If
|
||||
@scheme[v] is a pair, vector, or box, then the contents are
|
||||
recursively converted; mutable vectors and boxes are essentially
|
||||
replaced by immutable vectors and boxes. @tech{Syntax object}s already in
|
||||
@scheme[v] are preserved as-is in the result. For any kind of value
|
||||
other than a pair, vector, box, or @tech{syntax object}, conversion means
|
||||
wrapping the value with lexical information, source-location
|
||||
information, properties, and certificates.
|
||||
|
||||
Converted objects in @scheme[v] are given the lexical context
|
||||
information of @scheme[ctxt] and the source-location information of
|
||||
@scheme[srcloc]. If @scheme[v] is not already a @tech{syntax object}, then
|
||||
the resulting immediate @tech{syntax object} is given the properties (see
|
||||
@secref["stxprops"]) of @scheme[prop] and the @tech{inactive
|
||||
certificates} (see @secref["stxcerts"]) of @scheme[cert]; if
|
||||
@scheme[v] is a pair, vector, or box, recursively converted values are
|
||||
not given properties or certificates.
|
||||
|
||||
Any of @scheme[ctxt], @scheme[srcloc], @scheme[prop], or @scheme[cert]
|
||||
can be @scheme[#f], in which case the resulting syntax has no lexical
|
||||
context, source information, new properties, and/or certificates.
|
||||
|
||||
If @scheme[srcloc] is not @scheme[#f]
|
||||
or a syntax object, it must be a list of five elements:
|
||||
or a @tech{syntax object}, it must be a list of five elements:
|
||||
|
||||
@schemeblock[
|
||||
(list source-name line column position span)
|
||||
|
@ -170,15 +187,14 @@ name; @scheme[line] is an integer for the source line, or @scheme[#f];
|
|||
numbers or both be @scheme[#f], otherwise the
|
||||
@exnraise[exn:fail:contract].
|
||||
|
||||
Graph structure is preserved by the conversion of @scheme[v] to a
|
||||
syntax object, but graph structure that is distributed among distinct
|
||||
syntax objects in @scheme[v] may be hidden from future applications of
|
||||
@scheme[syntax->datum] and @scheme[syntax-graph?] to the new
|
||||
syntax object.}
|
||||
Graph structure is not preserved by the conversion of @scheme[v] to a
|
||||
@tech{syntax object}. Instead, @scheme[v] is essentially unfolded into a
|
||||
tree. If @scheme[v] has a cycle through pairs, vectors, and boxes,
|
||||
then the @exnraise[exn:fail:contract].}
|
||||
|
||||
@defproc[(identifier? [v any/c]) boolean?]{
|
||||
|
||||
Returns @scheme[#t] if @scheme[v] is a syntax object and
|
||||
Returns @scheme[#t] if @scheme[v] is a @tech{syntax object} and
|
||||
@scheme[(syntax-e stx)] produces a symbol.}
|
||||
|
||||
|
||||
|
|
|
@ -3,7 +3,9 @@
|
|||
scribble/bnf
|
||||
scribble/eval
|
||||
"utils.ss"
|
||||
(for-syntax scheme/base))
|
||||
(for-syntax scheme/base)
|
||||
(for-label (only-in scribble/reader
|
||||
use-at-readtable)))
|
||||
|
||||
@(define read-eval (make-base-eval))
|
||||
@interaction-eval[#:eval read-eval (require (for-syntax scheme/base))]
|
||||
|
@ -30,7 +32,8 @@ A PLT Scheme manual more likely starts with
|
|||
|
||||
which installs a reader, wraps the file content afterward into a
|
||||
MzScheme module, and parses the body into a document using
|
||||
@filepath{decode.ss}. See @secref["docreader"] for more information.
|
||||
@schememodname[scribble/decode]. See @secref["docreader"] for more
|
||||
information.
|
||||
|
||||
Another way to use the reader is to use the @scheme[use-at-readtable]
|
||||
function to switch the current readtable to a readtable that parses
|
||||
|
|
|
@ -4,10 +4,9 @@ in several significant ways:
|
|||
|
||||
- The documentation has been re-organized and re-written. Instead of
|
||||
just reference manuals that occasionally provide examples, our
|
||||
documentation is now based on "guides" that provides a friendly
|
||||
overview and extensive examples, and then separate "references"
|
||||
that provide the details (typically in a more terse, precise
|
||||
style).
|
||||
documentation is now based on a "guide" that provides a friendly
|
||||
overview and examples, and then separate "references" that provide
|
||||
the details (typically in a more terse, precise style).
|
||||
|
||||
- Pairs created with `cons', `list', `map', etc. are immutable. A
|
||||
separate datatype, "mpair", implements mutable pairs, with the
|
||||
|
@ -83,6 +82,9 @@ in several significant ways:
|
|||
used carefully; library functions should typically allow "~" to be
|
||||
a relative path).
|
||||
|
||||
- Literal vectors and boxes are immutable, as are vectors and boxes
|
||||
produced by `syntax->datum'.
|
||||
|
||||
- Hash table printing is enabled by default, and vector-length
|
||||
printing is disabled by default. Opaque structure instances no
|
||||
longer print with a leading "struct:" between angle brackets, and
|
||||
|
@ -91,7 +93,9 @@ in several significant ways:
|
|||
|
||||
- Graph input syntax, such as `#0=(1 . #0#)' is no longer allowed in
|
||||
program syntax parsed by `read-syntax', though it is still allowed
|
||||
for `read'.
|
||||
for `read'. The `datum->syntax' function now raises an exception
|
||||
when given a cyclic value, and non-cyclic graph structure (though
|
||||
pairs, vectors, and boxes) is not preserved.
|
||||
|
||||
- In fully expanded code, `#%datum' expands to `quote'. When using
|
||||
the `mzscheme' language, beware that `if' in expansions is the `if'
|
||||
|
@ -115,10 +119,10 @@ in several significant ways:
|
|||
`prop:equal+hash' property allows customization of `equal?' for a
|
||||
structure type.
|
||||
|
||||
- The contract library (in `scheme/contract') no longer exports
|
||||
object or mixin contracts. Instead they are exported from
|
||||
`scheme/class'. (The libraries in "mzlib" remain the same as
|
||||
before.)
|
||||
- The contract library (in `scheme/contract') does not export object
|
||||
or mixin contracts. Instead they are exported from
|
||||
`scheme/class'. The libraries in the "mzlib" collection remain as
|
||||
before.
|
||||
|
||||
======================================================================
|
||||
Immutable and Mutable Pairs
|
||||
|
@ -126,13 +130,14 @@ in several significant ways:
|
|||
|
||||
Making pairs immutable helps prevent security and design holes that
|
||||
result form unexpected mutation of lists; Schemers do not usually
|
||||
think about lists as mutable, and they wrote code that fails in exotic
|
||||
think about lists as mutable, and they write code that fails in exotic
|
||||
ways if a list is mutated concurrently. For similar reasons, immutable
|
||||
lists work better with higher-order contracts.
|
||||
|
||||
Although this change may sound drastic, our experience to date is that
|
||||
uses of mutable pairs are isolated and easy to convert to either
|
||||
mpairs or functional style.
|
||||
mpairs or functional style. The new `scheme/mpair' library provides
|
||||
functions for processing mutable lists.
|
||||
|
||||
For compatbility, the `cons' exported by the `r5rs' language module is
|
||||
an alias for `mcons', and the various list-consuming and -producing
|
||||
|
@ -194,7 +199,7 @@ language module, instead of `mzscheme' or its close analogue
|
|||
Big" language: in addition to the core forms, it supplies contracts,
|
||||
the class system, the unit system, and the pretty printer. More
|
||||
precisely, the default module is `scheme/init', which is like
|
||||
`scheme', but it installs the pretty printer.
|
||||
`scheme', but installs the pretty printer and `help' form.
|
||||
|
||||
The initial top-level environment is completely empty. Command-line
|
||||
flags like `-l' introduce bindings into the environment. Such bindings
|
||||
|
|
|
@ -4456,6 +4456,7 @@ static Scheme_Object *read_compact(CPort *port, int use_stack)
|
|||
break;
|
||||
case CPT_BOX:
|
||||
v = scheme_box(read_compact(port, 0));
|
||||
SCHEME_SET_IMMUTABLE(v);
|
||||
break;
|
||||
case CPT_PAIR:
|
||||
if (need_car) {
|
||||
|
@ -4497,6 +4498,10 @@ static Scheme_Object *read_compact(CPort *port, int use_stack)
|
|||
SCHEME_VEC_ELS(vec)[i] = cv;
|
||||
}
|
||||
|
||||
if (l) {
|
||||
SCHEME_SET_IMMUTABLE(vec);
|
||||
}
|
||||
|
||||
v = vec;
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -10,12 +10,12 @@
|
|||
The string and the separate X/Y/Z/W numbers must
|
||||
be updated consistently. */
|
||||
|
||||
#define MZSCHEME_VERSION "3.99.0.9"
|
||||
#define MZSCHEME_VERSION "3.99.0.10"
|
||||
|
||||
#define MZSCHEME_VERSION_X 3
|
||||
#define MZSCHEME_VERSION_Y 99
|
||||
#define MZSCHEME_VERSION_Z 0
|
||||
#define MZSCHEME_VERSION_W 9
|
||||
#define MZSCHEME_VERSION_W 10
|
||||
|
||||
#define MZSCHEME_VERSION_MAJOR ((MZSCHEME_VERSION_X * 100) + MZSCHEME_VERSION_Y)
|
||||
#define MZSCHEME_VERSION_MINOR ((MZSCHEME_VERSION_Z * 1000) + MZSCHEME_VERSION_W)
|
||||
|
|
|
@ -4575,6 +4575,7 @@ static Scheme_Object *syntax_to_datum_inner(Scheme_Object *o,
|
|||
} else if (SCHEME_BOXP(v)) {
|
||||
v = syntax_to_datum_inner(SCHEME_BOX_VAL(v), with_marks, mt);
|
||||
result = scheme_box(v);
|
||||
SCHEME_SET_IMMUTABLE(result);
|
||||
} else if (SCHEME_VECTORP(v)) {
|
||||
int size = SCHEME_VEC_SIZE(v), i;
|
||||
Scheme_Object *r, *a;
|
||||
|
@ -4585,8 +4586,10 @@ static Scheme_Object *syntax_to_datum_inner(Scheme_Object *o,
|
|||
a = syntax_to_datum_inner(SCHEME_VEC_ELS(v)[i], with_marks, mt);
|
||||
SCHEME_VEC_ELS(r)[i] = a;
|
||||
}
|
||||
|
||||
|
||||
result = r;
|
||||
if (size)
|
||||
SCHEME_SET_IMMUTABLE(result);
|
||||
} else
|
||||
result = v;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user