2009-08-28 54 views
5

這裏是一個特殊的Haskell程序,其輸出輸出Ruby程序,其輸出原始的Haskell程序(從http://blog.sigfpe.com/2008/02/third-order-quine-in-three-languages.html關於構建更高階Quine程序的任何想法?

爲了更精確地Python程序,輸出是這個Haskell的程序的

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" 

是Python程序,

$ runhaskell test.hs 
def q(a,b,c):print b+chr(10)+'q('+repr(b)+','+repr(c)+','+repr(a)+')' 
q("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","q a b c=putStrLn $ b ++ [toEnum 10,'q','('] ++ show b ++ [','] ++ show C++ [','] ++ show a ++ [')']") 

其運行後輸出一個Ruby程序,

$ runhaskell test.hs | python 
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 
q("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","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)+')'") 

最後,Ruby程序打印出原始的Haskell程序。

$ runhaskell test.hs | python | ruby 
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" 

由於傳統喹程序可以通過在兩個部分,其中A部分包含B部分的描述和B部分計算出從該描述中分離的程序來構建。

但這樣的三階奎寧是如何構造的?

+0

http://www.reddit.com/r/programming/comments/9ot8y/quinerelay_with_11_programming_languages/ – sdcvvc 2009-09-30 09:30:00

回答

2

首先,圍繞this programming assignment圍繞你的頭。相信我,一旦你花了一些時間,其實並不難。這個想法是,你可以編寫一個程序,將另一個程序作爲輸入,並將第三個程序作爲輸出結合這兩個程序並理解其自己的文本。這是一種更高級的奎因。如果你理解了所有三種編程語言的結構,你可以從這個任務中得出想法並進一步擴展它們。

2

Kleene's recursion theorem理論上可以用幾乎任何語言構造奎因。 (More information here.)雖然我自己迄今還沒有設法讓它工作。

對於高階quine,要考慮的功能是語言評估機制的組成。如果你能從KRT中獲得一個基本的奎因,也許你可以去爭取更高的秩序。

1

在該文的第一段中,我寫了一個簡短的解釋。我建議從那裏開始。

我從Barwise和Moss的「Vicious Circles」一書中學到了其中的一些技巧。 (!

0

我不是一個程序員,但聽起來像這樣對我說:

... - >ç - > A - >乙 - > C-> A-> B - > C^- > ...

一個(三角形)圈惡性的,沒有真正的開始或結束。 cointain B的描述

程序A含有C.

節目B的cointain℃的描述的描述包含A的描述

方案C cointain A,其的描述包含B的描述。

大概越來越深,你可以用許多不同的語言在圈子上獲得更多的角落。

相關問題