P
Piotr Filip Mieszkowski
Hello,
I like both C++ and Lisp and sometimes try to mix their ideas in the
code I write. Recently I started to think about writing a pair class
similar to the CONS in Lisp. (For those of you who don't know Lisp:
lists in Lisp are constructed of pairs whose second element is always
the next pair or NIL, a special symbol.) So I've tried something like
this:
template <class A, class B>
struct cons {
A car;
B cdr;
};
// I thought it might serve as the last pair.
template <class A>
struct cons<A, void> {
A car;
};
But I have no idea what to do next -- how to use this type. I've
redefined the basic cons to be:
template <class A, class C>
struct cons {
A car;
cons<A, C> cdr;
};
But still I have no idea how to use it. I think there must be some way
to get over the recursive nature of that type. But... it's signature
would be recursive, wouldn't it? Or maybe something's wrong with my
idea and I should re-think it?
Any ideas?
Thanks in advance.
Regards,
pfm
I like both C++ and Lisp and sometimes try to mix their ideas in the
code I write. Recently I started to think about writing a pair class
similar to the CONS in Lisp. (For those of you who don't know Lisp:
lists in Lisp are constructed of pairs whose second element is always
the next pair or NIL, a special symbol.) So I've tried something like
this:
template <class A, class B>
struct cons {
A car;
B cdr;
};
// I thought it might serve as the last pair.
template <class A>
struct cons<A, void> {
A car;
};
But I have no idea what to do next -- how to use this type. I've
redefined the basic cons to be:
template <class A, class C>
struct cons {
A car;
cons<A, C> cdr;
};
But still I have no idea how to use it. I think there must be some way
to get over the recursive nature of that type. But... it's signature
would be recursive, wouldn't it? Or maybe something's wrong with my
idea and I should re-think it?
Any ideas?
Thanks in advance.
Regards,
pfm