Re: [閒聊] quine

看板Ruby作者 (godfat 真常)時間17年前 (2007/02/19 00:03), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/2 (看更多)
※ 引述《godfat (godfat 真常)》之銘言: : 日前翻了翻這裡 : http://www.nyx.net/~gthompso/quine.htm : 印出自己的程式 : 把裡面的 C 程式改寫成 Ruby, 就變成 : s='s=%c%s%c : printf s, 39, s, 39' : printf s, 39, s, 39 : 好像沒什麼意義 : 翻了一下 wikipedia : http://en.wikipedia.org/wiki/Quine_(computing) : or : http://en.wikipedia.org/wiki/Quine_%28computing%29 : 看到 JavaScript 可以這樣做 : function a() { document.write (a + "\na();"); } : a(); : 忽然想到之前聽到的 Ruby2Ruby : 是否可以靠那東西達到類似的手法…? : 改天來試試看,Ruby2Ruby 能玩哪些花枝(誤) 花枝來了,烏賊走了 稍微試了一下 Ruby2Ruby #!/usr/bin/ruby require 'rubygems' require 'ruby2ruby' (a = proc { puts("#!/usr/bin/ruby") puts puts("require 'rubygems'") puts("require 'ruby2ruby'") puts print("(a = ") print(a.to_ruby) print(").call") }).call 缺點是我一定得這樣排版,因為 to_ruby 出來的排版就是這樣 空格用兩格,括號不能省略,字串用 "" 夾起來 (但如果他記下我的排版,那才真的可怕了…) 有 Ruby2Ruby 應該可以做很多很好玩的事 不過他內部程式居然用到 RubyInline, 第一次執行時會先呼叫 GCC 做出 .so 檔... 也許可以藉此相信他的執行效率有一定的程度 -- #!/usr/bin/ruby [露比] /Programming (Kn|N)ight/ 看板《Ruby》 # if a dog nailed extra legs that http://www.ptt.cc/bbs/Ruby/index.html # walks like an octopus, and Welcome ~Ruby@ptt~ # talks like an octopus, then ◢█◣ http://www.ruby-lang.org/ # we are happy to treat it as http://www.ruby-doc.org/ # if it were an octopus. http://www.rubyforge.org/ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.135.28.18
文章代碼(AID): #15s7ZR0o (Ruby)
討論串 (同標題文章)
本文引述了以下文章的的內容:
閒聊
2
3
完整討論串 (本文為第 2 之 2 篇):
閒聊
2
3
文章代碼(AID): #15s7ZR0o (Ruby)