Re: [polyml] suppressing compiler output

2013-03-29 Thread Rob Arthan
David,

On 29 Mar 2013, at 11:50, David Matthews  wrote:

> On 29/03/2013 08:42, Gergely Buday wrote:
>> Back to the original question: this is why I would like to suppress any
>> compiler message.
>> 
>> I did not find such a flag in the manual, would it be possible to add one,
>> David?
> 
> There have been a few suggestions for how to write your own top level and 
> that's definitely the best way if you really want control over the output.  
> I've just committed a change so that the -q option now sets 
> PolyML.print_depth to zero so that by default the output won't be printed.  
> To suppress the prompt you would be better off using the --use option to run 
> the file directly.  You will need to add
> OS.Process.exit OS.Process.success: unit;
> at the end if you don't want to enter the main read-eval-print-loop.

Quite a common thing to do in UN*X applications is not to prompt if the input 
isn't a terminal. Obviously, I can write my own read-eval-print loop that does 
that (indeed the read-eval-print loop in my earlier post on this topic doesn't 
prompt at all), but it might be a nice companion to the change you have just 
made to make the top level do that out of the box. That would give Gergely 
Buday exactly what he is asking for (i.e., the ability to have poly read code 
from the standard input and only output what the compiled code outputs).

Regards,

Rob,.___
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml


Re: [polyml] suppressing compiler output

2013-03-29 Thread David Matthews

On 29/03/2013 08:42, Gergely Buday wrote:

Back to the original question: this is why I would like to suppress any
compiler message.

I did not find such a flag in the manual, would it be possible to add one,
David?


There have been a few suggestions for how to write your own top level 
and that's definitely the best way if you really want control over the 
output.  I've just committed a change so that the -q option now sets 
PolyML.print_depth to zero so that by default the output won't be 
printed.  To suppress the prompt you would be better off using the --use 
option to run the file directly.  You will need to add

OS.Process.exit OS.Process.success: unit;
at the end if you don't want to enter the main read-eval-print-loop.

David

___
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml


Re: [polyml] suppressing compiler output

2013-03-29 Thread Makarius

On Fri, 29 Mar 2013, Gergely Buday wrote:

I want ML scripts to invoke from the command line, without compiling 
them.


As Phil has already pointed out, you can produce standalone executables 
from some Poly/ML program that do whatever you want them to do.


For that ML part of the executable you can invoke the Poly/ML compiler at 
runtime, to compile and run your "script".  Doing this yourself, instead 
of using the default ML toplevel loop, you can control compiler output to 
a large extent, by options provided in structure PolyML.Compiler.


See also this answer on Stackoverflow how to wrap up the Poly/ML compiler 
as "eval" function (without special options):


http://stackoverflow.com/questions/9555790/does-sml-poly-have-a-cl-like-repl/15162800#15162800

If you want we can also continue that Q&A game on Stackoverflow, although 
I have no particular preference for mailing list vs. social network here.



Makarius
___
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml


Re: [polyml] suppressing compiler output

2013-03-29 Thread Rob Arthan

On 29 Mar 2013, at 08:42, Gergely Buday  wrote:

> 
> Back to the original question: this is why I would like to suppress any 
> compiler message.
> 
> 

The function PolyML.compiler lets you write your own customised read-eval-print 
loop. In the code below, the fun my_read_eval_print_loop is a variant of the 
usual one that sends all compiler output to standard error and exits when 
standard input runs out. if you put it in my-revl.ML and run

poly < my-revl.ML 1>a 2>b

there will be a small predictable set of compiler messages at the head of file 
a followed by the standard output of the other code in my-revl.ML and all the 
rest of the compiler messages go in file b.  If you make an executable that 
runs my_read_eval_print_loop following Phil Clayton's post, then you will get a 
program that compiles and runs ML code and sends all compiler messages to 
standard error (so you can discard them using 2>/dev/null on the command line).

Regards,

Rob.

=== beginning of my-revl.ML 
fun read_or_exit () = (
case TextIO.input1 TextIO.stdIn of
NONE => Posix.Process.exit 0wx0
|   some => some
);

fun my_read_eval_print_loop () = (
PolyML.compiler (read_or_exit,
[PolyML.Compiler.CPOutStream
(fn s => TextIO.output(TextIO.stdErr, s))]) ();
my_read_eval_print_loop ()
);

val _ = my_read_eval_print_loop();

(* could also do PolyML.export("my-revl", read_eval_print_loop) at this point *)

fun repeat f n = if n <= 0 then () else (f (); repeat f (n-1));

fun say s () = TextIO.output(TextIO.stdOut, s ^ "\n");

val hello = repeat (say "Hello World!");

hello 10;

val goodbye = repeat (say "Goodbye cruel World!");

goodbye 10;
=== end of my-revl.ML 

___
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml


Re: [polyml] suppressing compiler output

2013-03-29 Thread Gergely Buday
Sorry, I did not make it clear what I want. I want ML scripts to invoke
from the command line, without compiling them. I made it work, see how.
There is an shc [1] translator that compiles shell scripts to C code. I
have used a one-liner [2]:

$ cat polyscript.sh
#!/bin/bash

tail -n +2 $1 | poly

I compiled this with shc and in turn with gcc:

$ shc-3.8.9/shc -f polyscript.sh
$ gcc -Wall polyscript.sh.x.c -o polyscript

Now, I was able to create a first script written in ML:

$ cat smlscript
#!/home/gergoe/projects/shebang/polyscript $0

print "Hello World!"

and, I was able to run it:

$ chmod u+x smlscript
$ ./smlscript
Poly/ML 5.4.1 Release
> > # Hello World!val it = (): unit

It might be interesting to write polyscript directly in C, but probably
that wouldn't make it faster.

Back to the original question: this is why I would like to suppress any
compiler message.

I did not find such a flag in the manual, would it be possible to add one,
David?

- Gergely

[1] http://www.datsi.fi.upm.es/~frosal/

[2]
http://stackoverflow.com/questions/15665119/how-to-define-script-interpreter-with-shebang
 holgero's answer


On 29 March 2013 02:03, Phil Clayton  wrote:

> I'm not sure what your exact requirements are but a possible solution may
> be to create an executable.  Then compile-time output would not be mixed
> with run-time output.  It's straightforward: wrap everything into a
> toplevel function and export that, e.g.
>
> [pclayton@rizzo ~]$ cat hello.sml
> fun main () = print "Hello World!\n";
> PolyML.export ("hello", main);
>
> Compile:
>   cat hello.sml | poly
>
> Link:
>   POLYHOME=/opt/polyml/polyml-5.**5  # your Poly/ML installation
>   POLYLIB=${POLYHOME}/lib
>   LD_RUN_PATH=${POLYLIB}:${LD_**RUN_PATH} cc -ggdb -o hello -L${POLYLIB}
> -lpolymain -lpolyml hello.o
>
> Run:
>   ./hello
>
>
> Phil
>
>
>
> On 28/03/13 20:49, Gergely Buday wrote:
>
>> Hi,
>>
>> I would like to feed an sml program into poly from standard input:
>>
>> $ cat hello.sml |poly
>> Poly/ML 5.4.1 Release
>>
>>> # Hello World!val it = (): unit
>>>
>>
>> Is it possible to use this so that the compiler itself does not print
>> anything? I have found poly -q which does not print the release
>> message but that still prints all the rest.
>>
>> - Gergely
>> __**_
>> polyml mailing list
>> polyml@inf.ed.ac.uk
>> http://lists.inf.ed.ac.uk/**mailman/listinfo/polyml
>>
>>
>>
> __**_
> polyml mailing list
> polyml@inf.ed.ac.uk
> http://lists.inf.ed.ac.uk/**mailman/listinfo/polyml
>
___
polyml mailing list
polyml@inf.ed.ac.uk
http://lists.inf.ed.ac.uk/mailman/listinfo/polyml