Re: converting sequence to string

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

Here's a recursive routine that will "flatten out" a
deeply nested sequences of atoms and sequences.

global function flatten_seq( sequence s )
  atom ec  sequence ns
  ns = {}  ec = 0
  for i = 1 to length(s) do
    if atom(s[i]) then
      ns &= s[i]
      ec += 1
    else
      ns &= flatten_seq(s[i])
    end if
  end for
  if ec = length(s) then return {ns}
  else return ns
  end if
end function

Instead of simply taking a sequence and making it have all
atoms inside, this will preserve "strings". For example:

Input: {1,2,3,{4,5,{"hi",{"guy","girl"},6,'7'}},8,9,10}
Output: {1,2,3,4,5,"hi","guy","girl",6,'7',8,9,10}

The only downside is if the sequence has only atoms in it
to begin with, then it will make them into a single string :)

----->Buddy
budmeister1 at juno.com
http://tenbux.iwarp.com/

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

Search



Quick Links

User menu

Not signed in.

Misc Menu