1. RE: Sequence depths please explain
Tony,
The way to test ANY object, whether a number, sequence, or
something unknown, to see what data type it is, is to use
the data type as a function.
For example:
integer i
object temp
ColorType ball_color
i = 543
ball_color = RED
...
temp = UNKNOWN_DATA
Above, you've declared 'temp' to be an object, so anything
can be put into it. How do you know if what's in it is an
atom, a sequence, a ColorType (if you've defined that), etc.?
Again, use the data type as a function:
if atom (temp) then
if sequence (temp) then
if ColorType (temp) then
If the value stored in 'temp' is of the same data type that
you're testing, then the function call will return a 1 (TRUE),
otherwise a 0 (FALSE).
So if UNKNOWN_DATA was 25, the first 'if' (atom (temp)) would
be true, the second would be false, and the third would depend
on how you defined the ColorType data type.
If you have a variable known to hold a sequence, then the way
to test each element in that sequence is to use subscripts:
temp = {{1,2,3}, 555, "Hello!", {}, 23.999}
if sequence (temp[1]) then --> is TRUE since {1,2,3} is first
if sequence (temp[2]) then --> is FALSE since 555 is 2nd
if sequence (temp[3]) then --> is TRUE since strings are sequences
if sequence (temp[4]) then --> is TRUE since empty sequences count
if sequence (temp[5]) then --> is FALSE since 23.999 is 5th
Keep in mind, each element of a string (a sequence in disguise)
will be an integer. "TONY" is really {84,79,78,89}, so
temp = "TONY"
if sequence (temp[1]) then --> FALSE since temp[1] is 'T', or 84
Rod
Tony Steward wrote:
> Hi all,
> How can I tell if a sequence is a single sequence of if it contains more
>
> sequences.
>
> eg
> test = {Tony Steward} -- Single sequence
> test = {{Tony Steward}{lockmaster67 at aol.com}{22432345}} -- Multi
>
> Thanks Tony
2. RE: Sequence depths please explain
- Posted by Henri.Goffin at sbs.be
Mar 29, 2002
Maybe i'm a tiny bit off topic but this may be inspiring. Take a look a this
(recursive) function:
--------------------------------------------------
global function skeleton(object o)
-- if the input is a sequence, the output is a printable representation of the
"skeleton" of the sequence
-- where the atoms are represented by dots (or whatever you like). ex:
{1,2,{3},"four",{5,6}} --> "{..{.}{....}{..}}"
sequence skel
object skeli
if atom(o) then return o end if
skel = ""
for i = 1 to length(o) do
skeli = skeleton(o[i])
if atom(skeli) then
skel &= '.' --<--change here if you prefer stars or dashes or...
else
skel &= skeli
end if
end for
return '{' & skel & '}'
end function
Henri Goffin