Quine
this one is short but needs 7.5.4
a little bit longer but works on older versions too:
both return itself in a string (including line breaks)
or just evaluate this, which is the shorted possible, because in newLISP lambda expressions evaluate/return to themselves:
Lutz
Code: Select all
(define (make-me)
(source 'make-me))
Code: Select all
(define (printme )
(save "printme" 'printme)
(read-file "printme"))
or just evaluate this, which is the shorted possible, because in newLISP lambda expressions evaluate/return to themselves:
Code: Select all
(lambda (x))
Well guys, I do not completely agree with you here... ;-) Since when put in a file things go wrong.
According to Wikipedia, a Quine is this:
-------------------------------------------------------------------------
Now, the first example of Lutz is nice, but when put in a file "quine.lsp", and run with "newlisp quine.lsp", things go wrong:
This actually prints the lambda, but not the "println" statement below; also it will leave us in the newLisp prompt.
I suggest the following improvement:
Now the code will completely produce itself as it's only output, when put in a file. Any improvement on this code is appreciated... :-)
I tried to get things working with 'silent' but for some reason this did not generate the correct result. Is the 'silent' statement only working in interactive mode?
Peter
According to Wikipedia, a Quine is this:
Quoted from http://en.wikipedia.org/wiki/Quine. Opening the file and reading it's contents to print is considered cheating.A quine is a program (a form of metaprogram) that produces its complete source code as its only output.
-------------------------------------------------------------------------
Now, the first example of Lutz is nice, but when put in a file "quine.lsp", and run with "newlisp quine.lsp", things go wrong:
Code: Select all
(define (make-me)
(source 'make-me))
(println (make-me))
I suggest the following improvement:
Code: Select all
(define (make-me)
(println (source 'make-me))
(println "(println (make-me))")
(println "(exit)")
(println ""))
(println (make-me))
(exit)
I tried to get things working with 'silent' but for some reason this did not generate the correct result. Is the 'silent' statement only working in interactive mode?
Peter
same idea as Peter's but shorter:
Lutz
Code: Select all
(define (quine )
(println (source 'quine) "(quine)")
(exit))
(quine)
Last edited by Lutz on Fri May 06, 2005 11:57 pm, edited 2 times in total.
If this is a quine:
Then here is a little bit shorter one:
Let's get rid of the pair of parentheses (but we still need the space)
And here is another one:
And finally:
But still this is not the shortest quine. The shortest one is the empty program. If you run it you will get on the screen the exact source of the program. Here it is the quinnest quine:
Code: Select all
(lambda (x))
Code: Select all
(lambda ())
Code: Select all
(lambda )
Code: Select all
nil
Code: Select all
0
Code: Select all
Nice thoughts but disqualified as can be read here: http://en.wikipedia.org/wiki/Quine_%28computing%29
In the end, the question is: how do we define a program? Can a single number like '0' be called a program?
Peter
Also, a quine that contains no code is ruled out as trivial; in many programming languages executing such a program will output the code (i.e. nothing). Such an empty program once won the "worst abuse of the rules" prize in the Obfuscated C contest.
In the end, the question is: how do we define a program? Can a single number like '0' be called a program?
Peter
May be in some machine code for some processor there is an instruction with opcode 0. So, this might be a kind of minimalistic program.pjot wrote:Can a single number like '0' be called a program?
For example, in 80x86 family the number 144 (i.e. 0x90) stands for NOP instruction, which is a program by itself. So, a single number could be a program.
The functionality of NOP is not the point. There are many others 1-byte instructions, e.g. RET (return from procedure). A single RET is the shortest subroutine.
In some languages there are formal definitions of programs. For example in Pascal there is a program reserved word. In Lisp and Logo (and machine code) the boundary between data and instructions is pretty vague, so I believe that there is a smooth transition between programs and data.
The situation is similar to that -- take the rainbow (spectrum) and ask people to point the beginning and the end of the yellow color. Everyone will show something different.
Let's go back to the quine problem. I think that a fair (i.e. classical) quine program should have at least one instruction for output and no instructions for input. Cases like empty program, 0, (lambda (x)) are ruled out, because they do not print anything, but rely on the programming environment to show the result (i.e. the P in the REPL acronym).
In some languages there are formal definitions of programs. For example in Pascal there is a program reserved word. In Lisp and Logo (and machine code) the boundary between data and instructions is pretty vague, so I believe that there is a smooth transition between programs and data.
The situation is similar to that -- take the rainbow (spectrum) and ask people to point the beginning and the end of the yellow color. Everyone will show something different.
Let's go back to the quine problem. I think that a fair (i.e. classical) quine program should have at least one instruction for output and no instructions for input. Cases like empty program, 0, (lambda (x)) are ruled out, because they do not print anything, but rely on the programming environment to show the result (i.e. the P in the REPL acronym).