Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] coding the closing parentheses correctly

From: dougedmunds:gma:il at: 30-Apr-2008 16:10

Hello, I am trying to code output from a string where: 1.'aN': 'a' represents a container, with 'N' items in it. 2. A container can be an item of another container I am using parentheses to show the container. In my example d, e, f, p, q, r, and s are separate items, not atoms 'def and 'pqrs For example, this input: x: "a2a3defa4pqrs" should produce this output: ((def)(pqrs)) But what I get is this: ((def(pqrs))) All the closing parentheses are at the end. Similarly, x: "a4a4pqrsdef" should produce this: ((pqrs)def) but I get this: ((pqrsdef)) Any suggestions? (Note, I can't do anything to hard-code the closing parenthesis of a container. It has to be based on the length of the container. My actual input is binary, and has a similar structure). == Doug Edmunds ;------------ REBOL[] start: func [x] [ main x] main: func [x] [print "looping" prin x prin " of len x (1) " print length? x while [(length? x) > 0] [ prin x prin " of len x (2) " print length? x fx: to-string first x x: skip x 1 switch/default fx [ "a" [append output "(" len: to-integer first x x: skip x 1 y: copy/part x length? x ; what's left x: tail x ; done with this iteration prin "y " print y main y append output ")"] ] [append output fx] ] ] ; test run output: [] ; should produce ((def)(pqrs)) x: "a2a3defa4pqrs" start x print output