Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

comment on

( #3333=superdoc: 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

In reply to (Almost) Purely Functional JAPH by Schemer

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2021-05-17 01:05 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (152 votes). Check out past polls.