Talk:Quine: Difference between revisions

1,203 bytes added ,  15 years ago
a C (cheating?) quine imitating forth in a compiled fashion but runtime output produces a real quine...
(a C (cheating?) quine imitating forth in a compiled fashion but runtime output produces a real quine...)
Line 30:
:: No, I haven't written the code (as far as I remember I have not contributed to any forth code yet; surely not to quine anyway), or I would have said that here. I simply said that noone can claim a copyright on such a small piece of code, except maybe the creator of the forth language. The code simply says "get the buffer where the source text is, and print it"; provided that a language has a primitive to "print" and one to get such information, everyone able to read a manual can, '''without copying''', produce this quine. If it is not stack based, one could say something like "printf("%s", get_source());" (interpreted C?)... Anyway, if it is an issue, one could try to contact Neal Bridges ([http://www.complang.tuwien.ac.at/forth/quine-complex.fs named here]), maybe he wrote it (or know who can have written it), altogether with more complex quine(s) (and these can't be copied without thinking about a lincense, since hardly one can reproduce them only reading the forth manual...); it appears [http://www.nyx.net/~gthompso/self_forth.txt here also] (author unknown! and cheating suspect...).
:: Someone wrote it, maybe after forth manual reading, or maybe taking a look on the net... and IanOsgood added just the link to a list of forth quines, among these there's also "ours". I think there are not license violation (I imagine RC must care a lot about these ''details''), but I am not a lawyer (rather in this case I would like to be a lawyer-eater) --[[User:ShinTakezou|ShinTakezou]] 00:12, 31 March 2009 (UTC)
::: Third thought, I think the guy suspecting it's almost cheating, after all, it's right; I've created the following C cheated-quine:
 
<lang c>#include "cheater.h"
int main()
{
printf("%s", __source__);
}</lang>
 
:::Which works (with gcc statement expression extension) provided that cheater.h is
 
<lang c>#include <stdio.h>
#define __source__ ({ \
char *s = "#include \"cheater.h\"\n\
int main()\n\
{\n\
printf(\"%s\", __source__);\n\
}\n"; s;\
})</lang>
 
::: From a "functional" point of view, this works the same way of forth (and maybe others), by accessing the text of the source stored in memory (not by loading it at runtime...); since C is compiled, the binary holds no the source (compiler at least once loaded the source in memory, but compiled binary can't see its past...), and I had to include it manually... (Hm, one could work harder on debug informations and ELF maybe, and write a more forth-like quine accessing at runtime the "segment" where the whole source code, stored by the compiler itself this time, is and print it...)... Is this a honest quine or really cheating? (Interesting question to me:D) --[[User:ShinTakezou|ShinTakezou]] 00:54, 31 March 2009 (UTC)