Changeset 2155
- Timestamp:
- 07/01/08 09:24:04 (3 months ago)
- Files:
-
- trunk/Library/FortressLibrary.fss (modified) (7 diffs)
- trunk/Library/List.fss (modified) (8 diffs)
- trunk/Library/PureList.fss (modified) (5 diffs)
- trunk/ProjectFortress/LibraryBuiltin/FortressBuiltin.fss (modified) (3 diffs)
- trunk/ProjectFortress/demos/ArrayListLong.fss (modified) (2 diffs)
- trunk/ProjectFortress/demos/PureListLong.fss (modified) (2 diffs)
- trunk/ProjectFortress/demos/wordcount.fss (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/numerics/DirectedRounding.java (modified) (1 diff)
- trunk/ProjectFortress/tests/ArrayListQuick.fss (modified) (3 diffs)
- trunk/ProjectFortress/tests/ListTest.fss (modified) (1 diff)
- trunk/ProjectFortress/tests/PureListQuick.fss (modified) (4 diffs)
- trunk/ProjectFortress/tests/asifTest.fss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Library/FortressLibrary.fss
r2150 r2155 2887 2887 getter indices(): FullRange[\T\] = bounds() 2888 2888 2889 (** The following two methods are used in bounds checking code to 2890 permit ranges that are just outside the edge of the given 2891 range. **) 2892 widenUpper(): FullRange[\T\] 2893 widenLower(): FullRange[\T\] 2894 2889 2895 opr[r:Range[\T\]]: FullRange[\T\] = fail("Unrecognized Range " r) 2890 2896 opr[_:OpenRange[\T\]]: FullRange[\T\] = self … … 2901 2907 (* Important, also handles empty range case. *) 2902 2908 self 2903 elif r.lower() IN selfthen2909 elif r.lower() IN widenUpper() then 2904 2910 r.lower():upper() 2905 2911 else … … 2910 2916 (* Important, also handles empty range case. *) 2911 2917 self 2912 elif r.upper() IN selfthen2918 elif r.upper() IN widenLower() then 2913 2919 lower():r.upper() 2914 2920 else … … 2964 2970 getter upper():N = lower() + extent() - 1 2965 2971 getter size():ZZ32 = |self| 2972 widenUpper(): ScalarRange[\N\] = lower()#(extent()+1) 2973 widenLower(): ScalarRange[\N\] = (lower()-1)#(extent()+1) 2966 2974 opr |self| : ZZ32 = narrow(extent()) 2967 2975 opr[i:N]: N = … … 3093 3101 Tuple2Range[\N\](0,0,x1,x2).map[\((N,M),(N,M))\]( 3094 3102 fn (n:N,m:M):((N,M),(N,M)) => ((n,m),(n+l1,m+l2))) 3103 widenUpper(): Tuple2Range[\N,M\] = (l1,l2)#(x1+1,x2+1) 3104 widenLower(): Tuple2Range[\N,M\] = (l1-1,l2-1)#(x1+1,x2+1) 3095 3105 opr |self| : ZZ32 = |l1#x1| |l2#x2| 3096 3106 opr[i:(N,M)]: (N,M) = do … … 3128 3138 fn (t:(N1,N2),n3:N3):((N1,N2,N3),(N1,N2,N3)) => 3129 3139 do (n1,n2)=t; ((n1,n2,n3),(n1+l1,n2+l2,n3+l3)) end) 3140 widenUpper(): Tuple3Range[\N1,N2,N3\] = (l1,l2,l3)#(x1+1,x2+1,x3+1) 3141 widenLower(): Tuple3Range[\N1,N2,N3\] = (l1-1,l2-1,l3-1)#(x1+1,x2+1,x3+1) 3130 3142 opr |self| : (N1,N2,N3) = |l1#x1| |l2#x2| |l3#x3| 3131 3143 opr[i:(N1,N2,N3)]: (N1,N2,N3) = do … … 3210 3222 match(regex:String,some:String):Boolean = builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Match") 3211 3223 3212 (** opr // appends a single newline separator. **) 3224 (** postfix %//% appends a single newline separator. The postfix version 3225 performs implicit conversion to String, which is why it's a 3226 standalone top-level function. Infix and prefix versions are defined by String. **) 3213 3227 opr (x:Any)// : String = x||"\n" 3214 3228 3215 (** opr /// appends a double newline separator **) 3229 (** postfix %///% appends a double newline separator. The postfix version 3230 performs implicit conversion to String, which is why it's a 3231 standalone top-level function. Infix and prefix versions are defined by String. **) 3216 3232 opr (x:Any)/// : String = x||"\n\n" 3217 3233 trunk/Library/List.fss
r2106 r2155 88 88 trait SomeList excludes { Number, HasRank } 89 89 (* comprises List[\E\] where [\E\] *) 90 append(f:SomeList): SomeList = app(self,f)90 opr ||(self, f:SomeList): SomeList = app(self,f) 91 91 addLeft(e:Any): SomeList = addL(e,self) 92 92 addRight(e:Any): SomeList = addR(self,e) … … 95 95 private app[\T,E extends T,F extends T\](a:List[\E\], b:List[\F\]): List[\T\] = 96 96 typecase (a,b) of 97 (List[\T\],List[\T\]) => a .append(b)97 (List[\T\],List[\T\]) => a || b 98 98 (List[\T\],List[\F\]) => a.appendRC[\F\](b) 99 99 (List[\E\],List[\T\]) => b.appendLC[\E\](a) … … 123 123 getter extractLeft(): Maybe[\(E,List[\E\])\] 124 124 getter extractRight(): Maybe[\(List[\E\],E)\] 125 (** %append% returns a list containing the elements of %self% followed125 (** the operator %||% returns a list containing the elements of %self% followed 126 126 by the elements of %f% *) 127 append(f:List[\E\]): List[\E\] 128 (** the operator %||% performs the %append% operation *) 129 opr ||(self, other:List[\E\]): List[\E\] = append(other) 127 opr ||(self, other:List[\E\]): List[\E\] 130 128 (** Helper methods for %append% *) 131 129 private appendRC[\T\](other:List[\T\]): List[\E\] … … 183 181 covariantComprehension[\T,R\](unwrap:SomeList->R): Comprehension[\T,R,SomeList,SomeList\] = 184 182 Comprehension[\T,R,SomeList,SomeList\]( 185 fn xs => unwrap(xs .append(emptyList[\T\]())), CVConcat[\T\], cvSingleton)183 fn xs => unwrap(xs || emptyList[\T\]()), CVConcat[\T\], cvSingleton) 186 184 187 185 (** Convert generator into list; can be used to desugar list … … 232 230 getter toString():String = "List concatenation" 233 231 empty(): List[\E\] = emptyList[\E\]() 234 join(a:List[\E\], b:List[\E\]): List[\E\] = a .append(b)232 join(a:List[\E\], b:List[\E\]): List[\E\] = a || b 235 233 end 236 234 … … 239 237 getter toString():String = "Covariant list concatenation" 240 238 empty(): SomeList = emptyList[\T\]() 241 join(a:SomeList, b:SomeList): SomeList = a .append(b)239 join(a:SomeList, b:SomeList): SomeList = a || b 242 240 end 243 241 … … 246 244 getter toString():String = "List reversal concatenation" 247 245 empty(): List[\E\] = emptyList[\E\]() 248 join(a:List[\E\], b:List[\E\]): List[\E\] = b .append(a)246 join(a:List[\E\], b:List[\E\]): List[\E\] = b || a 249 247 end 250 248 … … 353 351 end 354 352 355 (** % append%. Caneither append %other% to the right of %self%353 (** %||% cab either append %other% to the right of %self% 356 354 or %self% to the left of %other%. Choose based on available 357 355 space, preferring right append and if necessary right extension. **) 358 append(other:List[\E\]): List[\E\] =356 opr ||(self, other:List[\E\]): List[\E\] = 359 357 if rightSpace() >= |other| AND: canExtendRight.tryOnce() then 360 358 appendR[\E\](other) trunk/Library/PureList.fss
r2140 r2155 47 47 trait List[\E\] extends { LexicographicOrder[\List[\E\],E\] } 48 48 excludes { Number, HasRank } 49 getter left():Maybe[\E\] = extractLeft().map[\E\](fn (v:E,_):E => v) 50 getter right():Maybe[\E\] = extractRight().map[\E\](fn (_,v:E):E => v) 51 getter extractLeft(): Maybe[\(E,List[\E\])\] 52 getter extractRight(): Maybe[\(List[\E\],E)\] 53 append(f:List[\E\]): List[\E\] 54 opr ||(self, other:List[\E\]): List[\E\] 55 addLeft(e:E):List[\E\] 56 addRight(e:E):List[\E\] 57 take(n:ZZ32): List[\E\] 58 drop(n:ZZ32): List[\E\] 59 opr [n:ZZ32]: E 60 opr [n:Range[\ZZ32\]]: List[\E\] = 61 drop(n.lower()).take(n.extent()) 62 split(n:ZZ32): (List[\E\], List[\E\]) 63 split(): (List[\E\], List[\E\]) 64 reverse(): List[\E\] = generate[\List[\E\]\](RevConcat[\E\],singleton[\E\]) 65 filter(p: E -> Boolean): List[\E\] = 66 concatMap[\E\](fn (x:ZZ32):List[\E\] => if p(x) then singleton[\E\](x) 67 else emptyList[\E\]() end) 68 toString():String = 49 (** %left% and %extractLeft% return the leftmost element in the list 50 (and in the latter case, the remainder of the list without its 51 leftmost element). They return %Nothing% if the list is empty. 52 %right% and %extractRight% do the same with the rightmost 53 element. *) 54 getter left():Maybe[\E\] = extractLeft().map[\E\](fn (v:E,_):E => v) 55 getter right():Maybe[\E\] = extractRight().map[\E\](fn (_,v:E):E => v) 56 getter extractLeft(): Maybe[\(E,List[\E\])\] 57 getter extractRight(): Maybe[\(List[\E\],E)\] 58 opr ||(self, other:List[\E\]): List[\E\] 59 (** %addLeft% and %addRight% add an element to the left or right of 60 the list, respectively *) 61 addLeft(e:E):List[\E\] 62 addRight(e:E):List[\E\] 63 (** %take% returns the leftmost %n% elements of the list; if the 64 list is shorter than this, the entire list is returned. *) 65 take(n:ZZ32): List[\E\] 66 (** %drop% drops the leftmost %n% elements of the list; if the list 67 is shorter than this, an empty list is returned. *) 68 drop(n:ZZ32): List[\E\] 69 opr [n:ZZ32]: E 70 opr [n:Range[\ZZ32\]]: List[\E\] = do 71 r = (0 # |self|)[n] 72 drop(r.lower()).take(r.extent()) 73 end 74 (** %l.split(n)% is equivalent to %(l.take(n),l.drop(n))%. Note in 75 particular that appending its results yields the original 76 list. *) 77 split(n:ZZ32): (List[\E\], List[\E\]) 78 (** %split% splits the list into two smaller lists. If %|l| > 1% 79 both lists will be non-empty. *) 80 split(): (List[\E\], List[\E\]) 81 reverse(): List[\E\] = 82 generate[\List[\E\]\](RevConcat[\E\],singleton[\E\]) 83 filter(p: E -> Boolean): List[\E\] = 84 concatMap[\E\](fn (x:E):List[\E\] => if p(x) then singleton[\E\](x) 85 else emptyList[\E\]() end) 86 toString():String = 69 87 "<|" (if (h,t) <- extractLeft() then 70 88 h (BIG ||[e<-t] ", " e) 71 89 else " " end) "|>" 72 concatMap[\G\](f: E->List[\G\]): List[\G\] = 73 generate[\List[\G\]\](Concat[\G\],f) 74 map[\G\](f: E->G): List[\G\] = 75 concatMap[\G\](fn (e:E):List[\G\] => singleton[\G\](f(e))) 76 ivmap[\G\](f: (ZZ32,E)->G): List[\G\] = 77 indexValuePairs().generate[\List[\G\]\](Concat[\G\], 78 fn (t:(ZZ32,E)):List[\G\] => singleton[\G\](f(t))) 90 (** %concatMap% is an in-place version of the %nest% method from 91 %Generator%; it flattens the result into an actual list, rather than 92 returning an abstract %Generator%. *) 93 concatMap[\G\](f: E->List[\G\]): List[\G\] = 94 generate[\List[\G\]\](Concat[\G\],f) 95 map[\G\](f: E->G): List[\G\] = 96 concatMap[\G\](fn (e:E):List[\G\] => singleton[\G\](f(e))) 97 ivmap[\G\](f: (ZZ32,E)->G): List[\G\] = 98 indexValuePairs().generate[\List[\G\]\](Concat[\G\], 99 fn (t:(ZZ32,E)):List[\G\] => singleton[\G\](f(t))) 79 100 end 80 101 … … 96 117 getter toString(): String = "List concatenation reduction" 97 118 empty(): List[\E\] = emptyList[\E\]() 98 join(a:List[\E\], b:List[\E\]): List[\E\] = a .append(b)119 join(a:List[\E\], b:List[\E\]): List[\E\] = a || b 99 120 end 100 121 … … 103 124 getter toString(): String = "List reversal reduction" 104 125 empty(): List[\E\] = emptyList[\E\]() 105 join(a:List[\E\], b:List[\E\]): List[\E\] = b .append(a)126 join(a:List[\E\], b:List[\E\]): List[\E\] = b || a 106 127 end 107 128 … … 110 131 getter toString(): String = "PureList concatenation reduction" 111 132 empty(): PureList[\E\] = D0[\E\] 112 join(a:PureList[\E\], b:PureList[\E\]): PureList[\E\] = a .append(b)133 join(a:PureList[\E\], b:PureList[\E\]): PureList[\E\] = a || b 113 134 end 114 135 … … 130 151 it.generate[\R\](r,body) 131 152 seq(self): SequentialGenerator[\E\] = SeqListGenerator[\E\](it) 132 opr ||(self, other:List[\E\]): List[\E\] = append(other) 133 append(f:List[\E\]): PureList[\E\] = 134 append(f.generate[\PureList[\E\]\](PLConcat[\E\],singleton[\E\])) 135 append(f:PureList[\E\]): PureList[\E\] = 153 opr ||(self, other:List[\E\]): List[\E\] = 154 self || f.generate[\PureList[\E\]\](PLConcat[\E\],singleton[\E\]) 155 opr ||(self, f:PureList[\E\]): PureList[\E\] = 136 156 PureList[\E\](it.append(f.contents())) 137 157 addLeft(e:E):PureList[\E\] = trunk/ProjectFortress/LibraryBuiltin/FortressBuiltin.fss
r2150 r2155 207 207 get(i:ZZ32): Char = 208 208 builtinPrimitive("com.sun.fortress.interpreter.glue.prim.String$Index") 209 (** As a convenience, we permit LowerRange indexing to go 1 past the bounds210 of the string, returning the empty string, in order to permit some convenient211 string-trimming idioms. **)212 opr[r0:LowerRange[\ZZ32\]]: String = do213 l = r0.lower()214 if l = |self| then ""215 else self[l#(|self| - l)]216 end217 end218 209 opr[r0:Range[\ZZ32\]] : String = do 219 210 r1 = (bounds())[r0] … … 259 250 opr juxtaposition(self, b:Any):String = self || b 260 251 261 (** opr // appends with a single newline separator. **) 252 (** opr %//% appends with a single newline separator. Note that as 253 with %||% and %|||% at least one argument must be a String. 254 There is a postfix version in FortressLibrary that performs 255 string conversion, but the prefix version must occur before a 256 String. **) 262 257 opr //(self) : String = "\n"||self 263 258 opr //(self, a:String): String = self||"\n"||a … … 265 260 opr //(a:Any, self): String = a||"\n"||self 266 261 267 (** opr /// appends with a double newline separator **) 262 (** opr %///% appends with a double newline separator. Note that as 263 with %||% and %|||% at least one argument must be a String. 264 There is a postfix version in FortressLibrary that performs 265 string conversion, but the prefix version must occur before a 266 String. **) 268 267 opr ///(self) : String = "\n\n"||self 269 268 opr ///(self, a:String): String = self||"\n\n"||a trunk/ProjectFortress/demos/ArrayListLong.fss
r1778 r2155 79 79 chkExtract(li,i) 80 80 (ll,lr) = li.split() 81 lii = ll .append(lr)81 lii = ll || lr 82 82 chkPop(lii,i) 83 83 fli = li.filter(fn x => x REM 2 = 0) … … 114 114 print(".") 115 115 lj = list(i#j) 116 chkPop(li .append(lj),i+j)116 chkPop(li || lj, i+j) 117 117 gz = li.zip[\ZZ32\](lj) 118 118 assert(|gz|,|li| MIN |lj|, "zip size wrong") trunk/ProjectFortress/demos/PureListLong.fss
r1775 r2155 79 79 chkExtract(li,i) 80 80 (ll,lr) = li.split() 81 lii = ll .append(lr)81 lii = ll || lr 82 82 chkPop(lii,i) 83 83 fli = li.filter(fn x => x REM 2 = 0) … … 114 114 print(".") 115 115 lj = list(i#j) 116 chkPop(li .append(lj),i+j)116 chkPop(li || lj, i+j) 117 117 gz = li.zip[\ZZ32\](lj) 118 118 assert(|gz|,|li| MIN |lj|, "zip size wrong") trunk/ProjectFortress/demos/wordcount.fss
r1825 r2155 77 77 78 78 opr UNIONUNION(a:Map[\ZZ32,List[\String\]\], b:Map[\ZZ32, List[\String\]\]):Map[\ZZ32,List[\String\]\] = 79 a.union(fn(k,x,y) => x.append(y),b)79 a.union(fn(k,x,y) => x || y, b) 80 80 81 81 opr BIG UNIONUNION(): BigReduction[\Map[\ZZ32, List[\String\]\],Map[\ZZ32, List[\String\]\]\] = trunk/ProjectFortress/src/com/sun/fortress/numerics/DirectedRounding.java
r1566 r2155 26 26 * in pure Java. 27 27 */ 28 public class DirectedRounding { 28 public final class DirectedRounding { 29 30 private DirectedRounding() {} 29 31 30 32 public static float nextUp(float x) { trunk/ProjectFortress/tests/ArrayListQuick.fss
r1775 r2155 99 99 (ll,lr) = li.split() 100 100 print(".") 101 lii = ll .append(lr)101 lii = ll || lr 102 102 chkPop(lii,i) 103 103 print(".") … … 145 145 chkPop(l2,j) 146 146 chkPop(r2,j,i-j) 147 (l3,r3) = (li[#j],li[j#]) 148 chkPop(l3,j) 149 chkPop(r3,j,i-j) 150 (l4,r4) = (li[:(j-1)],li[j:]) 151 chkPop(l4,j) 152 chkPop(r4,j,i-j) 147 153 end 148 154 for j <- testLens do 149 155 print(".") 150 156 lj = list(i#j) 151 chkPop(li .append(lj),i+j)157 chkPop(li || lj, i+j) 152 158 print(".") 153 159 gz = li.zip[\ZZ32\](lj) … … 159 165 end 160 166 testStr : List[\String\] = <| "Hello" asif String |> 161 testU : List[\Any\] = testStr .append(testLens)167 testU : List[\Any\] = testStr || testLens 162 168 chkApp(testLens,testU) 163 chkApp(testLens, testU.append(testStr).drop(1))164 chkApp(testLens, testStr.append(testU).drop(1))169 chkApp(testLens,(testU || testStr).drop(1)) 170 chkApp(testLens,(testStr || testU).drop(1)) 165 171 chkApp(testLens,testLens.addLeft("Hello")) 166 172 chkApp(testLens,testLens.addRight("Hello")) trunk/ProjectFortress/tests/ListTest.fss
r1481 r2155 31 31 assert(list'.drop(1),<|5 asif ZZ32,7|>," list'.drop(1)") 32 32 assert((list'.drop(1))[1], 7," list'.drop(1)[1]") 33 l = list' .append(list'')33 l = list' || list'' 34 34 assert(3 IN list'', false, "3 IN ", list'') 35 35 assert(BIG AND [e <- list''] e IN l, true, trunk/ProjectFortress/tests/PureListQuick.fss
r1775 r2155 33 33 if NOT a then 34 34 fail("Failed assertion: " s l.toString() " and " r.toString()) 35 end 36 37 chkApp(tl: List[\ZZ32\], t : List[\Any\]) = do 38 assert("Hello" IN t, true, "missing Hello from ", t) 39 assert(l IN t, true, "missing ",l," from ",t), l <- tl 35 40 end 36 41 … … 81 86 assert(20,SUM testLens,"sum wrong") 82 87 for i <- seq(testLens) do 83 print( // i ":")88 print( // i ":") 84 89 li = list(0#i) 85 90 print(li) … … 89 94 assert(li,li,"Lists unequal") 90 95 assert(li CMP li,EqualTo,"Lists CMP unequal") 96 chkPop(li[#],i) 97 chkPop(li.addRight(i),i+1) 98 chkPop(li.addLeft(-1),-1,i+1) 91 99 (ll,lr) = li.split() 92 100 print(".") 93 lii = ll .append(lr)101 lii = ll || lr 94 102 chkPop(lii,i) 95 103 print(".") … … 137 145 chkPop(l2,j) 138 146 chkPop(r2,j,i-j) 147 (l3,r3) = (li[#j],li[j#]) 148 chkPop(l3,j) 149 chkPop(r3,j,i-j) 150 (l4,r4) = (li[:(j-1)],li[j:]) 151 chkPop(l4,j) 152 chkPop(r4,j,i-j) 139 153 end 140 154 for j <- testLens do 141 155 print(".") 142 156 lj = list(i#j) 143 chkPop(li .append(lj),i+j)157 chkPop(li || lj, i+j) 144 158 print(".") 145 159 gz = li.zip[\ZZ32\](lj) trunk/ProjectFortress/tests/asifTest.fss
r1597 r2155 62 62 y : List[\Foo\] = <| Baz asif Foo, Baz |> 63 63 (* Now appending the two ought to work. *) 64 println(x .append(y))64 println(x || y) 65 65 66 66 (* Top-level overloading *)
