1. Re: type string
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Mar 18, 1999
- 355 views
On Wed, 17 Mar 1999, Chris Hickman wrote: ] global type string13(object x) ] ] if atom(x) then ] return 0 ] end if ] ] -- ensure all elements are in the range 0 to 255 ] if compare(x, and_bits(255, x)) then ] return 0 ] end if ] ] -- ensure there's no sub-sequences ] for i = 1 to length(x) do ] if not integer(x[i]) then ] return 0 ] end if ] end for ] return 1 ] end type Nice to see someone taking a leaf out of my book here, but like I say, using my smallest-code options, you tend to lose out in the long run on speed. :) How 'bout: global type string14(object x) if atom(x) then return 0 end if -- conditions in loop listed in order of likelyhood most..least for i = 1 to length(x) do if sequence(x[i]) then return 0 end if -- The line below catches bad atoms, so 'not atom' is changed -- to 'sequence' in the line above... if x != and_bits(x, 255) then return 0 end if end for return 1 end type Unbenchmarked, but I reckon it's fairly quick. Incidentally, I've found myself using the all-on-one-line-if for types. Usually only one condition can be checked at a time if we want speed and/or no-error evaluation. if message_end then puts(mailer, Name & SIG) end if Carl -- Carl R White -- cyrek- at -bigfoot.com -- http://www.bigfoot.com/~cyrek aka Cyrek -- No hyphens :) -- Bigfoot URL Alias