464,788 Members | 1,408 Online
Need help? Post your question and get tips & solutions from a community of 464,788 IT Pros & Developers. It's quick & easy.

Not entirely serious: recursive lambda?

 P: n/a I came across the "japh" concept today and decided to do one of my own, obviously, interpreting the 'p' somewhat loosely, http://en.wikipedia.org/wiki/JAPH but I'm not entirely satisfied with it: #### # japh, for certain values of 'p' f=lambda(r,N):N and f((" acdefijlmnopqrstuv"[N%19]+r,N/19))or(r,N) print f( ("",reduce(lambda c,m:c*95+''.join(map(chr,range(32,127))).index(m), "!b)'1Mgh0z+fYQ]g::i^<&y~g)cnE-d=K&{GMNQ1gx+ooY<~L##N'X]P2<@XYXwX3z", 0)))[0] #### it bothers me that there are two statements. (In case you are wondering what they do, it's all essentially about changing from base 95 to base 19. It's based loosely on this fine, simple recipe by Drew Perttula which I have found to be useful on several occasions: http://aspn.activestate.com/ASPN/Coo.../Recipe/111286 ) Anyway, I'd much prefer an even uglier japh like this: # does not work print (lambda(r,N):N and \$\$\$\$((" acdefijlmnopqrstuv"[N%19]+r,N/ 19))or(r,N))( ("",reduce(lambda c,m:c*95+''.join(map(chr,range(32,127))).index(m), "!b)'1Mgh0z+fYQ]g::i^<&y~g)cnE-d=K&{GMNQ1gx+ooY<~L##N'X]P2<@XYXwX3z", 0)))[0] but what would \$\$\$\$ be for an unnamed function to call itself? I realize that lambda is something of an orphan and was arguably a bad idea for anything besides obfuscation, but obfuscation is exactly my purpose here. Can a lambda call itself without giving itself a name? Google was not my friend on this one, and I suspect there is no answer. Relax, I am not going to submit a PEP about it. mt Jul 20 '08 #1
8 Replies

 P: n/a On Sat, Jul 19, 2008 at 10:43 PM, Michael Tobis

 P: n/a On Jul 19, 11:49*pm, Miles

 P: n/a On 20 Jul., 04:43, Michael Tobis

 P: n/a Kay Schluehr: Sure, use a fixed point combinator. I've just added this recipe: http://aspn.activestate.com/ASPN/Coo.../Recipe/576366 Does it work? Bye, bearophile Jul 20 '08 #5

 P: n/a On 20 Jul., 13:08, bearophileH...@lycos.com wrote: Kay Schluehr: Sure, use a fixed point combinator. I've just added this recipe: http://aspn.activestate.com/ASPN/Coo.../Recipe/576366 Does it work? Bye, bearophile There are lots of informal derivations of the Y combinator on the web. I used one a while ago and translated the result into Python. So if there isn't an implementation bug it shall work. I added two examples for illustration purposes. Jul 20 '08 #6

 P: n/a Michael Tobis wrote: I realize that lambda is something of an orphan and was arguably a bad idea for anything besides obfuscation, but obfuscation is exactly my purpose here. Can a lambda call itself without giving itself a name? Google was not my friend on this one, and I suspect there is no answer. Relax, I am not going to submit a PEP about it. gerson kurz' writings on lambdaization might be helpful (or not): http://www.p-nand-q.com/python/lambd...quicksort.html http://www.p-nand-q.com/python/stupi...da_tricks.html Jul 20 '08 #7

 P: n/a Thanks all! What a remarkable set of answers, intelligent, thought provoking and informative without exception. Of course, now I can't use Paul's version; it hardly counts as a japh if someone else wrote it! It is probably the closest to my original vision, alas. Miles' second suggestion was the one I was fumbling toward; I will study it. No spoilers please. best mt Jul 22 '08 #8

 P: n/a On Jul 22, 11:52*am, Michael Tobis