Show
Ignore:
Timestamp:
08/25/08 07:23:17 (15 months ago)
Author:
black
Message:

Next iteration of CordedStrings?, with substring nodes. Comparison of Strings with substring nodes is a work in progress. This commit fixes bugs in the Range comparison code that were impeding that progress

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/Library/FortressLibrary.fss

    r2715 r2739  
    135135    isLeftZero(_:Comparison): Boolean = true 
    136136end 
     137 
     138opr BIG LEXICO(): BigReduction[\TotalComparison, TotalComparison\] = 
     139  BigReduction[\TotalComparison,TotalComparison\](LexicographicReduction) 
     140   
    137141 
    138142trait Comparison 
     
    11001104trait Condition[\E\] extends { ZeroIndexed[\E\], SequentialGenerator[\E\] } 
    11011105    getter isEmpty(): Boolean = NOT holds() 
     1106    getter nonEmpty(): Boolean = NOT isEmpty() 
    11021107    getter holds(): Boolean = cond[\Boolean\](fn (_:E):Boolean => true, fn () => false) 
    11031108    getter size(): ZZ32 = if holds() then 1 else 0 end 
     
    14531458        defined as size=0 *) 
    14541459    getter isEmpty(): Boolean = |self| = 0 
    1455     (** %size()% is depracated; use %|self|%. *) 
     1460    getter nonEmpty(): Boolean = NOT self.isEmpty 
     1461    (** %self.size% is equivalent to %|self|%. *) 
    14561462    getter size(): ZZ32 
    14571463    (** bounds() yields a range of indices that are valid for the 
     
    30273033                RangeWithExtent[\T\], PartialRange[\T\] } 
    30283034    excludes { Number } 
    3029     getter isEmpty(): Boolean = (|self| ≤ 0) 
     3035     
    30303036    opr[r:Range[\T\]]: Range[\T\] = fail("Unrecognized Range " r) 
    30313037    opr[_:OpenRange[\Any\]] : Range[\T\] = self 
     
    32843290            self.lower#r.extent 
    32853291        else 
    3286             fail(self "[" r "] is not sufficiently large in some dimension") 
     3292            fail(self "[" r "] is too small in some dimension") 
    32873293        end 
    32883294    opr[r:CompleteRange[\T\]]: CompleteRange[\T\] = 
     
    33033309 
    33043310    opr =(self, other:CompleteRange[\T\]): Boolean = 
    3305         self.isBounded=other.isBounded AND self.lower=other.lower AND 
    3306         self.extent = other.extent 
     3311    (*    isBounded()=other.isBounded() AND  
     3312         APB 2008.08.20: this seems bogus: isBounded tells us only whether we were created  
     3313         using an extent or an upper bound, and should not effect the comparison *) 
     3314         lower()=other.lower() AND extent() = other.extent()     
     3315          
    33073316    opr CMP(self, other:Range[\T\]): Comparison = 
    33083317        typecase other of 
     
    33153324                    (LessThan,LessThan) => Unordered 
    33163325                    (GreaterThan,GreaterThan) => Unordered 
    3317                     (EqualTo,EqualTo) => 
     3326    (*  This case seems unncessary; the (EqualTo,Comparison) case will cover us    --- APB  2008.08.20 
     3327                    (EqualTo,EqualTo) => EqualTo 
    33183328                        if self.isBounded = other.isBounded then 
    33193329                            EqualTo 
     
    33213331                            Unordered 
    33223332                        end 
     3333   *) 
    33233334                    (EqualTo,Comparison) => b 
    33243335                    (GreaterThan,Comparison) => LessThan 
     
    36763687      
    36773688    opr |self| : ZZ32 = self.size 
    3678     opr CASE_INSENSITIVE_CMP(self, other:String): TotalComparison 
    3679     (** As a convenience, we permit LowerRange indexing to go 1 past the bounds 
     3689        
     3690    opr CASE_INSENSITIVE_CMP(self, other:String): TotalComparison = 
     3691      ((BIG LEXICO[i <- 0#(|self| MIN |other|) ] self.get(i) CASE_INSENSITIVE_CMP other.get(i)) LEXICO (|self| CMP |other|)) 
     3692     
     3693    opr CMP(self, other:String): TotalComparison = 
     3694      ((BIG LEXICO[i <- 0#(|self| MIN |other|) ] self.get(i) CMP other.get(i)) LEXICO (|self| CMP |other|)) 
     3695       
     3696    opr [i:ZZ32]: Char = 
     3697        (** As a convenience, we permit LowerRange indexing to go 1 past the bounds 
    36803698        of the String, returning the empty String, in order to permit some convenient 
    36813699        String-trimming idioms. **) 
    3682     opr [i:ZZ32]: Char = 
    36833700        if 0 <= i < |self| 
    36843701        then self.get(i) 
     
    37733790 
    37743791 
    3775 print(a:Any):() = print("" a) 
    3776 println(a:Any):() = println("" a) 
     3792print(a:Any):() = print(a.toString) 
     3793println(a:Any):() = println(a.toString) 
    37773794(* 0-argument versions handle passing of () to single-argument versions. *) 
    37783795print():() = print("") 
     
    37823799println(a: JavaString): () =  
    37833800        builtinPrimitive("com.sun.fortress.interpreter.glue.prim.StringPrim$Println") 
    3784  
    37853801 
    37863802forDigit(x:ZZ32, radix:ZZ32): Maybe[\Char\] =