1 ! Copyright (C) 2007 Robbert van Dalen.
2 ! See http://factorcode.org/license.txt for BSD license.
4 IN: isequences.interface
5 USING: generic kernel ;
7 ! Unifies sequences, integers and objects, following Enchilada semantics.
8 ! Efficiency is achieved through lazy immutable size-balanced binary trees.
10 ! - An object is an isequence of size 1 containing itself
11 ! - An integer is an isequence of size itself containing zeros
12 ! - If a sequence is never modified it is also considered an isequence
13 ! - An isequence can have negative sign
16 GENERIC: -- ( s -- -s ) ! monadic negate
17 GENERIC: $$ ( s1 -- h ) ! monadic hash
18 GENERIC: ++ ( s1 s2 -- s ) ! dyadic concatenate
20 GENERIC: i-length ( s -- n ) ! monadic size
21 GENERIC: i-cmp ( s1 s2 -- n ) ! dyadic compare
22 GENERIC# i-at 1 ( s n -- v ) ! dyadic index
24 GENERIC# ihead 1 ( s n -- s ) ! dyadic head of a cut
25 GENERIC# itail 1 ( s n -- s ) ! dyadic tail of a cut
27 GENERIC: ileft ( s -- v ) ! balanced left side
28 GENERIC: iright ( s -- v ) ! balanced right side
29 GENERIC: ipair ( s1 s2 -- s ) ! pairing two isequences
31 GENERIC: ascending? ( s -- ? ) ! monadic ascending query
32 GENERIC: descending? ( s -- ? ) ! monadic descending query
34 GENERIC: left-side ( v -- v )
35 GENERIC: right-side ( v -- v )
36 GENERIC: left-side-empty? ( s -- ? )
37 GENERIC: right-side-empty? ( s -- ? )
38 GENERIC: :v: ( v -- v )
41 ! **** lazy turn of an isequence
43 GENERIC: :: ( s -- ts )
45 ! **** lazy reversal of an isequence
47 GENERIC: `` ( s -- rs )
49 ! **** lazy right division of an isequence
51 GENERIC: _/ ( n s -- n/s )
53 ! **** lazy left division of an isequence ****
55 GENERIC: /_ ( s1 n -- s1/n )
57 ! **** full division of two isequences ****
59 : // ( s1 s2 -- n1/s2 s1/n2 ) 2dup /_ -rot _/ ; inline
61 ! **** matching two isequences ****
63 GENERIC: >> ( s1 s2 -- s1/s2 )
67 GENERIC: ~~ ( s -- s )
69 ! **** lazy maximum of two isequences
71 GENERIC: || ( s1 s2 -- max-s1-s2 )
73 ! **** lazy minimum of two isequences ****
75 GENERIC: && ( s1 s2 -- min-s1-s2 )
77 ! **** strict modulus of two isequences ****
79 GENERIC: %% ( s1 s2 -- ms1 ms2 )
81 ! **** strict right product of an isequence ****
83 GENERIC: _* ( m s -- m*s )
85 ! **** lazy left product of an isequence ****
87 GENERIC# *_ 1 ( s m -- s*m )
89 ! **** full product of two isequences ****
91 : ** ( s1 s2 -- ms1 ms2 ) 2dup *_ -rot _* ; inline
93 ! **** lazy left union ****
95 GENERIC: <_ ( n s -- n/s )
97 ! **** lazy right diff ****
99 GENERIC: _< ( n s -- n/s )
101 ! **** lazy union and diff of two isequences ****
103 : << ( s1 s2 -- u-s1-s2 d-s1-s2 ) 2dup <_ -rot _< ; inline
105 ! **** lazy wiped isequence ****
107 GENERIC: ## ( s -- ws )