same (leftSchema rightSchema -- isSameSchema)
Inputs
leftSchema: First object or Ref whose dereferenced schema is compared.rightSchema: Second object or Ref whose dereferenced schema is compared.
Outputs
same is a dereferenced-schema equality predicate. It tests whether two dereferenced schemas are identical.
All input objects are accepted. Only the two dereferenced schemas participate in the result, so current value contents, value knowledge, and Ref mutability do not participate after dereferencing.
Different dereferenced schemas make same return FALSE instead of raising an error.
same therefore answers exact schema identity, not runtime compatibility or naming. Matching schemaName text does not imply same, and runtime comparisons such as = and is answer different questions.
Use same for exact dereferenced-schema identity, = for dereferenced value equality, and is for identity-like equality.
Behavior
- Schema kinds carry extra structure. Two separately written Block objects therefore have different schemas even when they look similar.
Example
{} 0 {} [
value: 0 dynamic;
"-- same schema, different values or value knowledge --" printCompilerMessage
0 1 same printStack _:;
0 dynamic 1 dynamic same printStack _:;
0 1 = printStack _:;
0 1 is printStack _:;
"-- different schemas give FALSE, not an error --" printCompilerMessage
0 0n32 same printStack _:;
7 FALSE same printStack _:;
"-- matching schemaName text is not enough --" printCompilerMessage
left: {
SCHEMA_NAME: "Point" virtual;
x: 0;
};
right: {
SCHEMA_NAME: "Point" virtual;
y: 0;
};
left schemaName printStack _:;
right schemaName printStack _:;
left right same printStack _:;
"-- references are dereferenced first --" printCompilerMessage
@value value same printStack _:;
"-- separate block literals have different schemas --" printCompilerMessage
[] [] same printStack _:;
"-- same block schema read twice --" printCompilerMessage
block: [];
@block @block same printStack _:;
"-- text schema only --" printCompilerMessage
"hi" "ho" same printStack _:;
"hi" "ho" = printStack _:;
"hi" "ho" is printStack _:;
0
] "main" exportFunction
Expected Output During Compilation
-- same schema, different values or value knowledge --
TRUE
TRUE
FALSE
FALSE
-- different schemas give FALSE, not an error --
FALSE
FALSE
-- matching schemaName text is not enough --
"Point"
"Point"
FALSE
-- references are dereferenced first --
TRUE
-- separate block literals have different schemas --
FALSE
-- same block schema read twice --
TRUE
-- text schema only --
TRUE
FALSE
FALSE
See also
alignmentbuiltin(schema -- alignment)Returns the storage alignment requirement of the dereferenced schema.=builtin(leftValue rightValue -- isEqual)Dereferenced-value equality for same-schemaCond, numeric, andTextvalues.isbuiltin(leftValue rightValue -- isIdentityLike)Identity-like equality on same-schema values; Ref-like objects can compareTRUE, while other same-schema inputs giveFALSE.code?builtin(schema -- isBlock)Historical Block-schema test.codeRef?builtin(schema -- isCode)Codedereferenced-schema test.isCombinedbuiltin(schema -- isCombined)Struct-group dereferenced-schema test.managed?builtin(schema -- isManaged)Managed-lifetime dereferenced-schema test.schemaNamebuiltin(schema -- reportedName)Reported name of the dereferenced schema.storageSizebuiltin(schema -- size)Returns the storage size of the dereferenced schema.virtual?builtin(schema -- isMeta)Historical Meta-schema test.