RegisterEssentials:
PROC [env: Environment] ~ {
nArgsPS: ARRAY PrimitiveSyntaxRep OF NAT ~ [quote: 1, define: 2, setBang: 2, lambda: 1, begin: 0, if: 3];
dottedPS: ARRAY PrimitiveSyntaxRep OF BOOL ~ [quote: FALSE, define: FALSE, setBang: FALSE, lambda: TRUE, begin: TRUE, if: FALSE];
FOR p: PrimitiveSyntaxRep
IN PrimitiveSyntaxRep
DO
symbol: Symbol ~ symbolForPrimitiveSyntaxRep[p];
expander: Primitive ~ NEW[PrimitiveRep ¬ [minArgs: nArgsPS[p], maxArgs: nArgsPS[p], dotted: dottedPS[p], proc: ExpandPrimitiveSyntaxPrim, doc: Rope.Concat[RopeFromSymbol[symbol], " primitive syntax"], data: NEW[PrimitiveSyntaxRep ¬ p], symbol: symbol]];
value: Syntax ~ NEW[SyntaxRep ¬ [expander: expander]];
DefineVariable[variable: symbol, value: value, env: env];
ENDLOOP;
DefineComparisons[type: $numeric, env: env];
DefineComparisons[type: $string, env: env, case: TRUE];
DefineComparisons[type: $char, env: env, case: TRUE];
DefinePrimitive[name: "eq?", nArgs: 2, dotted: FALSE, proc: EqPredPrim, env: env,
doc: "Pointer equality"];
DefinePrimitive[name: "eqv?", nArgs: 2, dotted: FALSE, proc: EqvPredPrim, env: env,
doc: "operational equivalence"];
DefinePrimitive[name: "cons", nArgs: 2, dotted: FALSE, proc: ConsPrim, env: env,
doc: "New pair"];
FOR i:
NAT
IN [2..32)
DO
name: ROPE ~ CXRName[i];
DefinePrimitive[name: name, nArgs: 1, dotted: FALSE, proc: CXRPrim, env: env, data: NEW[NAT ¬ i], doc: name];
ENDLOOP;
DefinePrimitive[name: "list", nArgs: 0, dotted: TRUE, proc: ListPrim, env: env, data: $list, doc: "Construct a list of the arguments"];
DefinePrimitive[name: "length", nArgs: 1, dotted: FALSE, proc: ListPrim, env: env, data: $length, doc: "length of a list"];
DefinePrimitive[name: "boolean?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env, data: LIST[false], doc: "test for boolean type"];
DefinePrimitive[name: "char?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env, data: LIST[MakeChar['a]], doc: "test for character type"];
DefinePrimitive[name: "pair?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env,
data: LIST[Cons[NIL, NIL], LIST[NIL]], doc: "test for pair type"];
DefinePrimitive[name: "symbol?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env,
data: LIST[$a], doc: "test for symbol type"];
DefinePrimitive[name: "vector?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env,
data: LIST[NEW[SimpleVectorRep[0]], NEW[VectorRep ¬ [0, NIL, NIL, NIL]]], doc: "test for vector type"];
DefinePrimitive[name: "string?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env,
data: LIST[emptyString], doc: "test for string type"];
DefinePrimitive[name: "procedure?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env,
data: LIST[NEW[PrimitiveRep], NEW[TidbitProcedureRep]], doc: "test for procedure type"];
DefinePrimitive[name: "number?", nArgs: 1, dotted: FALSE, proc: TypePredPrim, env: env, data: LIST[MakeFixnum[0], NEW[NumberRep ¬ [TRUE, flonum[0.0]]]], doc: "test for number type"];
DefinePrimitive[name: "memv", nArgs: 2, dotted: FALSE, proc: MemberPrim, env: env, data: LookupVariableValue[SymbolFromRope["eqv?"], env], doc: "membership test using eqv?"];
DefinePrimitive[name: "memq", nArgs: 2, dotted: FALSE, proc: MemberPrim, env: env, data: NIL, doc: "membership test using eq?"];
DefinePrimitive[name: "assv", nArgs: 2, dotted: FALSE, proc: AssocPrim, env: env, data: LookupVariableValue[SymbolFromRope["eqv?"], env], doc: "association list lookup using eqv?"];
DefinePrimitive[name: "assq", nArgs: 2, dotted: FALSE, proc: AssocPrim, env: env, data: NIL, doc: "association list lookup using eq?"];
DefinePrimitive[name: "set-car!", nArgs: 2, dotted: FALSE, proc: SetPrim, env: env, data: $car, doc: "Store object in car field"];
DefinePrimitive[name: "set-cdr!", nArgs: 2, dotted: FALSE, proc: SetPrim, env: env, data: $cdr, doc: "Store object in cdr field"];
DefinePrimitive[name: "symbol->string", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$symbol, $string], doc: "convert a symbol to a string"];
DefinePrimitive[name: "string->symbol", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$string, $symbol], doc: "convert a string to a symbol"];
DefinePrimitive[name: "string->list", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$string, $list], doc: "convert a string to a list"];
DefinePrimitive[name: "list->string", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$list, $string], doc: "convert a list to a string"];
DefinePrimitive[name: "list->vector", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$list, $vector], doc: "convert a list to a vector"];
DefinePrimitive[name: "char->integer", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$char, $integer], doc: "convert a char to an integer"];
DefinePrimitive[name: "integer->char", nArgs: 1, dotted: FALSE, proc: ConvertPrim, env: env, data: LIST[$integer, $char], doc: "convert an integer to a char"];
DefinePrimitive[name: "make-string", nArgs: 2, optional: 1, dotted: FALSE, proc: MakePrim, env: env, data: $string, doc: "make a new string"];
DefinePrimitive[name: "string-length", nArgs: 1, dotted: FALSE, proc: StringPrim, env: env, data: $length, doc: "length of a string"];
DefinePrimitive[name: "string-ref", nArgs: 2, dotted: FALSE, proc: StringPrim, env: env, data: $ref, doc: "element b in string a"];
DefinePrimitive[name: "string-set!", nArgs: 3, dotted: FALSE, proc: StringPrim, env: env, data: $set, doc: "set element b in string a to c"];
DefinePrimitive[name: "substring", nArgs: 3, dotted: FALSE, proc: StringPrim, env: env, data: $substring, doc: "substring of a starting at b and ending before c"];
DefinePrimitive[name: "string-copy", nArgs: 1, dotted: FALSE, proc: StringPrim, env: env, data: $copy, doc: "copy the string"];
DefinePrimitive[name: "essential-string-append", nArgs: 2, dotted: FALSE, proc: StringPrim, env: env, data: $append, doc: "append two strings"];
DefinePrimitive[name: "string-fill!", nArgs: 2, dotted: FALSE, proc: StringPrim, env: env, data: $fill, doc: "fill string a with character b"];
DefinePrimitive[name: "make-vector", nArgs: 2, optional: 1, dotted: FALSE, proc: MakePrim, env: env, data: $vector, doc: "make a new vector"];
DefinePrimitive[name: "vector-length", nArgs: 1, dotted: FALSE, proc: VectorPrim, env: env, data: $length, doc: "length of a vector"];
DefinePrimitive[name: "vector-ref", nArgs: 2, dotted: FALSE, proc: VectorPrim, env: env, data: $ref, doc: "element b in vector a"];
DefinePrimitive[name: "vector-set!", nArgs: 3, dotted: FALSE, proc: VectorPrim, env: env, data: $set, doc: "set element b in vector a to c"];
};
RegisterOptionals:
PROC [env: Environment] ~ {
DefineComparisons[type: $numeric, env: env, nAry: TRUE];
DefineComparisons[type: $string, env: env, case: TRUE, nAry: TRUE];
DefineComparisons[type: $char, env: env, case: TRUE, nAry: TRUE];
DefineComparisons[type: $string, env: env, case: FALSE, nAry: TRUE];
DefineComparisons[type: $char, env: env, case: FALSE, nAry: TRUE];
DefinePrimitive[name: "reverse", nArgs: 1, dotted: FALSE, proc: ListPrim, env: env, data: $reverse, doc: "reverse a list"];
DefinePrimitive[name: "char-alphabetic?", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $alphaPred,
doc: "test for an alphabetic character"];
DefinePrimitive[name: "char-upper-case?", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $upperPred,
doc: "test for an upper-case letter"];
DefinePrimitive[name: "char-lower-case?", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $lowerPred,
doc: "test for a lower-case letter"];
DefinePrimitive[name: "char-numeric?", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $numericPred,
doc: "test for a digit"];
DefinePrimitive[name: "char-whitespace?", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $whitespacePred,
doc: "test for whitespace"];
DefinePrimitive[name: "char-upcase", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $upcase,
doc: "convert char to upper case"];
DefinePrimitive[name: "char-downcase", nArgs: 1, dotted: FALSE, proc: CharPrim, env: env, data: $downcase,
doc: "convert char to lower case"];
};
RegisterExtensions:
PROC [env: Environment] ~ {
DefinePrimitive[name: "make-syntax", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "Make a syntax object", data: $make];
DefinePrimitive[name: "syntax?", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "Is this a syntax expander?", data: $syntaxP];
DefinePrimitive[name: "syntax-expander", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "Extract the expansion function from a syntax object", data: $expander];
DefinePrimitive[name: "primitive-syntax-marker->symbol", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "Convert a primitive syntax marker to a symbol", data: $toSymbol];
DefinePrimitive[name: "symbol->primitive-syntax-marker", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "Convert a symbol to a primitive syntax marker", data: $toMarker];
DefinePrimitive[name: "primitive-syntax-marker?", nArgs: 1, dotted: FALSE, proc: SyntaxPrim, env: env,
doc: "test for a primitive syntax marker", data: $primitiveSyntaxP];
DefinePrimitive[name: "gensym", nArgs: 1, optional: 1, dotted: FALSE, proc: GensymPrim, env: env, data: NIL, doc: "generate a new symbol [with prefix a]"];
DefinePrimitive[name: "sort", nArgs: 3, optional: 1, dotted: FALSE, proc: ListPrim, env: env, data: $sort, doc: "(list predicate [ key ]) sort a list"];
DefinePrimitive[name: "eq-hash", nArgs: 1, dotted: FALSE, proc: HashPrim, env: env, data: $eqHash, doc: "Hash function respecting the EQ? predicate"];
DefinePrimitive[name: "eqv-hash", nArgs: 1, dotted: FALSE, proc: HashPrim, env: env, data: $eqvHash, doc: "Hash function respecting the EQV? predicate"];
DefinePrimitive[name: "random", nArgs: 1, dotted: FALSE, proc: RandomPrim, env: env, doc: "Returns a random integer in the range [0..a)"];
DefinePrimitive[name: "string-match?", nArgs: 2, dotted: FALSE, proc: StringPrim, env: env, data: $stringmatch, doc: "(pattern-string target) Does pattern-string match target? Use \"*\" as a wildcard."];
DefinePrimitive[name: "string-ci-match?", nArgs: 2, dotted: FALSE, proc: StringPrim, env: env, data: $stringcimatch, doc: "(pattern-string target) Does pattern-string match target, ignoring case? Use \"*\" as a wildcard."];
DefinePrimitive[name: "%make-record", nArgs: 1, optional: 0, dotted: FALSE, proc: RecordPrim, env: env, data: $make, doc: "(length) PRIVATE: make a new structure object of the given length"];
DefinePrimitive[name: "%record-ref", nArgs: 2, optional: 0, dotted: FALSE, proc: RecordPrim, env: env, data: $ref, doc: "(structure index) PRIVATE: get a field of a structure"];
DefinePrimitive[name: "%record-set!", nArgs: 3, optional: 0, dotted: FALSE, proc: RecordPrim, env: env, data: $set, doc: "(structure index value) PRIVATE: set a field of a structure"];
DefinePrimitive[name: "%record-length", nArgs: 1, optional: 0, dotted: FALSE, proc: RecordPrim, env: env, data: $length, doc: "(structure) PRIVATE: return length of a structure object"];
DefinePrimitive[name: "%record?", nArgs: 1, optional: 0, dotted: FALSE, proc: RecordPrim, env: env, data: $test, doc: "(value) PRIVATE: is this a structure?"];
};