1. Sequence depths please explain
- Posted by Tony Steward <tony at locksdownunder.com> Mar 28, 2002
- 414 views
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 euman at bellsouth.net Mar 28, 2002
- 382 views
----- Original Message ----- From: "Tony Steward" <tony at locksdownunder.com> To: "EUforum" <EUforum at topica.com> > 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 There might be a better way but this seems to work ok. sequence test1, test2 test1 = "Tony Steward" -- Single sequence test2 = {"Tony Steward","lockmaster67 at aol.com",{22432345}} if sequence(test1[1]) then puts(1, "test1 is > 1") end if if sequence(test2[1]) then puts(1, "test2 is > 1") end if if getc(0) then end if Euman euman at bellsouth.net
3. Re: Sequence depths please explain
- Posted by Kat <gertie at PELL.NET> Mar 28, 2002
- 421 views
On 25 Feb 2002, at 9:56, 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 Loop thru and test each one to see if it's a sequence. Is sequence(test[1]) (if it is, then is sequence(test[1][1]), sequence(test[1][2]) etc), and sequence(test[2]) (if it is, then is sequence(test[2][1]), sequence(test[2][2]) etc), etc. Kat
4. Re: Sequence depths please explain
- Posted by Derek Parnell <ddparnell at bigpond.com> Mar 28, 2002
- 396 views
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 > Hi Tony, try this function: function subseq(sequence s) for i = 1 to length(s) do if sequence(s[i]) then return 1 end if end for return 0 end function test = "Tony Steward" if subseq(test) then puts(1, "Contains subsequences") else puts(1, "Has no subsequences") end if test = {"Tony Steward","lockmaster67 aol.com","22432345"} if subseq(test) then puts(1, "Contains subsequences") else puts(1, "Has no subsequences") end if ----- In essence, the only way to tell if a sequence has subsequences is to test every element. --------- Derek.
5. Re: Sequence depths please explain
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Mar 28, 2002
- 417 views
Tony, It might also be useful/necessary to know if you have an empty sequence, and while just doing a length() test where you need it is probably better, here is the length test as a function (and also shows why you probably need to re-define your sequences ) : -- code begins: sequence test1, test2, test3, test4, test5 integer result test1 = {"Tony Steward"} -- main sequence has only one sequence test2 = {"Tony Steward","lockmaster 67 at aol.com<mailto:lockmaster67 at aol.com>",22432345} -- main sequence has more than one sequence test3 = {} test4 = {1} --test5 = {Tony Steward} -- gives ERROR: "Tony has not been declared" :) function WhatIsLengthOfSequence (sequence aSequence) integer L L= length(aSequence) if L = 1 then puts(1, "sequence is single\n") elsif L > 1 then puts(1, "sequence is multiple\n") else puts(1, "sequence is empty\n") end if return L end function -- tests: result = WhatIsLengthOfSequence(test1) result = WhatIsLengthOfSequence(test2) result = WhatIsLengthOfSequence(test3) result = WhatIsLengthOfSequence(test4) --result = WhatIsLengthOfSequence(test5) -- code ends Dan Moyer ----- Original Message ----- From: "Tony Steward" <tony at locksdownunder.com> To: "EUforum" <EUforum at topica.com> Sent: Monday, February 25, 2002 1:56 AM Subject: Sequence depths please explain > > 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 >
6. Re: Sequence depths please explain
- Posted by petelomax at blueyonder.co.uk Mar 28, 2002
- 402 views
try this: type nested(sequence x) for i = 1 to length(x) do if sequence(x[i]) then return 1 end if end for return 0 end type or swap return 0 & 1 and call it simple() I recommend making it a type solely because it traps better when you know something should be simple, not nested, or vice versa. You can still just say, on any object,: if nested(thingy) then or if simple(thingy) then Pete
7. Re: Sequence depths please explain
- Posted by rforno at tutopia.com Mar 28, 2002
- 409 views
You can use this function, which is part of my General Functions package: global function MaxDepth(object o) --Returns the maximum depth of object o. --Atoms have depth 0. integer n, x if atom(o) then return 0 else n = 1 for i = 1 to length(o) do x = 1 + MaxDepth(o[i]) if x > n then n = x end if end for return n end if end function A string returns 1. An atom returns 0. A composite sequence returns 2 or more. ----- Original Message ----- From: "Tony Steward" <tony at locksdownunder.com> To: "EUforum" <EUforum at topica.com> Sent: Monday, February 25, 2002 6:56 AM Subject: Sequence depths please explain > > 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 > > > >
8. Re: Sequence depths please explain
- Posted by Dan Moyer <DANIELMOYER at prodigy.net> Mar 28, 2002
- 426 views
Tony, If you re-define your sequences as I think you must, like so: test1 = {"Tony Steward"} -- main sequence contains only one sequence test2 = {"Tony Steward","lockmaster 67 at aol.com<mailto:lockmaster67 at aol.com>",22432345} -- main sequence contains more than one sequence then all you have to do is use "length()" to test them: sequence test1, test2 integer L test1 = {"Tony Steward"} -- main sequence has only one element test2 = {"Tony Steward","lockmaster 67 at aol.com<mailto:lockmaster67 at aol.com>",22432345} -- main sequence has more than one element -- tests: L = length(test1) if L = 1 then puts(1, "sequence is single\n") elsif L > 1 then puts(1, "sequence is multiple\n") end if L = length(test2) if L = 1 then puts(1, "sequence is single\n") elsif L > 1 then puts(1, "sequence is multiple\n") end if Dan Moyer ----- Original Message ----- From: "Tony Steward" <tony at locksdownunder.com> To: "EUforum" <EUforum at topica.com> Sent: Monday, February 25, 2002 1:56 AM Subject: Sequence depths please explain > > 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 > > > >