Home My Page Projects Code Snippets Project Openings SML/NJ Bugs
Summary Activity Tracker Lists

[#84] No shebang support

Date:
2011-11-14 22:56
Priority:
3
State:
Open
Submitted by:
Bug Submitter (webuser)
Assigned to:
Nobody (None)
Machine Architecture:
None
Operating System:
None
Component:
None
Resolution:
None
Severity:
Minor
OS Version:
SML/NJ Version:
Keywords:
URL:
Transcript (of reproduction):
Source (for reproduction):
Summary:
No shebang support

Detailed description
Its useful to begin scripts in other programming languages with a shebang.

hello.py:

#!/usr/bin/env python
print Hello World!

This allows a script to be run with dot slash notation in Unix, Linux, and Mac OS X.

In other words, while you can already do this:

$ python hello.py
Hello World!

It is useful to treat a script as if it were a binary:

$ ./hello.py
Hello World!

We can come close to this behavior in SML:

hello.sml:

print Hello World!\n;
OS.Process.exit(OS.Process.success);

$ sml hello.sml
Hello World!

However, when we add the proper shebang, SML/NJ borks.

hello.sml:

#!/usr/bin/env sml
print Hello World!\n;
OS.Process.exit(OS.Process.success);

Example:

$ ./hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening ./hello.sml]
./hello.sml:1.12-1.15 Error: unbound variable or constructor: env
./hello.sml:1.16-1.19 Error: unbound variable or constructor: sml
./hello.sml:1.8-1.11 Error: unbound variable or constructor: bin
./hello.sml:1.1-1.4 Error: unbound variable or constructor: #!/
./hello.sml:1.4-1.7 Error: unbound variable or constructor: usr
/opt/local/share/smlnj/bin/sml: Fatal error -- Uncaught exception Error with 0
raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27

The solution is for SML to treat #!...\n as a comment. This is already being discussed in Successive ML.

Futhermore, I lied. When you submit the following code to SML:

hello.sml:

print Hello World!\n;
OS.Process.exit(OS.Process.success);

SML spits out a bunch of spurious warnings and statements.

$ sml hello.sml
Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011]
[opening hello.sml]
Hello World!
val it = () : unit
[autoloading]
[library $SMLNJ-BASIS/basis.cm is stable]
[autoloading done]
hello.sml:2.1-2.36 Warning: type vars not generalized because of
value restriction are instantiated to dummy types (X1,X2,...)

These really get in the way of scripting, because they gum up command line interfaces. Can some of these be turned off by default? Or, could SML/NJ add a special -script flag that disables such warnings?
Fix:
Consider #!...\n a comment.

Disable some warnings by default, or add a -script option.

Submitted via web form by Andrew Pennebaker andrew.pennebaker@gmail.com

Comments:

Message  ↓
Date: 2011-11-25 19:55
Sender: John Reppy

Probably the right way to address this request is to implement a wrapper program for running scripts. The wrapper could strip off the "#!" line and submit the rest of the code to the sml program.

Attached Files:

Changes

Field Old Value Date By
detailsIts useful to begin scripts in other programming languages with a shebang. hello.py: #!/usr/bin/env python print Hello World! This allows a script to be run with dot slash notation in Unix, Linux, and Mac OS X. In other words, while you can already do this: $ python hello.py Hello World! It is useful to treat a script as if it were a binary: $ ./hello.py Hello World! We can come close to this behavior in SML: hello.sml: print Hello World!\n; OS.Process.exit(OS.Process.success); $ sml hello.sml Hello World! However, when we add the proper shebang, SML/NJ borks. hello.sml: #!/usr/bin/env sml print Hello World!\n; OS.Process.exit(OS.Process.success); Example: $ ./hello.sml Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011] [opening ./hello.sml] ./hello.sml:1.12-1.15 Error: unbound variable or constructor: env ./hello.sml:1.16-1.19 Error: unbound variable or constructor: sml ./hello.sml:1.8-1.11 Error: unbound variable or constructor: bin ./hello.sml:1.1-1.4 Error: unbound variable or constructor: #!/ ./hello.sml:1.4-1.7 Error: unbound variable or constructor: usr /opt/local/share/smlnj/bin/sml: Fatal error -- Uncaught exception Error with 0 raised at ../compiler/TopLevel/interact/evalloop.sml:66.19-66.27 The solution is for SML to treat #!...\n as a comment. This is already being discussed in Successive ML. Futhermore, I lied. When you submit the following code to SML: hello.sml: print Hello World!\n; OS.Process.exit(OS.Process.success); SML spits out a bunch of spurious warnings and statements. $ sml hello.sml Standard ML of New Jersey v110.72 [built: Mon Nov 14 17:30:10 2011] [opening hello.sml] Hello World! val it = () : unit [autoloading] [library $SMLNJ-BASIS/basis.cm is stable] [autoloading done] hello.sml:2.1-2.36 Warning: type vars not generalized because of value restriction are instantiated to dummy types (X1,X2,...) These really get in the way of scripting, because they gum up command line interfaces. Can some of these be turned off by default? Or, could SML/NJ add a special -script flag that disables such warnings? Fix: Consider #!...\n a comment. Disable some warnings by default, or add a -script option. Submitted via web form by Andrew Pennebaker andrew.pennebaker@gmail.com 2016-06-30 18:46jhr