From: "Lucas Dixon" <[EMAIL PROTECTED]>:

I was not imagining  pickling the interactive loop itself, which will
have a IO stream to stdin/stdout, but the result of it. I know that
alicec can compile arbitrary ML files (presumably assuming that no
streams are left open?). So I thought that similar behavior must be
possible with the a user interaction - just take the users input lines
as lines in a file that is being compiled. The result would be a
compiled alice component, which, I thought, was pickleble?

Actually, you do need neither alicec nor pickling to do that, as the Compiler structure from the Alice library allows you to compile directly from a string to a first-class component value in memory. You can pass such values directly to the component manager for evaluation.

Given that, what you describe is pretty much the implementation of the Alice toplevel. So yes, your suggestion is workable. But admittedly, I do not fully understand what you are getting at. It seems that what you are considering boils down to 'using' files by compiling and evaluating them line by line (or rather, dec by dec). I already proposed something along these lines in an earlier post:

http://www.ps.uni-sb.de/pipermail/alice-users/2007/000785.html

I think it should be fairly easy to write a wrapper to the 'use' function that operates that way (i.e., splits the file and then uses each bit separately). That doesn't even require changing or redoing the toplevel implementation - just import the wrapper into the toplevel before use-ing anything.

Obviously, this would be simpler if there was some form of 'useString' function. Then you'd just do

fun splitSource (s : string) : string list = ...   (*) some string hackery

val useStringProper = useString
fun useString src = List.app useStringProper (splitSource src)
fun use file =
   let
      val f = TextIO.openIn file
      val src = TextIO.inputAll f
   in
      TextIO.closeIn f;
      useString src
   end

Short of that, you have to create temporary files. Here is a skeleton (untested):

val useProper = use
fun use file =
   let
      val f = TextIO.openIn file
      val src = TextIO.inputAll f
      do TextIO.closeIn f
      val srcs = splitSource src
val files = List.tabulate (List.length srcs, fn _ => OS.FileSys.tmpName ())
      val final = OS.FileSys.tmpName ()
      val ffinal = TextIO.openOut final
   in
      ListPair.app (fn (src, file) =>
         let
            val f = TextIO.openOut file
         in
            TextIO.output (f, src);
            TextIO.closeOut f;
TextIO.output (ffinal, "do OS.FileSys.remove \"" ^ file ^ "\"\n");
            useProper file    (*) queue it
         end) (srcs, files);
      TextIO.closeOut ffinal;
      useProper final      (*) remove temp files
   end

Admittedly, this is quite a hack with all the temporary files. But it should work. Maybe I'll add a useString function for the next release. :-)

Hope that helps,
- Andreas


_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users

Reply via email to