What would be the proper way to define the cons
, car
, and cdr
functions if we were to use javascript and functional programming? So far I have:
// CAR = λxy.x
// CDR = λxy.y
// CONS = λxy => ?
const car = a => b => a;
const cdr = a => b => b;
const cons = f => a => b;
let pair = cons(3)(4);
console.log(pair(car));
console.log(pair(cdr));
But my issue is pair(car)
seems like an odd way to invoke the function. It seems like car(pair)
seems like a better way but I’m not sure how to save the pair so it can be passed like that. How would that be done?