Hello all,
here is my first modest attempt at a JAPH. Please note the purely functional style (appart from the necessary side-effect of outputting something ;-) ).
Those who'll recognize the mechanism will probably have a smile in reminescence of that powerful and inefficient way of computing.
If there is some interest I will post an article on the theory behind this (unless it's been done here before).
Please enjoy, comments and suggestions would be greatly appreciated!
Schemer
#!/usr/bin/perl -w
use strict;
# author: guillaume[at]nulko.com
# functions
sub z { shift(); return shift(); }
sub u { return n(\&z); }
sub d { return n(n(\&z)); }
sub t { return lp(u)->(d); }
sub f { return um(d)->(d); }
sub c { return lp(t)->(d); }
sub a { return shift() + 1; }
sub w { return chr g(shift()) }
sub g { return shift()->(\&a, 0); }
sub p { print w(um(shift())->(u)); }
# functions building functions
sub lp { my $a = shift();
return sub { return $a->(\&n,shift()) } }
sub um { my $a = shift();
return sub { return $a->(lp(shift()),\&z) } }
sub n { my $a = shift();
return sub { my $b = shift();
return $b->($a->($b, shift())) } }
# Lambda, the ultimate...
$_='p(um(lp(u)->(um(um(t
)->(t))->(f)))->(d))
,p(um(um(lp(u)->(um(
t)->(f)))->(t))->(t)
),p(um(lp(u)->(um(lp
(u)->(um(d)->(c)))->
(d)))->(c)),p(um(lp(
u)->(um(lp(u)->(um(d
)->(t)))->(f)))->(f)
),p(um(um(d)->(f))->
(f)),p(lp(u)->(um(um
(um(d)->(t))->(f))->
(f))),p(um(um(lp(u)-
>(um(d)->(c)))->(d))
->(c)),p(um(lp(u)->(
um(um(t)->(t))->(f))
)->(t)),p(um(lp(u)->
(um(lp(u)->(um(d)->(
t))) ->(f))) ->(f)), p
(um(um(lp(u)->(um(t)->(f)
))->(d))->(f)),p(lp(u)->(um
(um(f)->(c))->(c))),p(um(um(l
p(u)->(um( um(d)->(t))->(t)))->
(d))->(t)) ,p(um(um(d)->(f))->(
f)),p(um(u m(f)->(f))->(c)),p(l
p(u)->(um( um(f)->(c))->(c))),p
(um(um(lp( u)->(um(um(d)->(t))-
>(t)))->(d ))->(t)),p(um(um(um(
t)->(t))-> (t))->(f)),p(um(um(d
)->(f))->( f)),p(um(um(lp(u)->(
um(t)->(f) ))->(d))->(f)),p(lp(
u)->(um(um (um(d)->(t))->(f))->
(f))),p(um (um(lp(u)->(um(d)->(
c)))->(t)) ->(t)),p(lp(u)->(um(
lp(u)->(um (lp(u)->(um(t)->(f))
)->(f)))-> (d))),p(lp(u)->(um(u
m(f)->(c)) ->(c))),p(um(um(lp(u
)->(um(um( d)->(t))->(t)))->(d)
)->(t)),p( um(lp(u)->(um(d)->(c
)))->(f)),p(um( d)->(c))',s/\s*//g,eval