Re: Strings and the like.
- Posted by Everett Williams <rett at GVTC.COM> Dec 08, 1999
- 521 views
My apologies, but somehow, I sent this previously incomplete. This is the full text. Lucius L. Hilley III wrote: > What if something like these were built-in? > >----------------------------------- >type whole_number_set(sequence s) > for A = 1 to length(s) do > if (s[A] = floor(s[A])) then > return 0 > end if > end for > > return 1 >end type >----------------------------------- I think that you have a small error in these routines, and I would not see the difference between your's and this: type whole_number_set(sequence s) sequence temp1 temp1 = (s = floor(s)) return (find(0, temp) = 0) end type ----------------------------------- > >Then you would be able to specify any range and test it >effeciently such as a byte_set() below. Of course, these >sets are enforcing that you have a one dimensional sequence. >But that is the whole point of detecting strings. > >----------------------------------- and this type byte_set(sequence s) -- I.E.: standard ASCII byte STRING !!! sequence temp if whole_number_set(s) then temp = ((s >= 0) and (255 > s)) return (find(0, temp) = 0) end if end type Are you deliberately leaving xFF out of the set? Anyway, I think I recognize a palliative gesture here. You have described a very specific, very non-embedded Euphoria typing routine here. It appears that the only way to type check by these techniques is to check the entire sequence each time that any operation is made on the sequence... OUCH!!...can anybody spell overhead. The only way to prevent this would be to assign the substring to be affected to another type-checked variable before the operation and then assign it back. Not only would this be clumsy, in some cases it might be tricky and from what I can tell, it would trigger the type check anyway on the whole string. Depending on how often the test is triggered for operations that affect the whole or some slice of the string, this could get ugly. OUCH!!...I, as an Euphoria newby, just stomped on a really ugly artifact of Euphoria and sequences. I see how relational and logical operators produce multiple results, true values rather than logical values. A logical value is a temporary item that only exists at the point of comparison unless deliberately and separately preserved. Unless the comparands are also preserved, any such logical "value" loses its relevance as soon as those comparands lose their validity. For validity, where a single logical result is expected, Euphoria should sequentially "and" together the truth values for this purpose. This should be valid, for example: type whole_number_set(sequence s) return (s = floor(s)) end type And in any other case where a single value would be necessary for consistency. Another example would be: sequence s s = "ABCD" if s = floor(s) then .... end if This is a major logical hole in the language. There needs to be a clear distinguishing between relational and logical symbols as functional operators returning a value or values and those same operators as standard truth tests in our standard binary logic system. Neither mode needs to be excluded. Overloading is not a problem here...I don't think. Maybe somebody can come up with a counter to that thought. Everett L.(Rett) Williams rett at gvtc.com