/ single linked homogenous list template

Bjoern nanali at nospam-wanadoo.fr
Sat May 3 16:16:04 PDT 2008


OR : Lisp like List in D Take 2

Andrew McKinley from Axxon / Suneido Software was gentle enough to allow 
me to show his C++ code to discuss what is (or what is actually not) 
possible in D2.

I'll attach his source as reference however the most interesting parts are :
How you work around for reference return values ?
Copy constructor ...
Some C++ specific operator overloads

...I am not asking you to to my homework... it is just that I can't find 
a satisfying solution regarding a D port of this specific software.

--
Okay a Lisp list is based on a CONS CELL
a CONS CELL defined in C  will look like :
typedef void   *POINTER;      /* General purpose pointer */


typedef struct                /* A CONS is two pointers  */
    {
    POINTER  car;
    POINTER  cdr;
    } CONS;
typedef CONS    *LIST;        /* A LIST is a pointer to  */
                               /* a CONS
// which becomes in D

alias void*  POINTER;
struct CONS
{
    POINTER  car;
    POINTER  cdr;
}
alias CONS* LIST;

which is nonsense (sorry reg. the mess I've published before Bearophile)

So :
struct CONS(T)
{
    T value;
    CONS* next;
}
//makes a bit more sense

A Q and Dirty implementation of LispList is :

class Lisp(T)
{
   this(T) {}


   scope class Cons(T) //erm
   {
      this(T)
       {}
   }


}

Well we have to look at the attached source now :
You'll find a lot of stuff -< which is not doable in D. Workarounds ?
just have a look at
T& operator[](int i)
{ return nth(i); }

const T& operator[](int i) const
	{ return nth(i); }


Yummie

Back to the cons cell. I really wonder if array slicing is an option 
here . Let's say :
//INSTEAD OF
struct CONS(T)
{
    T value;
    CONS* next;
}


struct CONS(T)
{
    T value;
    CONS*[] cons;
}

???????
Just for me it seems that porting C++ is not a stringent task.

What do yopu think ?




-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: lisp.h
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20080504/5cc1532d/attachment.h>


More information about the Digitalmars-d mailing list