"Makarius" <[EMAIL PROTECTED]> wrote:
A remaining hindrance appears to be the slightly strict handling of a sequence of toplevel ML declarations in Alice. This problem can already be reproduced with the 'use' provided by the Alice toplevel. For example: Alice> val a = 1; val b = a + 1; (* works *) File a.ML: val a = 1 Alice> use "a.ML"; val b = a + 1; (* fails, unknown `a' *) Alice> use "a.ML"; \n val b = a + 1; (* works *) The second version fails, because the whole line is compiled before the content of a.ML is evaluated. The third version works again, because the read-eval-print loop happens to treat separate lines of input as units for sequential evaluation (cf. tools/toplevel/TextToplevel.aml). As far as I understand other ML toplevels (notably Poly/ML), the outermost loop takes care not to read chunks of declarations too eagerly. Thus the natural sequential division of toplevel declarations is maintained.
Your are right. Unfortunately, realising this requires feedback between the compiler's parser and the interactive loop. The current setup in Alice does not support that - each input is just compiled as a component and then evaluated. That is, Compiler.eval is basically just ComponentManager.eval o Compiler.compile.
The only thing you can do is splitting the input yourself before feeding it to the eval function. A correct implementation would require a rudimentary parser that can distinguish toplevel from nested semicolons. However, I think the following heuristic should be good enough for practical purposes: split the string at every semicolon that is followed only by whitespace in the same line, and where the next line has no initial white space (i.e. is not indented). This can be implemented by a straight-forward string traversal.
Hope this helps, - Andreas _______________________________________________ alice-users mailing list [email protected] http://www.ps.uni-sb.de/mailman/listinfo/alice-users
