On Sat, Apr 27, 2013 at 12:48 PM,
w.r...@ntlworld.com
<
w.r...@ntlworld.com> wrote:
> I'm not too sure about your distinction. I thought that the best
> place to start would be with a C++ port of Shen, and maybe look at the
> SECD in the future.
> My problem is that a Lisp list is essentially heterogeneous and so is
> a KLambda list. C++ lists are type homogeneous and I don't see how to
> define a general type
> 'Lisp Object' in C++ without performing my own memory management.
>
Hi Willi.
Can you clarify what you mean by performing your own memory management
(you still need a GC which is not provided by C++, right?).
Regarding heteregeneous collections (warning, possibly dumb, naive and
not well-thought ideas), I would start with an abstract base class
'KLambdaObject' which defines as virtual methods every KLambda
primitive that takes a value as a parameter ('number?', 'cons?', 'hd',
'tl', etc) with their default implementations raising a type error
exception.
Then for each primitive type defined by the KLambda spec a subclass
would be defined that overrides the implementation of the methods that
make sense for that type (a pair type would redefine 'hd' and 'tl' to
return its first and second elements, and 'cons?' to return 'true').
KLambdaObject KLambdaObject::tl() { throw KLambdaTypeError("Not a cons"); }
KLambdaObject KLambdaCons::tl() { return my_tail; }
inline KLambdaObject tl(KLambdaObject &val) { return
val.tl(); }
This is of course not very performant, but assuming there is no typing
information (something which is true for the current version of Shen)
I'm not sure about how to do better. Once typing information is
available then overloaded versions of functions could be defined, for
example:
inline KLambdaObject plus(KLambdaObject a, KLambdaObject b) { return
a.plus(b); }
inline double plus(double a, double b) { return a + b; }
> Willi
>
> On 27 Apr, 13:53, Konrad Hinsen <
googlegro...@khinsen.fastmail.net>
> wrote:
>> --On 27 avril 2013 04:39:25 -0700 Mark Tarver <
dr.mtar...@gmail.com> wrote:
>>
>> > The SECD makes interop with any low level language much easier. Your
>> > vote for C++ has Willi's endorsement; it is something he would like to
>> > do. **He is hung up on the problem of heterogeneous lists and would
>> > like to know how to formulate this in C++.** I would guess that some
>>
>> What exactly is the goal:
>>
>> 1) Implement Lisp-style lists containing Lisp values in C++
>>
>> or
>>
>> 2) Implement heteregeneous lists whose elements can be any C++ data?
>>
>> The first version should be straightforward by defining a "Lisp object"
>> type, so I suppose you want to do the second? That's not straightforward at
>> all, in particular if you want some kind of memory management.
>>
>> > If anybody wants to donate "Lisp in Small Pieces" to the project then
>> > get in touch. We were trying to get this book through library loan
>> > and failed.
>>
>> For those who read French, there is an updated edition that also happens to
>> be a lot cheaper:
>>
>> Principes d'implantation de Scheme et Lisp
>>
http://paracamplus.com/?CGIRunMode=book&urn=Cours/LiSP/4
>>
>> Konrad.
>
> --
> You received this message because you are subscribed to the Google Groups "Qilang" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
qilang+un...@googlegroups.com.
> To post to this group, send email to
qil...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/qilang?hl=en.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>
--
BD