tuple= ( tuple1 tuple2 -- ? ) (original) (raw)

tuple= ( tuple1 tuple2 -- ? )
Factor handbook » The language » Objects » Tuples » Tuple introspection

Prev: slots>tuple ( seq class -- tuple )
Next: define-tuple-class ( class superclass slots -- )

Vocabulary
classes.tuple

Inputs

tuple1 a tuple
tuple2 a tuple

Outputs

? a boolean

Word description
Checks if two tuples have equal slot values. This is the default behavior of = on tuples, unless the tuple class subclasses identity-tuple or implements a method on equal?. In cases where equality has been redefined, this word can be used to get the default semantics if needed.

Definition

USING: classes.tuple.private kernel math sequences.private ;

IN: classes.tuple

: tuple= ( tuple1 tuple2 -- ? )
2dup [ tuple? ] both? [
2dup [ layout-of ] bi@ eq? [
[ drop tuple-size ] [
[ [ drop array-nth ] [ nip array-nth ] 3bi = ]
2curry
] 2bi all-integers?
] [ 2drop f ] if
] [ 2drop f ] if ; inline