% Written by Josh Siegel

/stringer { % proc => string
    {
        dup type cvlit
        {
            /arraytype {
                /the_string the_string ( { ) append store
                stringer
                /the_string the_string ( } ) append store
            }
            /nametype {
                dup xcheck {
                    255 string cvs the_string ( ) append exch 
                    append /the_string exch store
                } {
                    255 string cvs
                    /the_string the_string ( /) 4 -1 roll append 
                    append store
                } ifelse
            }
            /operatortype {
                255 string cvs dup length 2 sub 1 exch getinterval
                the_string ( ) append exch append /the_string exch store
            }
            /stringtype {
                ( \() exch (\) ) append append the_string
                exch append /the_string exch store
            }
            /Default {
                255 string cvs the_string ( ) append exch 
                append /the_string exch store
            }
        } case
    } forall
} def


/wrapper { % proc => string
    10 dict 
    begin
        /proc exch def
        /the_string (/) proc 255 string cvs ( { \n) append append def
        proc load stringer the_string ( } def \n) append
    end
} def

/write_out {
	/the_file (out_file) (w) file def
	the_file /stringer wrapper writestring
	the_file /wrapper wrapper writestring
	the_file /write_out wrapper writestring
	the_file (\nwrite_out\n) writestring
	the_file closefile
} def

write_out
