shebang launcher for D programs

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Sat Mar 24 09:00:56 PDT 2007


Daniel Keep wrote:
>>> The #! thing would be cool, but since I run Windows, I don't tend to use
>>> it.  That, and the fact that I tend to use lots of switches :3
>> Do your switches vary from one build to the next, or only from one file
>> to the next? If the latter, you could use:
>>
>> #!/path/to/rundmd -clean -debug -etc
>>
>> as the first line of the program containing main(), and that works under
>> cygwin. You don't have to build your program - ever. It builds itself
>> when necessary.
> 
> They don't vary a great deal.  Although there are times when I'll add in
> some experimental code hidden behind a version identifier, and then play
> with the program with and without the code.
> 
> The other problem is that some projects are not simply a single program.
>  For instance, with my current research project, the base programs are
> altered by specifying additional user modules on the compile-line.  I
> would be very annoyed having to modify a "main" script every time that
> changed :p

No, but it's good you have a default. The shebang does not prevent you 
from actually compiling the program from the command line - it will be 
ignored.

>>> To be honest, I think that D really lacks one important thing that I
>>> would make shell/system scripting far more appealing: an interpreter.
>> I already use D largely as an interpreter. It takes about as long as the
>> equivalent Perl script to build and run, and much less to run - with
>> readln() of course :o). That's why I can't figure out people's
>> indifference vis-a-vis the shebang. It fosters a very attractive
>> development cycle. If I had to build each and all of my D programs
>> before running and dedicate one flagged command to each, I'd be much
>> more frustrated.
>>
>>
>> Andrei
> 
> I should have qualified: an *interactive* interpreter.  Python is so
> massively productive because I can drop into a Python shell and start
> playing with code.  It would be an incredible thing if D had an
> interactive interpreter and I could say
> 
>   "I wonder what happens when I cast a real straight to a ubyte..."
> 
> Then just drop into the interpreter and type
> 
>   >>> cast(ubyte)3.14159
>   3
> 
>   "Ah, it turns into an integer.  What?  Well, it *might* have tried to
> reinterpret it literally, you know... :("

I actually toyed a little with the idea of writing a little shell that 
reads a line, builds a small program with main() around that line, and 
compiles and runs that program. Should be reasonably fast. The problem 
is that this approach won't remember the previously-defined symbols.

> P.S. Incidentally, running that example above has highlighted a new
> problem with my Phobos+Tango joint set up... I can't actually run dmd
> directly anymore :P

Yah, me too. But you can put ". dmdconf phobos" or ". dmdconf tango" in 
your startup file.


Andrei



More information about the Digitalmars-d mailing list