Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

(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!

#!/usr/bin/perl -w use strict; # author: guillaume[at] # 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

Replies are listed 'Best First'.
Re: (Almost) Purely Functional JAPH
by Aristotle (Chancellor) on Nov 21, 2003 at 15:25 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://307223]
Approved by grinder
Front-paged by broquaint
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-02-22 15:56 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (331 votes). Check out past polls.