factor/core/arrays/arrays.factor

33 lines
872 B
Factor
Raw Normal View History

2008-07-16 17:48:09 -04:00
! Copyright (C) 2005, 2008 Slava Pestov.
2007-09-20 18:09:08 -04:00
! See http://factorcode.org/license.txt for BSD license.
2008-07-16 17:48:09 -04:00
USING: accessors kernel kernel.private math math.private
sequences sequences.private ;
2007-09-20 18:09:08 -04:00
IN: arrays
M: array clone (clone) ;
2008-07-16 17:48:09 -04:00
M: array length length>> ;
M: array nth-unsafe [ >fixnum ] dip array-nth ;
M: array set-nth-unsafe [ >fixnum ] dip set-array-nth ;
2007-09-20 18:09:08 -04:00
M: array resize resize-array ;
: >array ( seq -- array ) { } clone-like ;
M: object new-sequence drop 0 <array> ;
2007-09-20 18:09:08 -04:00
M: f new-sequence drop dup zero? [ drop f ] [ 0 <array> ] if ;
2007-09-20 18:09:08 -04:00
M: array equal?
over array? [ sequence= ] [ 2drop f ] if ;
INSTANCE: array sequence
2008-08-22 18:38:23 -04:00
: 1array ( x -- array ) 1 swap <array> ; inline
2007-09-20 18:09:08 -04:00
2008-08-22 18:38:23 -04:00
: 2array ( x y -- array ) { } 2sequence ; inline
2007-09-20 18:09:08 -04:00
2008-08-22 18:38:23 -04:00
: 3array ( x y z -- array ) { } 3sequence ; inline
2007-09-20 18:09:08 -04:00
2008-08-22 18:38:23 -04:00
: 4array ( w x y z -- array ) { } 4sequence ; inline
2007-09-20 18:09:08 -04:00
2008-03-26 19:23:19 -04:00
PREDICATE: pair < array length 2 number= ;