I know that:
(cons [p] [q]) is ((s ((s i) (k [p]))) (k [q]))
(car [lst]) is ([lst] k)
(cdr [lst]) is ([lst] (k i))
I want to write a list like this
(cons [a] (cons [b] (cons [c] [nil])))
, which is going to be something like this:
((s ((s i) (k [a]))) (k ((s ((s i) (k [b]))) (k ((s ((s i) (k [c]))) (k [nil]))))))
But I don’t know how to compile ‘nil’ into S, K and I combinators. Does anyone know?
Thanks in advance,
Edwin Jose Palathinkal
The only thing you need from a
nilrepresentation is to be able to identify it — write somenull?predicate that returns “true” forniland “false” for all other pairs. This means that the answer depends on your representation of true/false. With the common choice ofλxy.xandλxy.y, a convenient encoding fornilisλf.[true]. Translating this to SKI is very easy now (and I won’t do it here, since it looks like homework…).(Also, implementing a
null?predicate given this representation fornilis a good exercise.)