1. Re: type string
global constant
TRUE = 1,
FALSE = 0
global type string (object x)
sequence s
if sequence (x) then
s = x
for index = 1 to length(s) do
x = s[index]
if sequence (x) or compare (and_bits (x, 255),x) then
return FALSE
end if
end for
return TRUE
else
return FALSE
end if
end type
Arguments that apply:
-- If its any odd value, not even close to a string, the most apparent
difference would be in its structure (and thus
types), therefor I check the type first, and then if the values are legal.
-- I use only one if-statement (in the main loop) that will short-circuit,
no need for an else-jump or not-operator
-- Atoms and_bits () are automatically floored and thus differ from the
original value, therefor the second condition of the
if-statement catches floating point values as well
-- We jump out as soon as any part of the structure is wrong. (in
test-cases)
-- We can be certain the and_bits () function is only applied to atoms.
This is a modified versions of Christopher's.
I haven't timed it, but for those we want to time it, I want to agree upon the
scalability of lengths and values put into the
function.
-- 1/2 Dummy Cases: (is it a string, or something else ?)
-- 1/2 Random different structure-sequence of random length
-- 1/4 Atom values.
-- 1/4 Sequence contain out-of-scope integer values (out-of-scope -->
lower than 0 or higher than 255)
-- 1/4 Legal Cases: (type check calls: legal-end-program)
-- 1/3 strings random length less than 16
-- 1/3 strings, in between 16 and 80
-- 1/3 strings, longer than 80
-- 1/4 Bad Cases: (type check calls: illegal-debugging)
-- 1/2 Sequence found inside character string, at random position, once
-- 1/4 Unfloored operation (floating point value), random position, once
-- 1/4 Subscript error: -1 or 256 as value, random position, once
The divisions above represent how many of the tries should be of which type, to
compare to.
Once a random set of calls is setup, we use that same set, for *each* string
routine.
Also, make *SURE* there's a lot of garbage in-between the time we are not
measuring, so the cache is cleaned out.
With garbage I mean: dummy code, using dummy long variables.
This way, the routines that use less code will have an unfair advantage in a
small test program. Such advantage does not apply
to huge programs, the programs where the speed really matters.
Ralf N.
nieuwen at xs4all.nl
ralf_n at email.com