2005-07-16 22:16:18 -04:00
|
|
|
! Copyright (C) 2005 Slava Pestov.
|
|
|
|
|
! See http://factor.sf.net/license.txt for BSD license.
|
|
|
|
|
IN: sequences
|
|
|
|
|
USING: kernel kernel-internals lists math strings vectors ;
|
|
|
|
|
|
|
|
|
|
! Note that the sequence union does not include lists, or user
|
|
|
|
|
! defined tuples that respond to the sequence protocol.
|
|
|
|
|
UNION: sequence array string sbuf vector ;
|
|
|
|
|
|
2005-09-07 18:56:42 -04:00
|
|
|
: length= ( seq seq -- ? ) length swap length number= ; flushable
|
2005-07-16 22:16:18 -04:00
|
|
|
|
|
|
|
|
: sequence= ( seq seq -- ? )
|
|
|
|
|
#! Check if two sequences have the same length and elements,
|
|
|
|
|
#! but not necessarily the same class.
|
2005-08-25 15:27:38 -04:00
|
|
|
2dup length= [
|
|
|
|
|
dup length [ >r 2dup r> 2nth = ] all? 2nip
|
2005-07-16 22:16:18 -04:00
|
|
|
] [
|
2005-08-25 15:27:38 -04:00
|
|
|
2drop f
|
2005-08-19 22:22:15 -04:00
|
|
|
] ifte ; flushable
|
2005-07-16 22:16:18 -04:00
|
|
|
|
|
|
|
|
M: sequence = ( obj seq -- ? )
|
|
|
|
|
2dup eq? [
|
|
|
|
|
2drop t
|
|
|
|
|
] [
|
|
|
|
|
over type over type eq? [ sequence= ] [ 2drop f ] ifte
|
|
|
|
|
] ifte ;
|
2005-07-19 04:23:33 -04:00
|
|
|
|
|
|
|
|
M: string = ( obj str -- ? )
|
|
|
|
|
over string? [
|
|
|
|
|
over hashcode over hashcode number=
|
|
|
|
|
[ sequence= ] [ 2drop f ] ifte
|
|
|
|
|
] [
|
|
|
|
|
2drop f
|
|
|
|
|
] ifte ;
|