📜 ⬆️ ⬇️

On the issue of introspective programs

Introspective is a program that feeds its source code to an output. But I came across a more interesting option: a Haskell program that displays a Python program that displays a Ruby program that displays a source Haskell program .

Unfortunately, the design “flows” a bit, but it is necessary:
 qabc = putStrLn $ b ++ [toEnum 10, 'q', '('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [') ']
 main = q "qabc = putStrLn $ b ++ [toEnum 10, 'q', '('] ++ show b ++ [','] ++ show c ++ [','] ++ show a + + [')'] "" def q (a, b, c): print b + chr (10) + 'q (' + repr (b) + ',' + repr (c) + ',' + repr (a) + ')' "" def e (x) return 34.chr + x + 34.chr end; def q (a, b, c) print b + 10.chr + 'main = q' + e (b ) + '' + e (c) + '' + e (a) + '' + 10.chr end "

Accordingly, we obtain the following chain: 1 -> 2 -> 3 -> 1, and the program eventually displays its source text :)
Of course, this piece of code reached me through the chain, too:

')

Source: https://habr.com/ru/post/19875/


All Articles