Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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

Replies are listed 'Best First'.
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?
[1nickt]: Now that one made me hopeful! First time not angry in a long time when I saw that kid.
[Discipulus]: i propend for removing: why? because we are so few that we must find i minimal common divisor, this is certainly Perl not our (anyway private) thougths. And i say this still wondering because i love a lot freedom of expression. And i say this not for roho
[1nickt]: Discipulus that was the point of my story of taking the sticker off my truck. I know there are lots of people in the world who if I knw their private beliefs I might want to argue with them. And they with me. But life cannot all be arguments!
[1nickt]: This is less than perfect ... but demanding perfection (from people or from life) is a sure way to unhappiness.
[Discipulus]: and anyway we have CB where every (democratic) opinion can be expressed
erix eat the rich!
[1nickt]: I do think it is sad that roho has received 3 downvotes for his polite request, as did I when I objected to the profanity in stonecolddevin's sig. I upvoted both him and Karl for the discussion. Way too much downvoting for inappropriate reasons here!
Discipulus learn that 'argue' has a little negative sense, he thought was a neutral sense, 'vox media'
[1nickt]: argue == discuss && argue == be contentious
[Discipulus]: you are right 1nickt i didnt voted nor downvoted; I just upvote perl content i like

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2017-06-22 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (519 votes). Check out past polls.