RE: Sequence depths please explain

new topic     » topic index » view thread      » older message » newer message

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

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu