LISP generalized lists in C



I want to work with "generalized lists" as in Lisp, say :

((23 () . 2) () ((10))) ; only pointers and integers

So the basic element is a node, a struct with two fields car and cdr.
Each of these fields can contain either a pointer (NULL or a pointer to
another node), or an int.

I want to define the functions cons, car and cdr of Lisp.

I tried this but gcc rejects it :

#include <stdio.h>
#include <stdlib.h>

typedef struct {
object car;
object cdr;
} node;

typedef struct {
int tag; // 0==int, 1==node*
union {
int value;
node *ptr;
} val;
} object;

node* cons(object a, object b) { ...}

Can you help ? Thanks...

JG
.



Relevant Pages

  • Re: LISP generalized lists in C
    ... So the basic element is a node, a struct with two fields car and cdr. ... Each of these fields can contain either a pointer (NULL or a pointer to ...
    (comp.lang.c)
  • Re: LISP generalized lists in C
    ... So the basic element is a node, a struct with two fields car and cdr. ... Each of these fields can contain either a pointer (NULL or a pointer to ...
    (comp.lang.c)
  • Re: Lisp in hardware
    ... > and then you could implement CAR, CDR, or both of them. ... unresolved CAR reference until a CDR is applied. ... functionally expressed directly with simple machine code. ...
    (comp.lang.lisp)
  • Re: delete command weirdness
    ... A appears only in the car of the first cons). ... Now delete is forced to do some work, and makes the cdr of the first ... always just (setq testing (remove 'a testing)). ...
    (comp.lang.lisp)
  • Re: Code: drawing cons trees on ASCII devices
    ... (car x)) ... (cdr x)))) ... (cons (nothing) ... (cons (draw-row (car n)) ...
    (comp.lang.scheme)