[pyar] OT: Programa poliglota (habla python).

Kragen Javier Sitaker kragen en canonical.org
Lun Jun 14 00:19:23 ART 2010


Traducción castellana, para no ser maleducado, aúnque ya sé que casi
todo el mundo acá ya sabe leer inglés.

Correcciones para mi terminología sean bienvenidas. También
modificaciónes para agregar más lenguajes.

On Sun, Jun 13, 2010 at 11:00:45PM -0300, Sebastian Bassi wrote:
> This program parses and runs successfully in Lua, Ruby, or
> Python. It’s the first polyglot program I’ve seen that includes
> Lua. Is it possible to add more languages to it?

Este programa parsea y corre con éxito en Lua, Ruby, o Python. Es la
primera programa políglota que conozco que incluye Lua. Es posible
agregarle más lenguajes?

> Here's a less minimal version with comments:

Una versión menos mínimo sigue, con comentarios.

> # A polyglot program that runs in either Python or Lua.

Un programa políglota que corre en Python o Lua.

> x = 1 or 1 -- """ Begin a Python/Ruby multiline string inside a Lua comment.

Empiece un string de varias lineas del sintaxis Python/Ruby adentro de
un comentario de Lua.

> -- In Python or Ruby, the expression parses as 1 or (1 - (- 'some string')).

En Python o Ruby, la expresión se parse como "1 or (1 - (- 'algún string')).

> -- As it happens, strings don't have an unary minus operator defined for them,
> -- and if they did, its result probably couldn't be subtracted from 1.

Resulta que los strings no tienen un operador menos unario definido para
ellos, y si hubiera tenido dicho operador, su resultado probablemente no
pudiera subtraerse de 1.

> -- But that would only matter if the second half of the 'or' expression
> -- were to be evaluated. And it's not.

Pero ésto sólo importaría si el segundo mitad de la expresion "or"
hubiera sido evaluado. Y no lo es.

> -- The 'x =' part is to make the expression '1 or 1' into a statement
> -- in Lua, which doesn't have expression statements.

La parte 'x =' es para convertir la expresión '1 or 1' en un statement
en Lua, que no tiene statements de sólo una expresión.

> -- See http://codegambler.wordpress.com/2009/10/04/polyglotsingle-program-runs-on-multiple-languages/
> -- and http://osdc.tw/2010/02/schedule_polyglot_programming.html
> -- and http://www.nyx.net/~gthompso/poly/polyglot.htm
> -- for techniques that might permit adding some other languages.

Ver (urls) para técnicas que puedan permitir agregar algunos otros
lenguajes.

> print('hello, world, from Lua!')
> x = [[ " # end the Ruby (but not the Python) multiline string inside a
> Lua multiline string.

Terminar el string de varias lineas de Ruby (pero no lo de Python)
adentro de un string de varias lineas de Lua.

> # Now, until we do it again, Python and Ruby are out of phase.

Hasta que lo hacemos otra vez, Python y Ruby están desincronizados.

> # Thanks to http://www.riffraff.info/2009/1/16/life-polyglot-ruby-python for the technique!

Gracias a <URL> por la técnica!

> puts 'hello, world, from Ruby!'
> """
> print 'hello, world, from Python!'
> #"#]] -- end the Ruby multiline string inside a Python comment and the Lua multiline string inside a Python/Ruby comment.

Termina el string de varias líneas de Ruby adentro de un comentario de
Python y el string de varias líneas de Lua adentro de un comentario de
Python y Ruby.

> Like everything else posted to kragen-hacks without a notice to the
> contrary, this software is in the public domain.

Cómo cualquiera otra cosa mandado a kragen-hacks sin noticia al
contrario, este software está en el dominio público.



More information about the pyar mailing list