www.digitalmars.com         C & C++   DMDScript  

D - Venus library 0.01

reply Helmut Leitner <helmut.leitner chello.at> writes:
You can find the first revision of the Venus library at

  <http://www.prowiki.org/wiki4d/wiki.cgi?VenusLibrary>

It's donated to Digital Mars and GPL for all others.

It is pretty rudimentary according to its 0.01 version
and the current explorative nature.

A few things may be interesting:

A function pointer => delegate conversion that helps to 
build or use abstract code interfaces:

   Delegate dg=FpRetDelegate(foo);

This is used in the benchmark module which aims at precision
timing of code from seconds down to single instructions, so

   double [char []] hash;
   DelegateBenchPrint( delegate void () { hash["Test"]=1; },"add to hash");

will result in something like:

   add to hash 46.933 usec

The module tries to make results as stable as possible.

There is an abstraction from the D primitive types (type module) allowing 
something like (in the str module)

   void StrCat(inout Str s,char    t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,byte    t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,ubyte   t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,short   t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,ushort  t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,int     t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,uint    t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,long    t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,ulong   t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,float   t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,double  t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,ifloat  t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,idouble t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,cfloat  t) {  StrCat(s,TypeRetTpi(t));  }
   void StrCat(inout Str s,cdouble t) {  StrCat(s,TypeRetTpi(t));  }

I hope that some primitive type abstraction will allow us to reduce
this to one line in the near future.

Similar interfaces support the printing of all types (print module)
using

   Print(type);
   PrintLine(type);
   Print(Str prompt,type);
   PrintLine(Str prompt,type);

Older snippets are included in the library like

   DirFindFile / DirFindFileCall 

And there is of course the

   alias char[] Str;

I've avoided the name String, because someone might like to introduce 
an official string type and I didn't want to pollute the namespace.

Hope you find it useful, provoking or at least interesting. 

Any feedback is welcome, here or in the wiki.

--
Helmut Leitner    leitner hls.via.at   
Graz, Austria   www.hls-software.com
May 04 2003
next sibling parent "Walter" <walter digitalmars.com> writes:
Thanks for doing this!
May 04 2003
prev sibling parent "Sean L. Palmer" <palmer.sean verizon.net> writes:
I hope something like this gets ratified into the standard soon.

It seems to not limited to just printing.  Got timing, file handling;  lots
of stuff.

Sean

"Helmut Leitner" <helmut.leitner chello.at> wrote in message
news:3EB567AD.85CE5C53 chello.at...
 You can find the first revision of the Venus library at

   <http://www.prowiki.org/wiki4d/wiki.cgi?VenusLibrary>

 It's donated to Digital Mars and GPL for all others.

 It is pretty rudimentary according to its 0.01 version
 and the current explorative nature.

 A few things may be interesting:

 A function pointer => delegate conversion that helps to
 build or use abstract code interfaces:

    Delegate dg=FpRetDelegate(foo);

 This is used in the benchmark module which aims at precision
 timing of code from seconds down to single instructions, so

    double [char []] hash;
    DelegateBenchPrint( delegate void () { hash["Test"]=1; },"add to
hash");
 will result in something like:

    add to hash 46.933 usec

 The module tries to make results as stable as possible.

 There is an abstraction from the D primitive types (type module) allowing
 something like (in the str module)

    void StrCat(inout Str s,char    t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,byte    t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,ubyte   t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,short   t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,ushort  t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,int     t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,uint    t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,long    t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,ulong   t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,float   t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,double  t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,ifloat  t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,idouble t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,cfloat  t) {  StrCat(s,TypeRetTpi(t));  }
    void StrCat(inout Str s,cdouble t) {  StrCat(s,TypeRetTpi(t));  }

 I hope that some primitive type abstraction will allow us to reduce
 this to one line in the near future.

 Similar interfaces support the printing of all types (print module)
 using

    Print(type);
    PrintLine(type);
    Print(Str prompt,type);
    PrintLine(Str prompt,type);

 Older snippets are included in the library like

    DirFindFile / DirFindFileCall

 And there is of course the

    alias char[] Str;

 I've avoided the name String, because someone might like to introduce
 an official string type and I didn't want to pollute the namespace.

 Hope you find it useful, provoking or at least interesting.

 Any feedback is welcome, here or in the wiki.

 --
 Helmut Leitner    leitner hls.via.at
 Graz, Austria   www.hls-software.com
May 04 2003