[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: Python self-evaluating strings

Terry Reedy

1/27/2008 11:59:00 PM


"Arnaud Delobelle" <arnodel@googlemail.com> wrote in message
news:1BEEBF03-1A38-4745-B08B-DCA3106D1CC5@gmail.com...
| An earlier post today got me thinking about "quines" (programs that
| output themselves) in Python. I tried to find some on the web but
| didn't find many ([1]). In particular I didn't find any that
| corresponded to my instinctive (LISP-induced, probably) criterion:
....
| I'd like to know if anyone on the list has indulged in this time-
| bending/mind-wasting activity before. If so, it would be nice to
| create a list of such expressions.

Some years ago there was a substantial thread on this, (Shortest
Self-Reproducing Programs, or some such) including a fairly long one from
me that gave several 'shortest' (depending of definition and input method).
It included a Python tranlation of at least one standard Lisp version. I
presume you could find it on groups.google

Terry J. Reedy





3 Answers

Arnaud Delobelle

1/28/2008 12:17:00 AM

0

On Jan 27, 11:58 pm, "Terry Reedy" <tjre...@udel.edu> wrote:
> "Arnaud Delobelle" <arno...@googlemail.com> wrote in message

> Some years ago there was a substantial thread on this, (Shortest
> Self-Reproducing Programs, or some such) including a fairly long one from
> me that gave several 'shortest' (depending of definition and input method).
> It included a Python tranlation of at least one standard Lisp version.  I
> presume you could find it on groups.google

I found this:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/a1316cb4e216eba4/0cda739385abd03c?lnk=gst&q=Self-Reproducing+Program#0cda73...

It contains a lambda-solution similar to mine, only more concise:

(lambda x:x%`x`)('(lambda x:x%%`x`)(%s)')

I have been using python for 7 years, and it the first time ever that
I see the `...` construct being used! In fact I didn't even remember
that it existed (I'm not even sure that I've ever known about it...)

Thanks

--
Arnaud

Terry Reedy

1/29/2008 3:48:00 AM

0


"Arnaud Delobelle" <arnodel@googlemail.com> wrote in message
news:a04ca850-fe63-4b7e-abff-cdacab3bcc0f@i29g2000prf.googlegroups.com...
| I found this:
http://groups.google.com/group/comp.lang.python/browse_thread/thread/a1316cb4e216eba4/0cda739385abd03c?lnk=gst&q=Self-Reproducing+Program#0cda73...

Exactly the one I meant.

| It contains a lambda-solution similar to mine, only more concise:

| (lambda x:x%`x`)('(lambda x:x%%`x`)(%s)')

Being a Lisp novice, I was rather proud of that translation

| I have been using python for 7 years, and it the first time ever that
| I see the `...` construct being used!

It is going away in 3.0, so the above would need revision to work with
repr(), if indeed it will.

| Thanks

You're welcome

Terry



Arnaud Delobelle

1/29/2008 7:07:00 AM

0

On Jan 29, 3:48 am, "Terry Reedy" <tjre...@udel.edu> wrote:
> "Arnaud Delobelle" <arno...@googlemail.com> wrote in message
>
> news:a04ca850-fe63-4b7e-abff-cdacab3bcc0f@i29g2000prf.googlegroups.com...
> | I found this:http://groups.google.com/group/comp.lang.python/browse_thre......
>
> Exactly the one I meant.
>
> | It contains a lambda-solution similar to mine, only more concise:
>
> | (lambda x:x%`x`)('(lambda x:x%%`x`)(%s)')
>
> Being a Lisp novice, I was rather proud of that translation
>
> | I have been using python for 7 years, and it the first time ever that
> | I see the `...` construct being used!
>
> It is going away in 3.0, so the above would need revision to work with
> repr(), if indeed it will.

Here's the py3k-compliant version:

>>> k=(lambda x:x%repr(x))('(lambda x:x%%repr(x))(%s)')
>>> k == eval(k)
True

--
Arnaud