PreviousUpNext

15.4.1106  src/lib/std/src/io/say.pkg

## say.pkg
## author: Matthias Blume (blume@cs.princeton.edu)

# Compiled by:
#     src/lib/std/src/standard-core.sublib

# Output of feedback and diagnostics.



###           "Examine what is said, not who speaks."
###
###                         -- Arabian proverb



api Say {

    say:  List( String ) -> Void;
    dsay: List( String ) -> Void;
    log:  List( String ) -> Void;

    set_name: String     -> Void;
};

stipulate
    package fil =  file__premicrothread;                                # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    package   say
    :         Say
    {
        server_name =  REF NULL: Ref( Null_Or( String ));
        log_stream  =  REF NULL: Ref( Null_Or( fil::Output_Stream ) );

        debug   = TRUE;

        fun set_name name
            =
            {   server_name := THE name;
                #
                log_stream  := THE (fil::open_for_write  (name + ".compile.log"));
            };


        fun log stringlist
            =
            case (*server_name, *log_stream)
                #         
                 (THE name, THE outstream)
                     =>
                     {   fil::write 
                             (
                               outstream, 
                               cat (name ! ": " ! stringlist)
                             );

                         fil::flush  outstream;
                     };

                 _ => ();
            esac;

        fun say stringlist
            =
            {   print (cat stringlist);
                fil::flush  fil::stdout;

                log stringlist;
            };



                                                            # makelib_defaults  is from   src/app/makelib/stuff/makelib-defaults.pkg


        fun csay flag stringlist                                # "csay" == "conditional say".
            =
            if flag
                say stringlist;
            fi;

        dsay =   csay  debug;
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext