1. Re: your mail

:  With the following program I want to end up with a file looking like
:  this:
:                {
:                {{"SMITH"},{{{"FRED"},62,75},{{"JACK"},55,57}}},
:                {{"JONES"},{{{"HARRY"},44,54},{{"SAM"},12,15}}}
:                }
:  and NOT this:
:       {
:       {{83,77,73,84,72},{{{70,82,69,68},62,75},{{74,65,67,75},55,57}}},
:       {{74,79,78,69,83},{{{72,65,82,82,89},45,54},{{83,65,77},12,15}}}
:       }

I wrote a routine similar to what you need, feel free to modify it.

-- begin code

-- performs exactly the same function as print( but does it in a more
-- readable fashion by indenting nested sequences and outputing strings
-- in quotes rather than a sequence of ascii numbers

function string_sequence(object x)
   atom answer

   if sequence(x) then

      answer = 1
      for i = 1 to length(x) do

         if sequence(x[i]) then

            answer = 0

         else

            if x[i] < ' ' then answer = 0 end if

         end if

      end for

   else

      answer = 0

   end if
   return answer
end function


function blarg(object x, atom indent)
   object temp

   if atom(x) then

      return repeat(' ', indent) & sprintf("%d", x)

   else

      if string_sequence(x) then

         return repeat(' ', indent) & "\"" & x & "\""

      else

         temp = repeat(' ', indent) & "{\n"
         for i = 1 to length(x) do

            temp = temp & blarg(x[i], indent + 3)
            if i < length(x) then temp = temp & "," end if
            temp = temp & "\n"

         end for
         return temp & repeat(' ', indent) & "}"

      end if

   end if
end function


global procedure human_and_computer_readable_print(atom handle, object x)
   puts(handle, blarg(x, 0))
end procedure


global function human_and_computer_readable_sprint(object x)
   return blarg(x, 0)
end function

-- end code
run thru this routine, your example would look like this...
{
   {
      {
         "SMITH"
      },
      {
         {
            {
               "FRED"
            },
            62,
            75
         },
         {
            {
               "JACK"
            },
            55,
            57
         }
      }
   },
   {
      {
         "JONES"
      },
      {
         {
            {
               "HARRY"
            },
            44,
            54
         },
         {
            {
               "SAM"
            },
            12,
            15
         }
      }
   }
}

Matthew McNamara                          _
mat at iconz.co.nz                         o( )
The Internet Company of New Zealand    /  /\

new topic     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu