Re: Strings and the like.
- Posted by Irv Mullins <irv at ELLIJAY.COM> Dec 11, 1999
- 527 views
On Sat, 11 Dec 1999, you wrote: > Irv Mullins wrote: > > >For the rarer case when we actually need a byte-by-byte comparison returned - > >(somebody suggest an appropriate keyword) > >a = "Bart" > >b = "Bill" > >? coincidence(a,b) > >returns: {1,0,0,0} > > > Actually, I don't see the need > for a special function. It should be quite easy for the interpreter to > "interpret" when one value or multiple values are needed. Of course you're right - the context should indicate whether to return a sequence or a boolean in most cases. I wonder about this one, however: a = "Hello" b = "World" result = (a = b) One person would want result to be {0,0,0,1,0} as it is now, while another might want result to be a true/false flag. I wonder why, if you define result as an atom or integer, the assignment can't evaluate the returned sequence {0,0,0,1,0} and cast it as false, since the interpreter _does_ do a type check, and knows that the sequence cannot be assigned to an atom? Further, consider the following: sequence a,b type boolean (object x) -- attempt to convert a sequence of 1's and 0's into a integer flag flag = 0 for i = 1 to length(x) do if x[i] != 0 then flag = 1 exit end if end for return flag end type boolean result a = "Hello" b = "World" result = (a = b) ? result Guess what - this fails, because type() can't return anything except a 1 or 0, where 1 means "it passed my check" and 0 means "it failed, so abort" If we could return a meaninful result from the type() routine, that would open up the way for us to define as many variable types as we desired, without breaking any existing code. It would also allow useful error recovery routines to be written: call a user-written error-handling routine from within the type() check, which could either allow the user to fix the problem by modifying the return data to as to be more acceptable, or to exit gracefully. Irv