rapidly scribbling documentation

This commit is contained in:
Danny Yoo 2011-07-03 20:16:06 -04:00
parent 3693506796
commit 35054f8b18
3 changed files with 78 additions and 3 deletions

View File

@ -153,14 +153,14 @@
buffer.push(this._constructorName);
for(var i = 0; i < this._fields.length; i++) {
buffer.push(" ");
buffer.push(toWrittenString(this._fields[i], cache));
buffer.push(plt.helpers.toWrittenString(this._fields[i], cache));
}
buffer.push(")");
return buffer.join("");
};
Struct.prototype.toDisplayedString = function(cache) {
return toWrittenString(this, cache);
return plt.helpers.toWrittenString(this, cache);
};
Struct.prototype.toDomNode = function(cache) {
@ -170,7 +170,7 @@
node.appendChild(document.createTextNode(this._constructorName));
for(var i = 0; i < this._fields.length; i++) {
node.appendChild(document.createTextNode(" "));
appendChild(node, toDomNode(this._fields[i], cache));
appendChild(node, plt.helpers.toDomNode(this._fields[i], cache));
}
node.appendChild(document.createTextNode(")"));
return node;

View File

@ -2526,6 +2526,12 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['HaltError'] = HaltError;
exports['makeStructureType'] = plt.baselib.structs.makeStructureType;
exports['Struct'] = plt.baselib.structs.Struct;
exports['StructType'] = plt.baselib.structs.StructType;
scope.link.announceReady('runtime');

View File

@ -710,6 +710,75 @@ tested with @tt{plt.runtime.isBox()}, and they support two methods:
@subsubsection{Structures}
structure types can be made with plt.runtime.makeStructureType. For example,
@verbatim|{
var Color = plt.runtime.makeStructureType(
'color', // name
false, // parent structure type
3, // required number of arguments
0, // number of automatically-filled fields
false, // OPTIONAL: the auto-v value
false, // OPTIONAL: a guard procedure
);
}|
@tt{makeStructuretype} is meant to mimic the @racket[make-struct-type]
function in Racket. It produces a structure type value with the
following methods:
@itemlist[
@item{@tt{constructor}: create an instance of a structure type.
For example,
@verbatim|{
var aColor = Color.constructor(3, 4, 5);
}|
creates an instance of the Color structure type.
}
@item{@tt{predicate}: test if a value is of the given structure type.
For example,
@verbatim|{
Color.predicate(aColor) --> true
Color.predicate("red") --> false
}|
}
@item{@tt{accessor}: access a field of a structure.
For example,
@verbatim|{
var colorRed = function(x) { return Color.accessor(x, 0); };
var colorGreen = function(x) { return Color.accessor(x, 1); };
var colorBlue = function(x) { return Color.accessor(x, 2); };
}|
}
@item{@tt{mutator}: mutate a field of a structure.
For example,
@verbatim|{
var setColorRed = function(x, v) { return Color.mutator(x, 0, v); };
}|
}
]
In addition, it has a @tt{type} whose @tt{prototype} can be changed in order
to add methods to an instance of a structure type. For example,
@verbatim|{
Color.type.prototype.toString = function() {
return "rgb(" + colorRed(this) + ", "
+ colorGreen(this) + ", "
+ colorBlue(this) + ")";
};
}|
should add a toString method for instances of the @tt{Color} structure.
@;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@subsection{Tests}