same

same (leftSchema rightSchema -- isSameSchema)

Inputs

Outputs

same is a dereferenced-schema equality predicate. It tests whether two dereferenced schemas are identical.

All input values 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

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