From: Charles Hixson Date: 2000-07-20T08:34:38-07:00 Subject: [ruby-talk:04146] Re: String range inconsistence This is a multi-part message in MIME format. --------------11B62B0B28DB59A7D7293439 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sergey Abel wrote: > Hi, > > "z".succ == "aa", but "z" > "aa". > As a consequence, ("z".."aa").size == 0 instead of 2. > (Same with upto method, for that matter.) > > The reason is clear: it's "unnatural" succ definition. > (BTW, "\000".succ == "\001\001". Wow.) > > IMHO, this has been conceived as the method for "plain letters", > not for arbitrary strings. If so, isn't this a subject to discuss? > > Does the language need a special subclass (encoding-dependent?) > for such strings and/or methods? > How to cope with punctuation, e.g. should we expect "a:".succ == "b:"? > > Sergey Abel The problem is, there is a range of plausible interpretations, each valid in it's particular domain. E.g. (my apologies for not having mastered the syntax yet): "a:".succ == "b:" "a:".succ == "a"+":".succ "alpha".succ="beta" etc. Perhaps the thing to do is to define some basic class, and to allow the various interpretations to be the result of sub-classing. That would, however, make it more difficult to present the constant values in the code. Perhaps: LetS.val("a:").succ == LstS.val("b:") StrS.val("a:").succ == StrS.val("a")+StrS.val(":").succ GrkA.val("alpha").succ == GrkA.val("beta") but that certainly looses a lot of the simplicity. Perhaps a "block cast" for operators could be devised, along the lines of: with (\", \+) from LetS do val = "a:".succ ## Assert that val == "b:" end This would mean that within the block encompassed by the do, end the operators " and + would be understood to have the meaning assigned to them by the class LetS. Probably not worthwhile, as it can already be accomplished by the creation of temporaries (which I noted above as, e.g., LetS.val("a:"). But it might have other applications. I just can't think what they would be. -- (c) Charles Hixson -- All commercial rights reserved -- Addition of advertisements or hyperlinks to products specifically prohibited --------------11B62B0B28DB59A7D7293439 Content-Type: text/x-vcard; charset=us-ascii; name="charleshixsn.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for Charles Hixson Content-Disposition: attachment; filename="charleshixsn.vcf" begin:vcard n:Hixson;Charles x-mozilla-html:FALSE adr:;;;;;; version:2.1 email;internet:charleshixson@earthling.net fn:Charles Hixson end:vcard --------------11B62B0B28DB59A7D7293439--