nim-lang/Nim

cant use w/ #!shebang

takano32 opened this issue · 10 comments

Many script programming languages are commonly able to comment out w/ '#'.
Nimrod is also able to do it.

And many script programming languages are able to use w/ #!shebang.

!shebang is i.e.

#!/usr/bin/env gosh

(define (fib n)
  (if (< n 2) 1
    (+ (fib (- n 2)) (fib (- n 1)))))

(print (fib 30))

But Nimrod cant kick w/ #!shebang.

And i wrote a Nimrod script kicker, cush named from nimrod's father. :-)

# cush.nim
import
  os, osproc

var nim = paramStr(1)
when defined(windows):
  var null = "nul"
  else:
  var null = "/dev/null"
var ret = execCmd("nimrod c " & nim & " > " & null)
var bin = changeFileExt(nim, "")
ret = execCmd(bin)

compile it and put it on $PATH.

And then fix hallo.nim in examples as below.

#!/usr/bin/env cush
# Hello world program

echo "Hello World!"

And you can now, just type

cd examples
./hallo.nim
Hello World!

Wow.

My Nimrod life is accelerated by cush and having more fun!

would you accept cush.nim and builtin build script?

sorry for miss closing. :-(

Araq commented

What about #! /usr/bin/nimrod c -r?

thank you for your comment!

i know about its options, but i wrote cush.nim since below two reasons.

  • i cant make "-r" option completely be quiet. some output must be appeared.
    • even i tried cariblating hints messages.
  • /usr/bin/env is to use for supporting many kinds of user env. i.e. some user may have nimrod at /usr/local/bin/nimrod
    • but /usr/bin/env command dont relay args to what to be exec.

thankyou.

Araq commented

If you change your nimrod.cfg to contain --verbosity:0, --hints:off, --warnings:off the compile is completely quiet. ;-)

Your 'else' is actually not indented properly but the compiler does not complain and the grammar allows it too. :D I am unsure what to do about it because actually your way of indentation makes some sense too...

I close this issue because you found a nice solution to work around the problem which however I don't feel like adding to the distribution ;-) as the compiler's command line handling will change a bit in the future for better editor/IDE support.

thanks for your comment, and i feel ease for loadmap of command line and Edit/IDE support! :-)

thanks to ask me reason of this issue and how to solve it!

thank you.

If cush works, might I request making it an part of the official part of the language (ideally under a more obvious, less namespace-polluting) name, like nimrod-script)?

The thing is, shebang support is often possible in one way or another, but making scripts just work on any plaform that has Nimrod installed... that's a big step forward.

I think silencing all output from the compiler is a bad idea, as it is it looks as if you're running a script interpreted. Maybe a message that says how long it took to compile or something.

So we want self-compiling binaries now?

Now that I hear it Tass way I say YES that sounds like the future to me!