lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Taj Khattra wrote:
> 
> On Sat, Dec 28, 2002 at 12:28:25AM +0100, Peter Prade wrote:
> >
> > very interesting indeed.
> >
> > i don't think i have seen this idea to implement a new datatype with
> > closures before.
> >
> 
> see http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.3
> 
> -taj

Cool! Here's pair functionality for lua, based on that text:

function cons(x,y) return function(m) return m(x,y) end; end;
function car(z) return z(function(p,q) return p; end) end;
function cdr(z) return z(function(p,q) return q; end) end;

> x = cons(1,2);
> print(car(x));
1
> print(cdr(x));
2


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be