Steve Graham wrote:
> I use Unicon infrequently enough that it probably looks like another 
> language written in Unicon.  In the program below, I am running through 
> 2 levels of directories to print the files in the 2nd level.  If you 
> have any suggestions on how to better take advantage of Unicon's 
> features, I would appreciate hearing them.
> 
> procedure main()
>    infile := "c:/users/steve/documents/bom"
>    in := open(infile,"r") | stop("Unable to open " || infile)
>    while line := read(in) do {
>       if line[1] ~== "." then {
>          write("\r\l",line)
>          afile := infile || "/" || line
>          in2 := open(afile,"r") | stop("Unable to open " || afile)
>          while line := read(in2) do {
>             if line[1] ~== "." then write("   ",line," 
> (",afile,"/",line,")")
>          }
>       }
>    }
>    close(in)
> end

That's a simple enough task that I'm not sure how much
rewriting is useful.  (However, you should close(in2)
inside the outer loop!)

Here's a slight rewrite that hits Unicon features a
bit harder, but I'm not sure the task justifies the
changes!:

procedure main(A)
    infile := A[1] | "c:/users/steve/documents/bom"     # (generalize)
    in := open(infile) | stop("Unable to open ", infile)
    every "." ~== (line := !&input) do {
       write("\n",line)
       afile := infile || "/" || line
       in2 := open(afile) | stop("Unable to open ", afile)
       every "." ~== (line := !in2) do
          write("  ",line," (",afile,"/",line,")")
       close(in2)
       }
    close(in)
end

If you wanted to format the output different Unicon's features might
play a bigger role.

-- 
Steve Wampler -- [email protected]
The gods that smiled on your birth are now laughing out loud.

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Unicon-group mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to