nxy

1

n

2

2

3

n

1

3xy

3xy

3yz

3zx

3yz

3yz

3zx

3xy



q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show c ++ [','] ++ show a ++ [')']

main=q "q a b c=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"



Suppose Fis a program, written in language x, that takes as input n string arguments as input, G,...,Gand outputs a program in language y that is the application of the function whose source code is Gto the strings G,G,...,G,G. Then F(F,F,F) will be a program in language x that that outputs a program in y that computes F(F,F,F).We can put this into practice:This is a Haskell program that outputs a Python program that outputs a Ruby program that outputs the original Haskell program.Apologies for the lack of line breaks. If it's not readable, it should be possible to copy and paste that source. Also, you may need to tweak it if your OS doesn't treat character 10 as a new line.

Labels: haskell, programming, self-reference