Programs that print their own source code

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Programs that print their own source code

Postby PM 2Ring » Sat Feb 07, 2009 5:09 pm UTC

It can be a fun exercise to write a program that prints its own source code. It gets you thinking about the language syntax in ways that are a bit different to the usual programming problems. I couldn't find a thread on this topic here, so I thought it might be a nice idea to create one where we can put examples in all the different languages we are familiar with.

Try to avoid using fancy library functions as much as possible.

To get the ball rolling, here's one in Python.

Code: Select all

#! /usr/bin/env python

s='#! /usr/bin/env python\n\ns=%s\nprint s%%repr(s)'
print s%repr(s)

And a one line version that runs in the interpreter.

Code: Select all

s='>>> s=%s;print s%%repr(s)';print s%repr(s)

If you think using the repr() function is cheating, feel free to post an alternative.

I'll post one or two in PostScript a bit later. I've got one in C here (written by someone else) that is also a palindrome!

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Programs that print their own source code

Postby Xanthir » Sat Feb 07, 2009 5:19 pm UTC

You're looking for the term 'quine'. There are a bunch of them out there. ^_^
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Programs that print their own source code

Postby PM 2Ring » Sat Feb 07, 2009 5:33 pm UTC

Xanthir wrote:You're looking for the term 'quine'. There are a bunch of them out there. ^_^


"To quine a phrase", to quine a phrase. :) I was introduced to W. V. O. Quine via Godel, Escher, Bach, which I recently started re-reading. But I didn't realize the term "quine" has become common jargon for programs like this.

So has this topic already been done here? If so, I certainly don't mind if the moderators merge or kill this thread.

I realize that there are many such self-reproducing programs scattered around the Net, but it'd be nice to have a bunch of them in one place. And it could be a fun game, especially for those who haven't tried it before.

Lightnix
Posts: 4
Joined: Tue Feb 03, 2009 6:54 pm UTC

Re: Programs that print their own source code

Postby Lightnix » Sat Feb 07, 2009 7:55 pm UTC

Simple one in PHP:

Code: Select all

<?
$file = "quine.php";
$fh = fopen($file, 'r');
$data = fread($fh, filesize($file));
$data = htmlspecialchars($data);
fclose($fh);
echo 'Source: ' . $data;
?>


It could be improved by: adding new lines (<br />) in comments and just parsing the php start and end tags out - though that would be removing some of the source code from the output making the quine incomplete. It could also be improved by parsing the URL to find out what its file name is rather than having it hardcoded in.

But I'm too lazy for that. :D

HenryGifford
Posts: 152
Joined: Mon Nov 03, 2008 2:01 am UTC

Re: Programs that print their own source code

Postby HenryGifford » Sat Feb 07, 2009 8:28 pm UTC

Yeah in Python I did:

Code: Select all

quine=open("quine.py")
quine=quine.read()
print quine

User avatar
Why Two Kay
Posts: 266
Joined: Sun Mar 23, 2008 6:25 pm UTC
Location: Plano, TX
Contact:

Re: Programs that print their own source code

Postby Why Two Kay » Sat Feb 07, 2009 8:43 pm UTC

I'm pretty sure a restriction on quines is that they are not supposed to use files.
tl;dr - I said nothing important.

Ended
Posts: 1459
Joined: Fri Apr 20, 2007 3:27 pm UTC
Location: The Tower of Flints. (Also known as: England.)

Re: Programs that print their own source code

Postby Ended » Sat Feb 07, 2009 8:46 pm UTC

...I don't think reading in and printing the source file is quite in the spirit of the challenge. (Although I don't think I can do any better :) )
[Edit: ninja'd]

For extra difficulty, try iterating quines:

Source file A is in language X.
When A compiled and run, it outputs source file B in language Y.
When B is compiled and run, it outputs A.
Generally I try to make myself do things I instinctively avoid, in case they are awesome.
-dubsola

User avatar
jaap
Posts: 2094
Joined: Fri Jul 06, 2007 7:06 am UTC
Contact:

Re: Programs that print their own source code

Postby jaap » Sat Feb 07, 2009 9:58 pm UTC

Xanthir wrote:You're looking for the term 'quine'. There are a bunch of them out there. ^_^


Such as in this thread in the computer science forum.

User avatar
hotaru
Posts: 1045
Joined: Fri Apr 13, 2007 6:54 pm UTC

Re: Programs that print their own source code

Postby hotaru » Sat Feb 07, 2009 10:42 pm UTC

is this cheating?

Code: Select all

[ " dup pprint call" print ] dup pprint call

Code: Select all

factorial product enumFromTo 1
isPrime n 
factorial (1) `mod== 1

User avatar
sparkyb
Posts: 1091
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville proper!
Contact:

Re: Programs that print their own source code

Postby sparkyb » Sun Feb 08, 2009 4:43 am UTC

In college I had a class where we had to do something similar to this. They couldn't make it this easy though. Instead it worked as follows. Given a function that takes a string as input and produces some output, write a program that when run produces as output the same thing that the given function would produce if the source code to this program were passed to it as the input string (the normal quine would be the trivial case of this where the function just directly prints its input). Actually, the assignment was write a program than given as input the source code to a function as described above generates a program as described above to match that particular function. The way it was described was that if you call the function that takes the program as input "eat" and if you call the program "self" then self()==eat(self), roughly speaking. And the meta program that we were supposed to write that given some "eat" function generates the matching "self" program was called an autocannibalizer. Anyone else need an asprin now?

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Programs that print their own source code

Postby PM 2Ring » Sun Feb 08, 2009 4:59 am UTC

Ended wrote:...I don't think reading in and printing the source file is quite in the spirit of the challenge.

Indeed.

jaap wrote:
Xanthir wrote:You're looking for the term 'quine'. There are a bunch of them out there. ^_^


Such as in this thread in the computer science forum.

Thanks, guys.

User avatar
evilbeanfiend
Posts: 2650
Joined: Tue Mar 13, 2007 7:05 am UTC
Location: the old world

Re: Programs that print their own source code

Postby evilbeanfiend » Sun Feb 08, 2009 11:38 am UTC

Why Two Kay wrote:I'm pretty sure a restriction on quines is that they are not supposed to use files.


yes reading your source code from file is usually forbidden as its trivial in any language which allows it (so all useful ones). also empty programs are usually disallowed as these are also trivially quines in some languages e.g.

in TCL

Code: Select all

 
in ur beanz makin u eveel

HenryGifford
Posts: 152
Joined: Mon Nov 03, 2008 2:01 am UTC

Re: Programs that print their own source code

Postby HenryGifford » Sun Feb 08, 2009 5:23 pm UTC

Why Two Kay wrote:I'm pretty sure a restriction on quines is that they are not supposed to use files.

Ah bummer.

Filius Nullius
Posts: 72
Joined: Sat Apr 05, 2008 12:24 am UTC

Re: Programs that print their own source code

Postby Filius Nullius » Sun Feb 08, 2009 9:17 pm UTC

Code: Select all

#include <stdio.h>
char *program = "#include <stdio.h>%cchar *program = %c%s%c;%cint main()%c{%c
printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);%c    return 0;%c}%c";
int main()
{
        printf(program, 10, 34, program, 34, 10, 10, 10, 10, 10, 10);
        return 0;
}



I think the above is a standard solution to the problem of a program printing it's own source, this isn't my solution but I don't remember where I found it.

Notch
Posts: 318
Joined: Tue Dec 12, 2006 5:52 pm UTC
Location: Stockholm, Sweden
Contact:

Re: Programs that print their own source code

Postby Notch » Mon Feb 09, 2009 12:51 pm UTC

Ended wrote:For extra difficulty, try iterating quines:


I once wrote a java program that, when run, spits out the source code for a brainfuck program that, when run, spits out the source code for the original java program. :D

Main
Posts: 11
Joined: Mon Nov 26, 2007 7:27 am UTC

Re: Programs that print their own source code

Postby Main » Mon Feb 09, 2009 1:33 pm UTC

Here's some in Lisp. Being lisp code, they're more expressions that return their own source than programs that print it, but the idea is the same. Besides, "program" in lisp isn't well-defined.

Code: Select all

((lambda (x) (list x x)) (lambda (x) (list x x)))
I think this is valid Scheme. I like this one, it's very elegant.

Code: Select all

(let ((let '`(let ((let ',let)) ,let))) `(let ((let ',let)) ,let))
This one is in Common Lisp.

I think for Common Lisp, using #n# and #n= is probably cheating. Using '- is definitely cheating; (symbol-value '-) is the value of the expression currently being evaluated, so it makes quines really easy.

If anyone's got any more lisp quines, I'd like to see them.
Last edited by Main on Mon Feb 09, 2009 2:41 pm UTC, edited 2 times in total.

Code: Select all

(format t "~&~9,'0,V,3:B" #\Newline 143)

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Programs that print their own source code

Postby Berengal » Mon Feb 09, 2009 1:46 pm UTC

Probably doesn't count as a proper quine, but in prolog 'Quine = quine.' will produce "Quine = quine." in the interpreter. (Depending on which interpreter you're using it may also print "Yes" or "true" or something to that effect. It doesn't in mine).

I once wrote a python function that would redefine itself each time it was run, producing different results. It was something as simple as 'def foo(): global foo; s = "<foo source>"; <modify s>; foo = eval(s)' but with some additional effects thrown in.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
Cosmologicon
Posts: 1806
Joined: Sat Nov 25, 2006 9:47 am UTC
Location: Cambridge MA USA
Contact:

Re: Programs that print their own source code

Postby Cosmologicon » Mon Feb 09, 2009 2:20 pm UTC


Main
Posts: 11
Joined: Mon Nov 26, 2007 7:27 am UTC

Re: Programs that print their own source code

Postby Main » Mon Feb 09, 2009 2:40 pm UTC

There was a link in the other thread to a page full of them:
http://www.nyx.net/~gthompso/quine.htm
They're in various languages. Here's some of the more interesting common lisp ones:

Code: Select all

#1=(WRITE '#1# :CIRCLE T)
#1=(SETQ *PRINT-CIRCLE* '#1#)

#1='#1# ; Only if *print-circle* is already non-nil
These all use circular-object syntax.

This one's technically common lisp, but it's really written in FORMAT:
(format t "~@?" "(format t \"~~@?\" ~:*~S)")
Like the WRITE one above, it prints it's source.

Code: Select all

(format t "~&~9,'0,V,3:B" #\Newline 143)

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Programs that print their own source code

Postby PM 2Ring » Sun Feb 15, 2009 9:05 am UTC

PM 2Ring wrote:I'll post one or two in PostScript a bit later. I've got one in C here (written by someone else) that is also a palindrome!


A PostScript program which outputs itself to the console:

Code: Select all

/s
(
[(/s)<28>s<29>(def)s]{=}forall
)
def
[(/s)<28>s<29>(def)s]{=}forall


And this PostScript one prints itself to the output device:

Code: Select all

/Times-Roman findfont 9 scalefont setfont 9 700 moveto
/s
(
[(/Times-Roman findfont 9 scalefont setfont 9 700 moveto)(/s)<28>s<29>(def)s]{gsave show grestore 0 -20 rmoveto}forall showpage
)
def
[(/Times-Roman findfont 9 scalefont setfont 9 700 moveto)(/s)<28>s<29>(def)s]{gsave show grestore 0 -9 rmoveto}forall showpage


Here's the palindrome in C, written by Thad Smith. Note: this is all on one line.

Code: Select all

/**/char q='"',*a="*//**/char q='%c',*a=%c%s%c*/};)b(stup;]d[b=]d-472[b)--d(elihw;)q,a,q,q,2+a,b(ftnirps;)b(stup{)(niam;731=d tni;]572[b,",b[275];int d=137;main(){puts(b);sprintf(b,a+2,q,q,a,q);while(d--)b[274-d]=b[d];puts(b);}/*c%s%c%=a*,'c%'=q rahc/**//*"=a*,'"'=q rahc/**/

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Programs that print their own source code

Postby Random832 » Mon Feb 16, 2009 7:55 pm UTC

Code: Select all

#!/bin/cat
Any text so it's not a blank file.


And, just to provide an entry that isn't cheating - a cheap trick is to provide a copy of most of the source code as a string literal, and then use that in the output along with code to convert it to a string literal for the bit where you put the strings.

Code: Select all

public class Hello1{static string[] s={"public class Hello1{stati
c string[] s={","};public static void Main(){System.Console.Write
Line(s[0]+\"\\\"\"+s[0].Replace(\"\\\\\",\"\\\\\\\\\").Replace(\"
\\\\\",\"\\\\\\\"\")+\"\\\",\\\"\"+s[1].Replace(\"\\\\\",\"\\\\\\
\\\").Replace(\"\\\\\",\"\\\\\\\\\")+\"\\\"\"+s[1]);}}"};public s
tatic void Main(){System.Console.WriteLine(s[0]+"\""+s[0].Replace
("\\","\\\\").Replace("\\","\\\"")+"\",\""+s[1].Replace("\\","\\\
\").Replace("\\","\\\\")+"\""+s[1]);}}


Remove all linebreaks.

qbg
Posts: 586
Joined: Tue Dec 18, 2007 3:37 pm UTC

Re: Programs that print their own source code

Postby qbg » Tue Feb 17, 2009 3:16 am UTC

Yet another Common Lisp solution I just came up with:

Code: Select all

(macrolet ((do-self (&body body)
             `(progv '(*self*) '((do-self ,@body))
                (eval '(progn ,@body)))))
  (do-self
   `(macrolet ((do-self (&body body)
                 `(progv '(*self*) '((do-self ,@body))
                    (eval '(progn ,@body)))))
      ,*self*)))


EDIT: Or something simpler:

Code: Select all

(let ((a '(lambda (a)
            `(let ((a ',a))
               (funcall (compile nil a) a)))))
  (funcall (compile nil a) a))

FatPhil
Posts: 3
Joined: Tue Feb 17, 2009 3:23 pm UTC

Re: Programs that print their own source code

Postby FatPhil » Tue Feb 17, 2009 10:07 pm UTC

Stick this in your nearest shell:

Code: Select all

dc -e'[[dc -e]P39P91PP93P[dx]P39PAP]dx'

(I of course have a pure dc quine too, but that's too short and simple to be interesting.)

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Programs that print their own source code

Postby TheChewanater » Sun Nov 15, 2009 9:25 pm UTC

Code: Select all

 
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Programs that print their own source code

Postby You, sir, name? » Sun Nov 15, 2009 9:48 pm UTC

Code: Select all

#!/bin/bash
# fish in barrel, meet stick of dynamite:
cat $0
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

tekk
Posts: 35
Joined: Wed Aug 12, 2009 5:48 am UTC

Re: Programs that print their own source code

Postby tekk » Mon Nov 16, 2009 12:47 am UTC

:shock: I'm surprised noone's used the best tool for this job, aside from the genius who first came up with using cat

Code: Select all

#!/usr/bin/perl

open(source, "./printsrc");
@src = <source>;
print(@src);

yay perl =D

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Programs that print their own source code

Postby You, sir, name? » Mon Nov 16, 2009 1:05 am UTC

tekk wrote::shock: I'm surprised noone's used the best tool for this job, aside from the genius who first came up with using cat

Code: Select all

#!/usr/bin/perl

open(source, "./printsrc");
@src = <source>;
print(@src);

yay perl =D


Ah, but that fails if you change the file name. Mine doesn't.
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

tekk
Posts: 35
Joined: Wed Aug 12, 2009 5:48 am UTC

Re: Programs that print their own source code

Postby tekk » Mon Nov 16, 2009 1:12 am UTC

You, sir, name? wrote:
tekk wrote::shock: I'm surprised noone's used the best tool for this job, aside from the genius who first came up with using cat

Code: Select all

#!/usr/bin/perl

open(source, "./printsrc");
@src = <source>;
print(@src);

yay perl =D


Ah, but that fails if you change the file name. Mine doesn't.

I honestly just cannibalized my game for that code :roll: I'll have to think of a way to fix that

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Programs that print their own source code

Postby Random832 » Mon Nov 16, 2009 2:09 am UTC

Code: Select all

#!/bin/cat
cat $0 is for weenies - cut out the middleman.

User avatar
Earlz
Gets Obvious Implications
Posts: 785
Joined: Sat Jun 09, 2007 8:38 am UTC
Location: USA
Contact:

Re: Programs that print their own source code

Postby Earlz » Mon Nov 16, 2009 5:04 am UTC

Sadly I can't contribute(I'm not good at such problems) but I have a request.

Can someone please make a self-printing BF program? lol
My new blag(WIP, so yes it's still ugly..)
DEFIANCE!
Image
This is microtext. Zooming in digitally makes it worse. Get a magnifying glass.. works only on LCD

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Programs that print their own source code

Postby phlip » Mon Nov 16, 2009 5:26 am UTC

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Programs that print their own source code

Postby You, sir, name? » Mon Nov 16, 2009 12:44 pm UTC

Random832 wrote:

Code: Select all

#!/bin/cat
cat $0 is for weenies - cut out the middleman.


But cat is an integral part of shell scripting! Okay, so how about this one.

Everything beyond the first line is valid C and valid bash code, and the bash code compiles itself as a C program that works like a limited version of cat, which can be used to print it's own sources.

Code: Select all

#!/bin/bash
#if 0
file=`mktemp`
tail -n+2 $0 | cc -o $file -x c -
$file < $0
rm $file
exit
#endif
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[]) {
        for(;;) {
                int c = getchar();
                if(c == EOF) break;
                putchar(c);
        }

        return EXIT_SUCCESS;
}
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

User avatar
Squid Tamer
Posts: 220
Joined: Fri Apr 03, 2009 3:59 am UTC
Location: Over there
Contact:

Re: Programs that print their own source code

Postby Squid Tamer » Thu Nov 19, 2009 12:52 pm UTC

I heard of some guy who won a competition like this just by his program being:

Code: Select all

hi

When it's run it has an error and returns the culprit line: the only one there.
I think that this competition had no official rules, no there was nothing to stop him.

Yes, I would count it as cheating, but still thought it was funny.

User avatar
phlip
Restorer of Worlds
Posts: 7572
Joined: Sat Sep 23, 2006 3:56 am UTC
Location: Australia
Contact:

Re: Programs that print their own source code

Postby phlip » Thu Nov 19, 2009 1:01 pm UTC

Hmm... in that vein, this file:

Code: Select all

tmp.c:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
tmp.c:1:41: warning: multi-character character constant
tmp.c:1:50: warning: character constant too long for its type
when saved as "tmp.c" and compiled with:

Code: Select all

LC_ALL=C gcc tmp.c 2>&1
(the LC_ALL=C is required in Unicode terminals, otherwise the error messages come out with smart quotes instead of ASCII quotes) comes out with the same output as its input. Sort of a GCC quine, rather than a C quine.

I'm interested to know what compiler you were using where an input of "hi" came out with an error message of merely "hi"... no other messages at all.

Code: Select all

enum ಠ_ಠ {°□°╰=1, °Д°╰, ಠ益ಠ╰};
void ┻━┻︵​╰(ಠ_ಠ ⚠) {exit((int)⚠);}
[he/him/his]

User avatar
PM 2Ring
Posts: 3713
Joined: Mon Jan 26, 2009 3:19 pm UTC
Location: Sydney, Australia

Re: Programs that print their own source code

Postby PM 2Ring » Thu Nov 19, 2009 2:23 pm UTC

phlip wrote:I'm interested to know what compiler you were using where an input of "hi" came out with an error message of merely "hi"... no other messages at all.

Me, too. Maybe this happened a long time ago on some odd interpreter-based system.

I could imagine a BASIC interpreter that used "hi" as the prompt, intstead of the usual Ok. And it could ignore "hi" alone on a line as a harmless syntax error.

Back in the day, most BASICs would spit out a simple message on a syntax error, and so if you typed the syntax error message at the interpreter, it'd spit it back out at you. This is the most likely scenario for the story above, IMHO, but the details have become altered as the tale was passed around. :)

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Programs that print their own source code

Postby Random832 » Thu Nov 19, 2009 2:23 pm UTC

Using the Microsoft C# compiler...

Code: Select all

Microsoft (R) Visual C# 2008 Compiler version 3.5.30729.1
for Microsoft (R) .NET Framework version 3.5
Copyright (C) Microsoft Corporation. All rights reserved.

foo.cs(1,23): error CS1040: Preprocessor directives must appear as the first
        non-whitespace character on a line
foo.cs(1,1): error CS0116: A namespace does not directly contain members such as
        fields or methods
foo.cs(7,45): error CS1514: { expected
foo.cs(10,40): error CS1513: } expected

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Programs that print their own source code

Postby TheChewanater » Thu Nov 19, 2009 7:17 pm UTC

Creative, but a quine is "A program that prints it's own source code when run". These neither run nor print their source code (the compilers do).
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.

User avatar
You, sir, name?
Posts: 6983
Joined: Sun Apr 22, 2007 10:07 am UTC
Location: Chako Paul City
Contact:

Re: Programs that print their own source code

Postby You, sir, name? » Thu Nov 19, 2009 7:34 pm UTC

TheChewanater wrote:Creative, but a quine is "A program that prints it's own source code when run". These neither run nor print their source code (the compilers do).


That's compiled langauges though. In interpreted languages, there is very little to distinguish between "the program caused the interpreter to print" and "the program prints".
I edit my posts a lot and sometimes the words wrong order words appear in sentences get messed up.

Random832
Posts: 2525
Joined: Wed Oct 10, 2007 4:38 pm UTC

Re: Programs that print their own source code

Postby Random832 » Thu Nov 19, 2009 7:39 pm UTC

How about...

Code: Select all

C:\foo.exe is not a valid Win32 application.

Save to the file "C:\foo.exe", or adjust the content accordingly.

User avatar
TheChewanater
Posts: 1279
Joined: Sat Aug 08, 2009 5:24 am UTC
Location: lol why am I still wearing a Santa suit?

Re: Programs that print their own source code

Postby TheChewanater » Thu Nov 19, 2009 7:45 pm UTC

You, sir, name? wrote:
TheChewanater wrote:Creative, but a quine is "A program that prints it's own source code when run". These neither run nor print their source code (the compilers do).


That's compiled langauges though. In interpreted languages, there is very little to distinguish between "the program caused the interpreter to print" and "the program prints".


Well, it translates it into machine code, right? If it cannot do this and the interpreter prints this out, I don't think it's a quine.
ImageImage
http://internetometer.com/give/4279
No one can agree how to count how many types of people there are. You could ask two people and get 10 different answers.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 12 guests