shebang launcher for D programs
Lionello Lunesu
lio at lunesu.remove.com
Sun Mar 25 07:30:37 PDT 2007
Andrei Alexandrescu (See Website For Email) wrote:
> 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.
Yes!! I thought about making this too! Like the old times with MSX and
C64! I loved having a "playground" like that.
It's possible to do in D as well, just append all lines to an in-memory
D-file and it'll "remember" variables. You'll have to take care about
multiply defined symbols, by ignoring the first? Not sure about the
details yet.
L.
More information about the Digitalmars-d
mailing list