Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

(Almost) Purely Functional JAPH

by Schemer (Scribe)
on Nov 14, 2003 at 21:41 UTC ( #307223=obfuscated: print w/ replies, xml ) Need Help??

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

Comment on (Almost) Purely Functional JAPH
Download Code
Re: (Almost) Purely Functional JAPH
by Aristotle (Chancellor) on Nov 21, 2003 at 15:25 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://307223]
Approved by grinder
Front-paged by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (10)
As of 2014-09-18 21:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (124 votes), past polls