Re: if statement not working
- Posted by Kat <gertie at PELL.NET> Mar 22, 2002
- 509 views
On 22 Mar 2002, at 9:47, kbochert at ix.netcom.com wrote: > > Hi David Cuny, you wrote on 3/22/02 7:04:39 AM: > > >To reiterate: > > > >0. The goal is to write safe string handling code. > >1. Slices (by themselves) are unsafe when working with strings. Before someone nails down "type string", lets make all sequence handling safe, regardless of what's stored in it. > >2. Guarded slices are unsafe because the guard isn't coupled to the string. > >3. > >Euphoria doesn't provide any built-in routines for creating substrings. Unless you parse() the string (err, sequence) and such. Really, i mix what i think most people call "string" with nested sequences. I'd hate to see restrictions put on what can or cannot be a "string", Eu's strength is the sequence. For instance, if you nail down a string to be atoms of 1-255, you can't handle most of the world's language characters gracefully (old thread from yrs ago). This would hurt translation dictionaries for one, and could artificially restrict the countries that use Eu, as well as the knowledge domains that use it (like all those calculus and trig symbols). > How about a new operator '=~' First thought: ~ like "fuzzy logic"? Hmmm, better write that as a real optional include at this point, Rob will never sign onto it. > that acts like '=' except that it > plows on ahead in the face of errors: > s =~ t[2..4] > -- s is padded to length 3 if necessary Since you specified [2..3], why pad s some more? And with what? Better to look at what t actually has, and deliver what is in the envelope of [2..3] and no more. If [2..3] doesn't exist, then return {}. If you asked to borrow a book that i don't have, i won't pad out a empty box of non-existant book with some random selection of book parts. > if s[2..4] =~ '123' then > -- comparison fails if s is too short > -- (or uninitialized!) In this case, if s is too short, it's not equal. You did a test there, not an extraction or assignment, it obviously fails, but shouldn't bomb the whole program. In mirc, if i do: if ( $gettok(%address,2,$asc(.)) == ipt ) { whatever } and %address has nothing in it this time, because of whatever, i expect this boolean test to fail, not the entire program. In Eu, i expect the whole program to crash horribly. > I suppose the postfix '~' could also be applied elsewhere: > s = t[2..8]~ --s has 6 elements even if t has 4 > But I haven't thought too much about that. Nononononono! In this case, if t has 6 elements, Eu should grab the [2..6] of them for s, making s have 5 elements. Basically, if Eu would crash on it because of a length, either preemptively handle it, or grab the error Eu throws now, and deal with it intelligently. Don't add anything to it, because whatever you add might be tested for later on and cause an error. Kat