Constructing quines (self-reproducing functions)

前端 未结 5 1505
走了就别回头了
走了就别回头了 2021-02-19 03:47

Has anyone constructed a quine (\"A program that generates a copy of its own source text as its complete output\": http://www.nyx.net/~gthompso/quine.htm) in R? (The [quine] ta

5条回答
  •  爱一瞬间的悲伤
    2021-02-19 04:28

    If you want a function that returns a function.....maybe this?

    junk <- function(...) {
      function(...) {
        structure(junk(...))
      }
    }
    

    The output is:

    > junk()
    
    function(...) {
        structure(junk(...))
      }
    
    
    
    > boo <- junk(999)
    > boo
    
    function(...) {
        structure(junk(...))
      }
    
    
    
    >dput(boo)
    
    function (...) 
    {
        structure(junk(...))
    }
    

提交回复
热议问题