]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/isequences/interface/interface.factor
Initial import
[factor.git] / unmaintained / isequences / interface / interface.factor
1 ! Copyright (C) 2007 Robbert van Dalen.
2 ! See http://factorcode.org/license.txt for BSD license.
3
4 IN: isequences.interface
5 USING: generic kernel ;  
6
7 ! Unifies sequences, integers and objects, following Enchilada semantics.
8 ! Efficiency is achieved through lazy immutable size-balanced binary trees. 
9
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
14
15
16 GENERIC: -- ( s -- -s )                         ! monadic negate
17 GENERIC: $$ ( s1 -- h )                         ! monadic hash
18 GENERIC: ++ ( s1 s2 -- s )                      ! dyadic concatenate  
19
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
23
24 GENERIC# ihead 1 ( s n -- s )                           ! dyadic head of a cut
25 GENERIC# itail 1 ( s n -- s )                           ! dyadic tail of a cut
26
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
30
31 GENERIC: ascending? ( s -- ? )                  ! monadic ascending query
32 GENERIC: descending? ( s -- ? )                 ! monadic descending query    
33
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 )
39
40
41 ! **** lazy turn of an isequence 
42 !
43 GENERIC: :: ( s -- ts )
44
45 ! **** lazy reversal of an isequence
46 !
47 GENERIC: `` ( s -- rs )
48
49 ! **** lazy right division of an isequence
50 !
51 GENERIC: _/ ( n s -- n/s )
52
53 ! **** lazy left division of an isequence ****
54 !
55 GENERIC: /_ ( s1 n -- s1/n )
56
57 ! **** full division of two isequences ****
58 !
59 : // ( s1 s2 -- n1/s2 s1/n2 ) 2dup /_ -rot _/ ; inline
60
61 ! **** matching two isequences ****
62 !
63 GENERIC: >> ( s1 s2 -- s1/s2 )
64
65 ! **** iota ****
66 !
67 GENERIC: ~~ ( s -- s )
68
69 ! **** lazy maximum of two isequences
70 !
71 GENERIC: || ( s1 s2 -- max-s1-s2 )
72
73 ! **** lazy minimum of two isequences ****
74 !
75 GENERIC: && ( s1 s2 -- min-s1-s2 )
76
77 ! **** strict modulus of two isequences ****
78 !
79 GENERIC: %% ( s1 s2 -- ms1 ms2 )
80
81 ! **** strict right product of an isequence ****
82 !
83 GENERIC: _* ( m s -- m*s )
84
85 ! **** lazy left product of an isequence ****
86 !
87 GENERIC# *_ 1 ( s m -- s*m )
88
89 ! **** full product of two isequences ****
90 !
91 : ** ( s1 s2 -- ms1 ms2 ) 2dup *_ -rot _* ; inline
92
93 ! **** lazy left union ****
94 !
95 GENERIC: <_ ( n s -- n/s )
96
97 ! **** lazy right diff ****
98 !
99 GENERIC: _< ( n s -- n/s )
100
101 ! **** lazy union and diff of two isequences ****
102 !
103 : << ( s1 s2 -- u-s1-s2 d-s1-s2 ) 2dup <_ -rot _< ; inline
104
105 ! **** lazy wiped isequence ****
106 !
107 GENERIC: ## ( s -- ws )
108
109
110