[Grace-core] String methods

Kim Bruce kim at cs.pomona.edu
Thu Aug 14 14:56:54 PDT 2014


That would be great, thanks!  As you say, I don't care how they get in there.

Kim



On Aug 14, 2014, at 2:37 PM, Andrew P. Black <andrew.p.black at gmail.com> wrote:

> I’ll put them in the String object.  It will probably be easier to re-write them using the Javascript primitives than to do the plumbing necessary to call Gracecode.  I assume that you don’t care.
> 
> 	Andrew
> 
> On 14 Aug 2014, at 13:18, Kim Bruce <kim at cs.pomona.edu> wrote:
> 
>> I just finished the first pass through the strings chapter of Programming with Grace.  Not surprisingly, there were a number of String
>> methods that I needed which are not currently implemented in the compiler as String methods.  I wrote them all as methods of a module "extraStringMethods" that is sitting in ProgrammingWithGrace/ch15-strings in the svn repository.  Here is a listing of those I wrote:
>> 
>>   // return first occurrence of pattern in source that occurs at or after position i
>>   indexOf(pattern: String) in (source: String) starting (i:Number) -> Number {
>> 
>>   // return first occurrence of pattern in source
>>   indexOf(pattern: String) in (source: String) -> Number {
>> 
>>   // return string like theString, but with all lower case letters replaced by the
>>   // corresponding upper case letters
>>   toUpper(theString: String) -> String {
>> 
>>   // return string like theString, but with all upper case letters replaced by the
>>   // corresponding lower case letters
>>   toLower(theString: String) -> String {
>> 
>>   // return true if s1 occurs before s2 in lexicographic order or if they are equal
>>   lessThanEqual(s1:String, s2: String) -> Boolean {
>> 
>>   // return true if s1 occurs before s2 in lexicographic order
>>   lessThan(s1:String, s2: String) -> Boolean {
>> 
>>   // return true if s1 occurs after s2 in lexicographic order
>>   greaterThan(s1:String,s2:String) -> Boolean {
>> 
>>   // return true if s1 occurs after s2 in lexicographic order or if they are equal
>>   greaterThanEqual(s1:String, s2: String) -> Boolean {
>> 
>>   // return string obtained from sourse by throwing away spaces at the beginning
>>   //  and end of a string.  If it is all spaces, return an empty string
>>   trim(source: String) -> String 
>> 
>> They are all fairly standard methods usually found as methods of String.  While they are stand-alone, the code in extraStringMethods.grace can be easily rewritten if someone were to add these methods to the String type.  The book currently assumes they are in that library module, but I'd be happy to see them added to the compiler (though the priority of this is behind the other features I currently can't do: images, gui components, etc.)
>> 
>> Kim
>> 
>> 
>> 
>> 
>> _______________________________________________
>> Grace-core mailing list
>> Grace-core at cecs.pdx.edu
>> https://mailhost.cecs.pdx.edu/mailman/listinfo/grace-core
> 




More information about the Grace-core mailing list