1) Efficient implementation, but doesn’t allow for improper lists:
['a', 'b', 'c']
car = function(xs) { return xs[0]; }
cdr = function(xs) { return xs.slice(1); }
2) Less efficient, but full control over the cons pair:
['a', ['b', ['c', null]]
car = function(xs) { return xs[0]; }
cdr = function(xs) { return xs[1]; }
3) Similar to 2 – not sure what the advantages are, if any:
{car: ‘a’, cdr: {car: ‘b’, cdr: {car: ‘c’, cdr: null}}}
car = function(xs) { return xs.car; }
cdr = function(xs) { return xs.cdr; }
No comments yet.