I'd like to know what this code means in Scheme:
(define ((K x) y) x)
(define (((S x) y) z)
((x z) (y z)))
The whole file is here.
Is this legal Scheme? Is (K x) a parametrized function, something like generic functions in Java? I looked up the MIT Scheme reference, there seems to be nothing mentioned for definition of this kind.
Trying it in MIT Scheme works
Apparently, these are the definitions for
K
andS
combinators from a combinatorial logic SKI calculus.We can define the same function explicitly,
Apparently, MIT-Scheme does that for us, just as in case of regular definitions like
(define (fun foo) bar)
being translated to(define fun (lambda (foo) bar))
.The
S
combinator would be defined explicitly asThis is how currying languages (like e.g. Haskell) work, where every function is a function of one argument. Haskell is very close to the combinatorial logic in that respect, there's no parentheses used at all, and we can write the same definitions simply as
So that
_S (+) (1+) 3
produces7
.