Scientific computing with D

Daniel Keep daniel.keep.lists at gmail.com
Sat Jan 31 17:56:26 PST 2009



Walter Bright wrote:
> Daniel Keep wrote:
>>
>> Walter Bright wrote:
>>> Bill Baxter wrote:
>>>> Having to recompile and rerun after every one of those changes just
>>>> isn't quite as direct.
>>> If it can be done in under half a second, isn't that direct enough? Of
>>> course, I'm talking about a shell that does it for you.
>>
>> $ int a = 42;
>> $ writefln("a = %s", a);
>> $ double a = 3.0; // rounded to 1 sf
>>
>> How would you write a prompt that does that with D?  Either you store
>> each successive line in a source file and choke on the third one, or you
>> compile each line separately and choke on the second.
>>
>> Or you could examine each line to look for things like redefining of
>> symbols... but at that point you're half way to writing an interpreter
>> anyway.
> 
> It's the shell's responsibility to decide what semantics to present to
> the user, I'm just saying that the process of turning a code snippet
> into an executable is fast and should not be a barrier.

Perhaps, but the above example shows why interactive prompts are so
useful, and why simply feeding them to a standard compiler isn't likely
to work very well.  Speed isn't the issue in this particular case.

Here's another fun one:

$ void hello() { writefln("Hello, World!"); }
$ hello();
Hello, World!
$ import enAU : hello; hello();
G'day, World!

An interactive prompt, to be really useful, should have slightly
different semantics to the language proper.  I personally think that
turning DMD into a library won't help; you really need a purpose-built
interpreter.

  -- Daniel



More information about the Digitalmars-d mailing list