Version 25 of D

Updated 2006-10-10 22:06:33

The D programming language (of interest here; there actually have been several distinct significant D languages [L1 ] during the history of programming) is a new language designed as an evolution of C/C++. The language specification is currently at http://www.digitalmars.com/d/index.html Also of potential interest are the Wikipedia page [L2 ] and Wiki4D site [L3 ].

To see how D compares to other languages, check out http://www.digitalmars.com/d/comparison.html .


We can call Tcl from D fairly simply. In fact, it looks a lot like C++ in most places. The main issue is to generate an import symbol file for the Tcl API (which can be done by using the genStubs script file).

Under Microsoft Windows I had to convert the standard ActiveTcl tcl83.lib to an OMF format library. To do this we convert to COFF format using Microsoft's LINK program and then Digital Mars' COFF2OMF utility

  link /lib /convert tcl83.lib
  coff2omd tcl83.lib

To illustrate, here is an initial stab. Build this using

 dmd simple.d tcl83.lib  (Using Windows)

or

 dmd simple.d -L-ltcl    (Using UNIX)

 // simple.d - Copyright (C) 2003 Pat Thoyts <[email protected]>
 //
 // Demonstrate linking to Tcl from the D programming language. 
 // See http://www.digitalmars.com/d/index.html for information
 // about ``D''
 //
 // $Id: 6261,v 1.26 2006-10-11 06:00:08 jcw Exp $

 import c.stdio;
 import stream;
 import compiler;

 // ----------------------------------------------------------------------
 // Define the bits we need for interfacing to Tcl API
 //
 extern (C) {
     alias void* ClientData;
     alias void (*Tcl_FreeProc)(char* blockPtr);
     alias void (*Tcl_CmdDeleteProc)(ClientData clientData);
     alias int (*Tcl_CmdProc)(ClientData clientData, Tcl_Interp * interp,
                              int argc, char* argv[]);
     alias void* Tcl_Command;

     struct Tcl_Interp {
         char* result;
         Tcl_FreeProc blockPtr;
         int errorLine;
     }

     enum {
         TCL_OK = 0,
         TCL_ERROR = 1,
         TCL_RETURN = 2,
         TCL_BREAK = 3,
         TCL_CONTINUE = 4,
     }

     enum : Tcl_FreeProc {
         TCL_VOLATILE = (Tcl_FreeProc)1,
         TCL_STATIC = (Tcl_FreeProc)0,
         TCL_DYNAMIC = (Tcl_FreeProc)3,
     }

     export {
        Tcl_Interp* Tcl_CreateInterp();
        Tcl_Command Tcl_CreateCommand(Tcl_Interp * interp, char * cmdName,
                                      Tcl_CmdProc proc,
                                      ClientData clientData,
                                      Tcl_CmdDeleteProc deleteProc);
        int Tcl_Eval(Tcl_Interp * interp, char * string);
        int Tcl_EvalFile(Tcl_Interp * interp, char * fileName);
        char * Tcl_GetStringResult(Tcl_Interp* interp);
        void Tcl_SetResult(Tcl_Interp * interp, char * str,
                           Tcl_FreeProc freeProc);

     }
 }

 // ----------------------------------------------------------------------

 int main(char[][] args)
 {
     Tcl_Interp* interp;
     interp = Tcl_CreateInterp();

     Tcl_CreateCommand(interp, "ddemo", &DDemoCmd,
                       (ClientData)null, (Tcl_CmdDeleteProc)null);

     int r;
     if (args.length < 2)
     {
         r = Tcl_Eval(interp, "puts "Tcl version: [info tcl]"; ddemo");
     }
     else
     {
         int r = Tcl_EvalFile(interp, args[1]);
     }
     printf(Tcl_GetStringResult(interp));
     return r;
 }

 // Add a new command to the Tcl interpreter.
 // In this case: return some information about the D compiler.
 extern (C):
 int 
 DDemoCmd(ClientData clientData, Tcl_Interp *interp, int argc, char* argv[])
 {
     MemoryStream stm = new MemoryStream;
     stm.printf(compiler.name);
     stm.printf(" %d.%d", compiler.version_major, compiler.version_minor);
     Tcl_SetResult(interp, stm.toString(), TCL_STATIC);
     return TCL_OK;
 }

 // ----------------------------------------------------------------------
 //
 // Local variables:
 //   mode: c
 //   compile-command: "dmd simple.d tcl83.lib"
 // End:

RLH That seems like a good language. I wonder why it isn't used more?

MSW From a quick glance at it, probably because there's no open source compiler and thus the thing only runs on a very limited set of (OS x CPU/arch). There's http://www.opend.org and it seems dead for soon half a decade...

RLH Is this integration with GCC what you are talking about it not having [L4 ]? But the limited OS support is probably a reason.

MSW Ok, haven't seen that one. Still being a kind of "simple" successor to C, it should run in more places. Kind of like same reason why people don't use Cyclone([L5 ]) etc I guess...


As of October 2006, D is on the verge of being a language with a Tk binding [L6 ].

RLH That isn't how I read that thread.

LWV After reading through the thread a bit, I see http://www.algonet.se/~afb/d/TK.zip is a beginning of a binding between D and Tk. Some of the issues are people wanting a D GUI that is designed with D philosophies, and later in the thread, concern about the fact that Tk requires X11 headers in some cases. I do not get the feeling that the D community itself is embracing Tk. Instead, there appears to be a number of people thinking about the possibility, with a larger number looking at alternatives.


[ Category Language ]