The Daily WTF: Curious Perversions in Information Technology
Welcome to TDWTF Forums Sign in | Join | Help
in Search

Self-Printing Program

Last post 05-23-2009 12:04 PM by The Wolf. 64 replies.
Page 1 of 2 (65 items) 1 2 Next >
Sort Posts: Previous Next
  • 02-24-2007 3:11 PM

    Self-Printing Program

    Here's a tough one:

    Make a program that print's it own source code.
     

  • 02-24-2007 3:25 PM In reply to

    Re: Self-Printing Program

    DOH edit expired...

    Rules: The program must have at least 1 real(not whitespace) line of source code

  • 02-24-2007 6:01 PM In reply to

    Re: Self-Printing Program

    meisawesome:

    Here's a tough one:

    Make a program that print's it own source code.
     

    In Brainfuck:

    ->+>+++>>+>++>+>+++>>+>++>>>+>+>+>++>+>>>>+++>+>>++>+>+++>>++>
    ++>>+>>+>++>++>+>>>>+++>+>>>>++>++>>>>+>>++>+>+++>>>++>>+++++
    +>>+>>++>+>>>>+++>>+++++>>+>+++>>>++>>++>>+>>++>+>+++>>>++>>+
    ++++++++++++>>+>>++>+>+++>+>+++>>>++>>++++>>+>>++>+>>>>+++>>+
    ++++>>>>++>>>>+>+>++>>+++>+>>>>+++>+>>>>+++>+>>>>+++>>++>++>+
    >+++>+>++>++>>>>>>++>+>+++>>>>>+++>>>++>+>+++>+>+>++>>>>>>++>
    >>+>>>++>+>>>>+++>+>>>+>>++>+>++++++++++++++++++>>>>+>+>>>+>>
    ++>+>+++>>>++>>++++++++>>+>>++>+>>>>+++>>++++++>>>+>++>>+++>+
    >+>++>+>+++>>>>>+++>>>+>+>>++>+>+++>>>++>>++++++++>>+>>++>+>>
    >>+++>>++++>>+>+++>>>>>>++>+>+++>>+>++>>>>+>+>++>+>>>>+++>>++
    +>>>+[[->>+<<]<+]+++++[->+++++++++<]>.[+]>>[<<+++++++[->+++++++++<]>-
    .------------------->-[-<.<+>>]<[+]<+>>>]<<<[-[-[-[>>+<++++++[->+++++<]]>+++++++
    +++++++<]>+++<]++++++[->+++++++<]>+<<<-[->>>++<<<]>[->>.<<]<<]

    Note that whitespace is not preserved, but is semantically meaningless.  With apologies to Brian Raiter.

  • 02-24-2007 6:27 PM In reply to

    • iwpg
    • Top 500 Contributor
    • Joined on 05-24-2006
    • Posts 258

    Re: Self-Printing Program

    In Perl:

    #! /usr/bin/perl

    use strict;
    use warnings;

    use LWP::UserAgent;
    use HTML::PullParser;

    my $ua = new LWP::UserAgent;

    my $req = new HTTP::Request(GET => "http://forums.worsethanfailure.com/forums/permalink/114219/114219/ShowThread.aspx");
    my $resp = $ua->request($req);

    my $p = new HTML::PullParser(doc => $resp->decoded_content,
    report_tags => [qw/a pre br/],
    start => '"S", tagname, attr',
    end => '"E", tagname',
    text => '"T", dtext',
    unbroken_text => 1,
    );

    while (my $token = $p->get_token()) {
    last if $token->[0] eq "S" && $token->[1] eq "a" && ($token->[2]->{name} || "") eq "114219";
    }

    while (my $token = $p->get_token()) {
    last if $token->[0] eq "S" && $token->[1] eq "pre";
    }

    my $code = "";
    while (my $token = $p->get_token()) {
    last if $token->[0] eq "E" && $token->[1] eq "pre";
    $code .= "\n" if $token->[0] eq "S" && $token->[1] eq "br";
    $code .= $token->[1] if $token->[0] eq "T";
    }

    print($code);

    ;-)

  • 02-24-2007 6:46 PM In reply to

    • GeneWitch
    • Top 200 Contributor
    • Joined on 12-23-2006
    • Orange County, CA
    • Posts 315

    Re: Self-Printing Program

    iwpg:

    In Perl:

    #! /usr/bin/perl

    use strict;
    use warnings;

    use LWP::UserAgent;
    use HTML::PullParser;

    my $ua = new LWP::UserAgent;

    my $req = new HTTP::Request(GET => "http://forums.worsethanfailure.com/forums/permalink/114219/114219/ShowThread.aspx");
    my $resp = $ua->request($req);

    my $p = new HTML::PullParser(doc => $resp->decoded_content,
    report_tags => [qw/a pre br/],
    start => '"S", tagname, attr',
    end => '"E", tagname',
    text => '"T", dtext',
    unbroken_text => 1,
    );

    while (my $token = $p->get_token()) {
    last if $token->[0] eq "S" && $token->[1] eq "a" && ($token->[2]->{name} || "") eq "114219";
    }

    while (my $token = $p->get_token()) {
    last if $token->[0] eq "S" && $token->[1] eq "pre";
    }

    my $code = "";
    while (my $token = $p->get_token()) {
    last if $token->[0] eq "E" && $token->[1] eq "pre";
    $code .= "\n" if $token->[0] eq "S" && $token->[1] eq "br";
    $code .= $token->[1] if $token->[0] eq "T";
    }

    print($code);

    ;-)

    HAHAHA that's fucked up.

    you're gunna get a FILE-NOT-FOUND error soon though, ain't ya?

    sudo make me a sandwich
  • 02-25-2007 6:35 AM In reply to

    Re: Self-Printing Program

    This stopped being difficult when languages gained self-referential capabilities
    In Perl:
    seek DATA,0,0;print while <DATA>
    __END__
    
  • 02-25-2007 2:22 PM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,530

    Re: Self-Printing Program

    meisawesome:

    Here's a tough one:

    Make a program that print's it own source code. 

    int main(int argc, char *argv[]) { char *s="int main(int argc, char *argv[]) { char *s=%c%s%c; printf(s,34,s,34,10); return 0; }%c"; printf(s,34,s,34,10); return 0; }

     

     

    Disclaimer: I've written this little program all by myself, without peeking into existing solutions (but knowing the basic concept). Anyway, due to the nature of this challenge, it's likely that a very similar or even identical solution already exists somewhere on the web.
     

     

     

    beanbag girl 4ever ... or maybe Astah girl?
  • 02-25-2007 3:02 PM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,530

    Re: Self-Printing Program

    Now to something less boring than C: the self-replicating SQL*PLUS script


    set feedback off
    set head off
    set linesize 32767
    create or replace function selfrep return varchar2 is
    s varchar2(2000) := 'set feedback offAset head offAset linesize 32767Acreate or replace function selfrep return varchar2 isAs varchar2(2000) := BCB;AbeginAreturn replace(replace(replace(s,chr(65),chr(10)),chr(66),chr(39)),chr(67),s);Aend;A/Aselect selfrep from dual;A';
    begin
    return replace(replace(replace(s,chr(65),chr(10)),chr(66),chr(39)),chr(67),s);
    end;
    /
    select selfrep from dual;

    beanbag girl 4ever ... or maybe Astah girl?
  • 02-25-2007 3:19 PM In reply to

    Re: Self-Printing Program

    I have heard, that level 2 version of this problem is to write source code for program A, which outputs source code for program B, which in turn outputs source code for program A.

    I am too stupid to solve these by myself, but it would be interesting to see if this could be solved by using CodeDom in .Net.
     

  • 02-25-2007 5:47 PM In reply to

    • ammoQ
    • Top 10 Contributor
    • Joined on 04-13-2005
    • Vienna.Austria.Europe.Earth
    • Posts 3,530

    Re: Self-Printing Program

    sirhegel:

    I have heard, that level 2 version of this problem is to write source code for program A, which outputs source code for program B, which in turn outputs source code for program A.

    I am too stupid to solve these by myself, but it would be interesting to see if this could be solved by using CodeDom in .Net.

    Here we go, Level 2... the only difference between program A and program B is one character in a comment.. better than nothing, I guess...It's a modified version of the SQL*PLUS script.

     

     

    set feedback off
    set head off
    set linesize 32767
    create or replace function selfrep return varchar2 is
    s varchar2(2000) := 'set feedback offAset head offAset linesize 32767Acreate or replace function selfrep return varchar2 isAs varchar2(2000) := BCB;AbeginA-- DAreturn replace(replace(replace(replace(replace(replace(replace(s,chr(65),chr(10)),chr(66),chr(39)),chr(67),s),chr(68),chr(70)),chr(69),chr(71)),chr(70),chr(69)),chr(71),chr(68));Aend;A/Aselect selfrep from dual;A';
    begin
    -- D
    return replace(replace(replace(replace(replace(replace(replace(s,chr(65),chr(10)),chr(66),chr(39)),chr(67),s),chr(68),chr(70)),chr(69),chr(71)),chr(70),chr(69)),chr(71),chr(68));
    end;
    /
    select selfrep from dual;

    beanbag girl 4ever ... or maybe Astah girl?
  • 03-06-2007 12:05 PM In reply to

    • kryptn
    • Not Ranked
    • Joined on 03-06-2007
    • Posts 1

    Re: Self-Printing Program

    in php:

    <?php 

    $self substr($_SERVER['SCRIPT_NAME'], 1);
    highlight_string(file_get_contents($self));

    ?>

  • 03-06-2007 2:26 PM In reply to

    • Pap
    • Top 200 Contributor
    • Joined on 09-12-2006
    • Earf
    • Posts 281

    Re: Self-Printing Program

    Who can beat 21 characters?

    <?readfile(__FILE__);
  • 03-06-2007 2:34 PM In reply to

    • iwpg
    • Top 500 Contributor
    • Joined on 05-24-2006
    • Posts 258

    Re: Self-Printing Program

    Pap:
    Who can beat 21 characters?

    How about: 

  • 03-06-2007 2:41 PM In reply to

    • Pap
    • Top 200 Contributor
    • Joined on 09-12-2006
    • Earf
    • Posts 281

    Re: Self-Printing Program

    Rules: The program must have at least 1 real(not whitespace) line of source code
  • 03-06-2007 2:43 PM In reply to

    • Pap
    • Top 200 Contributor
    • Joined on 09-12-2006
    • Earf
    • Posts 281

    Re: Self-Printing Program

    I'm more interested in self-replicating WTFs... you know, the ones where the comments are more retarded than the original story.  Anyone have any favorites of these they would care to link to?
  • 03-06-2007 3:16 PM In reply to

    • iwpg
    • Top 500 Contributor
    • Joined on 05-24-2006
    • Posts 258

    Re: Self-Printing Program

    Pap:
    Rules: The program must have at least 1 real(not whitespace) line of source code

    Bah, how boring. 

  • 03-06-2007 5:37 PM In reply to

    Re: Self-Printing Program

    Anyone remember the Wang 2200?  The shortest self-reproducing program for it was:

     ^Error 42

     

    If you typed that in, the response would be:

    ^Error 42

     

  • 03-06-2007 9:59 PM In reply to

    • iwpg
    • Top 500 Contributor
    • Joined on 05-24-2006
    • Posts 258

    Re: Self-Printing Program

    iwpg:

    Pap:
    Who can beat 21 characters?

    How about: 

    Seriously though, Unix shell:

    cat $0
  • 03-08-2007 1:34 PM In reply to

    • klmann
    • Not Ranked
    • Joined on 03-08-2007
    • Posts 2

    Re: Self-Printing Program

    Python:
    import sys
    print file(sys.argv[0]).read()
    
  • 03-09-2007 9:17 AM In reply to

    • JvdL
    • Top 500 Contributor
    • Joined on 01-26-2007
    • Spain
    • Posts 212

    Re: Self-Printing Program

    This is a no-brainer in JavaScript:

      function program() {
        alert(program);
        return "Brillant";
      }
  • 03-09-2007 10:44 AM In reply to

    • aikii
    • Top 500 Contributor
    • Joined on 05-18-2006
    • Brussels
    • Posts 143

    Re: Self-Printing Program

    How about a program that opens its source in word, prints the screenshot that lands on a wooden table, triggers a shot by a digital camera and then exports the picture to a website ?
  • 03-10-2007 3:23 PM In reply to

    Re: Self-Printing Program

    In Powershell:

    function TypeMe() { Get-Content "Function:\TypeMe" }

    It's funny because it's out of context.
  • 03-19-2007 2:21 PM In reply to

    • XIU
    • Top 200 Contributor
    • Joined on 01-08-2007
    • Belgium
    • Posts 277

    Re: Self-Printing Program

    Found this one on the internets:

    http://p-nand-q.com/python/scripts/quine6.txt

     

  • 03-22-2007 2:14 PM In reply to

    Re: Self-Printing Program

    windows batch file...


    rem
     

  • 03-23-2007 12:57 PM In reply to

    In C, with nice formatting

    sirhegel:

    I have heard, that level 2 version of this problem is to write source code for program A, which outputs source code for program B, which in turn outputs source code for program A.

    #include <stdio.h>

    int main()
    {
        const int id = 0;
        char *prog = "#include <stdio.h>%c%cint main()%c{%c    const int id = %d;%c    char *prog = %c%s%c;%c    printf(prog, 10, 10, 10, 10, id^1, 10, 34, prog, 34, 10, 10, 10);%c    return 0;%c}";
        printf(prog, 10, 10, 10, 10, id^1, 10, 34, prog, 34, 10, 10, 10);
        return 0;
    }

    Begging the question since 2007.
  • 03-23-2007 4:36 PM In reply to

    Re: Self-Printing Program

    Python (without using read...):

    s="s=%c%s%c%cprint(s%c(34,s,34,10,37))"
    print(s%(34,s,34,10,37))

     

  • 03-24-2007 12:12 PM In reply to

    Re: Self-Printing Program

    Hehe. One year a zero-length 'quine' one the IOCCC prize for "Worst abuse of the rules".

    In English

    "Repeat exactly what I just said"

     

    TRWTF is Community Server
  • 03-25-2007 8:36 AM In reply to

    Re: Self-Printing Program

    I'd really like to see a quine written *in* Whitespace.
    TRWTF is Sandcastle Builder
  • 03-26-2007 3:30 PM In reply to

    Re: Self-Printing Program

    <%@ Page Language="C#" %>
    <script runat="server">
    protected void Page_Init(object sender, EventArgs e){
        Response.Write(System.IO.File.ReadAllText(Request.PhysicalPath));
    }
    </script>
  • 03-29-2007 3:29 PM In reply to

    Re: Self-Printing Program

    Atari 8K BASIC:

    10 LIST

    Heh.

     

  • 04-12-2007 6:48 PM In reply to

    Re: Self-Printing Program

    Bash :)

    echo $BASH_COMMAND
  • 04-13-2007 2:41 PM In reply to

    Re: Self-Printing Program

    CREATE PROC SP_ME
    AS
    SELECT ROUTINE_DEFINITION
        FROM INFORMATION_SCHEMA.ROUTINES
        WHERE ROUTINE_NAME = 'SP_ME'
        AND ROUTINE_TYPE='PROCEDURE'
  • 04-14-2007 10:14 PM In reply to

    Re: Self-Printing Program

    Rexx

    /* */ say sourceline(1)


     

  • 04-16-2007 5:59 AM In reply to

    Re: Self-Printing Program

    #!/bin/bash
    x=20; d='bupr
    rabq
    "}1:d:q{$" a- bupr
    bq ;))--d;0=>d;2-k=d((ebs
    "740\" r- bupr
    31gbe | "q$" a- bupr
    "740\" ra- bupr
    rabq
    "}1:d:q{$" a- bupr
    bq ;))--d;k=>d;1-}q#{$=d((ebs
    ]k-y[$=k ;}q#{$=y
    `31gbe | "q$" bupr`=q
    =q ;02=k
    ufno/avo/!#'
    d=`echo "$d" | rot13`
    l=${#d}; x=$[l-x]
    for((q=${#d}-1;q>=x;q--)); do
      echo -n "${d:q:1}"
    done
    echo -ne "\047"
    echo -n "$d" | rot13
    echo -e "\047"
    for((q=x-2;q>=0;q--)); do
      echo -n "${d:q:1}"
    done
    echo
  • 04-16-2007 10:19 AM In reply to

    • cf3
    • Not Ranked
    • Joined on 06-14-2006
    • Posts 12

    Re: Self-Printing Program

    #!/bin/cat
  • 04-23-2007 10:27 AM In reply to

    • cangulo
    • Not Ranked
    • Joined on 04-23-2007
    • A beautiful town, Brasil
    • Posts 18

    Re: Self-Printing Program

    <?php echo implode("\n", file(__FILE__)); ?>
  • 04-25-2007 4:40 PM In reply to

    Re: Self-Printing Program

    Because someone had to do it

    (My apologies for the length)

    <?xml version="1.0" encoding="UTF-8" ?>
    <?xml-stylesheet type="text/xsl" href="http://forums.worsethanfailure.com/forums/AddPost.aspx?PostID=119432#" ?>
    <s:stylesheet version="1.0" xmlns:s="http://www.w3.org/1999/XSL/Transform">
        <s:output method="html" />
        <s:strip-space elements="*" />
        <s:preserve-space elements="s:text" />
        <s:template name="line">
            <br />
            <s:for-each select="ancestor::*">
                <s:text><![CDATA[    ]]></s:text>
            </s:for-each>
        </s:template>
        <s:template name="tagHead">
            <s:text><![CDATA[<]]></s:text>
            <span class="tagName">
                <s:value-of select="name()" />
            </span>
            <s:for-each select="./@*">
                <s:text><![CDATA[ ]]></s:text>
                <span class="attribName">
                    <s:value-of select="name()" />
                </span>
                <s:text><![CDATA[="]]></s:text>
                <span class="attribValue">
                    <s:value-of select="." />
                </span>
                <s:text><![CDATA["]]></s:text>
            </s:for-each>
        </s:template>
        <s:template name="tagTail">
            <s:text><![CDATA[</]]></s:text>
                <span class="tagName">
                    <s:value-of select="name()" />
                </span>
            <s:text><![CDATA[>]]></s:text>
        </s:template>
        <s:template match="//*">
            <s:call-template name="line" />
            <s:call-template name="tagHead" />
            <s:text><![CDATA[ />]]></s:text>
        </s:template>
        <s:template match="//*[child::*]">
            <s:call-template name="line" />
            <s:call-template name="tagHead" />
            <s:text><![CDATA[>]]></s:text>
            <s:apply-templates />
            <s:call-template name="line" />
            <s:call-template name="tagTail" />
        </s:template>
        <s:template match="//s:text|//style|//title|//span[@class='system']">
            <s:call-template name="line" />
            <s:call-template name="tagHead" />
            <s:text><![CDATA[>]]></s:text>
            <span class="cdataMarkup">
                <s:text><![CDATA[<![CDATA[]]></s:text>
            </span>
            <span class="textValue">
                <s:value-of select="text()" />
            </span>
            <span class="cdataMarkup">
                <s:text><![CDATA[]]]]></s:text>
                <s:text><![CDATA[>]]></s:text>
            </span>
            <s:call-template name="tagTail" />
        </s:template>
        <s:template match="/s:stylesheet">
            <html>
                <head>
                    <title><![CDATA[Quine!!!]]></title>
                    <style><![CDATA[
                        pre {
                            background-color:rgb(255,255,201);
                            border-color:rgb(255,255,0);
                            border-width:3px;
                            border-style:solid;
                            padding:3px;
                        }
                        .tagName        {color:DarkBlue;font-weight:bold;}
                        .attribName     {color:Blue;}
                        .attribValue    {color:DarkGoldenRod;font-style:italic;}
                        .cdataMarkup    {color:DarkMagenta;}
                        .textValue      {color:DarkOliveGreen;font-style:italic;}
                        .system         {color:BlueViolet;}
                    ]]></style>
                </head>
                <body>
                    <H1>
                        <s:value-of select="//title" />
                    </H1>
                    <code>
                        <pre>
                            <span class="system"><![CDATA[<?xml version="1.0" encoding="UTF-8" ?>]]></span>
                            <br />
                            <span class="system"><![CDATA[<?xml-stylesheet type="text/xsl" href="http://forums.worsethanfailure.com/forums/AddPost.aspx?PostID=119432#" ?>]]></span>
                            <br />
                            <s:for-each select="/s:stylesheet">
                                <s:call-template name="tagHead" />
                            </s:for-each>
                            <span class="system"><![CDATA[ xmlns:s]]></span>    
                            <s:text><![CDATA[="]]></s:text>
                            <span class="attribValue">
                                <s:text><![CDATA[http://www.w3.org/1999/XSL/Transform]]></s:text>
                            </span>
                            <s:text><![CDATA[">]]></s:text>
                            <s:apply-templates />
                            <br />
                            <s:for-each select="/s:stylesheet">
                                <s:call-template name="tagTail" />
                            </s:for-each>
                        </pre>
                    </code>
                </body>
            </html>
        </s:template>
    </s:stylesheet>

    (Apparently the WTF forum tries to be "smart" and messes up my stylesheet links... those href="http://forums.worsethanfailure.com/..."s are supposed to be just "#".)

  • 04-26-2007 2:47 PM In reply to

    Re: Self-Printing Program

    An interesting concept for all languages, here in PHP:

     

     <?php
    <b>Parse error</b>:  syntax error, unexpected '<' in <b>/opt/lampp/htdocs/selfrep.php</b> on line <b>2</b>
    ?>

     

     
    Of course, this is if your php files are in /opt/lampp/htdocs/, and the file is called "selfrep.php", but it works :P


     

  • 04-27-2007 6:33 AM In reply to

    • flop
    • Top 500 Contributor
    • Joined on 04-27-2007
    • Posts 148

    Re: Self-Printing Program

    For bash, ksh and probably others: z='echo "$x$z$y\"$x\" ; y=\"$y\" ; $z"' ; x="z='" ; y="' ; x=" ; echo "$x$z$y\"$x\" ; y=\"$y\" ; $z"
  • 05-17-2007 2:54 AM In reply to

    • Worf
    • Not Ranked
    • Joined on 05-15-2007
    • Posts 14

    Re: Self-Printing Program

    sirhegel:

    I have heard, that level 2 version of this problem is to write source code for program A, which outputs source code for program B, which in turn outputs source code for program A.

    I am too stupid to solve these by myself, but it would be interesting to see if this could be solved by using CodeDom in .Net.
     

     

    A recent (a couple years ago or so) back, the IOCCC had such an entry. It started out formatted as a Japanese character. Compile, run, outputs source code in the form of another Japanese character. Compile/run, you get a third, and so on for at least 6 times, at which point, you ended up with the beginning character.
     

  • 05-25-2007 1:41 PM In reply to

    Re: Self-Printing Program

    [i did the #!/bin/cat, then noticed someone else had after the delete time limit ran out]

     

  • 07-13-2007 11:22 AM In reply to

    Re: Self-Printing Program

    dillybar1:

    windows batch file...


    rem
     

     No, that doesn't print out its source code.
     

    the forum software ate my colon
  • 07-13-2007 2:22 PM In reply to

    Re: Self-Printing Program

    gremlin:

     No, that doesn't print out its source code.
     



    Sure it does. The only time it doesn't is if ECHO OFF was used before running it. Sample output of "TESTBAT.BAT" that only contains the statement "REM":


    C:\>testbat

    C:\>REM

    C:\>echo off
    testbat
    echo on

    C:\>

    Join us at #TDWTF on irc.slashnet.org !

  • 02-10-2008 12:43 PM In reply to

    Re: Self-Printing Program

    This is called a quine and it has been done a lot already. I have made one quine program in MS-DOS: @echo off %1 %2 call %0 goto e %% call %0 goto e %%3 echo.%%4 echo :f goto f :e echo.%4@echo off echo.%4%31 %32 echo.%4call %30 goto e %3%3 echo.%4call %30 goto e %3%33 echo.%3%34 echo.%4echo :f echo.%4goto f echo.%4:e :f
    Let's using TeXnicard.
  • 02-10-2008 12:45 PM In reply to

    Re: Self-Printing Program

    O! It's a kimian quine!
    Let's using TeXnicard.
  • 02-12-2008 9:37 AM In reply to

    • XIU
    • Top 200 Contributor
    • Joined on 01-08-2007
    • Belgium
    • Posts 277

    Re: Self-Printing Program

     http://sigfpe.blogspot.com/2008/02/third-order-quine-in-three-languages.html not mine but damn, how do you come up with that :|

  • 02-12-2008 2:36 PM In reply to

    • mfah
    • Top 500 Contributor
    • Joined on 12-01-2007
    • Posts 117

    Re: Self-Printing Program

     

    AbbydonKrafts:

    gremlin:

     No, that doesn't print out its source code.
     



    Sure it does. The only time it doesn't is if ECHO OFF was used before running it. Sample output of "TESTBAT.BAT" that only contains the statement "REM":


    C:\>testbat

    C:\>REM

    C:\>echo off
    testbat
    echo on

    C:\>

    @echo off

    type printme.bat

     

  • 02-13-2008 9:40 AM In reply to

    Re: Self-Printing Program

    OK, since the thread is resurrected I decided I'll contribute as well:

    puts [format [set s {puts [format [set s {%s}] $s]}] $s]

    Guessing the language is left as an exercise to the reader 9=]. (Note, to make it perfect, the file must be terminated by a newline.)

    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
  • 02-13-2008 12:21 PM In reply to

    Re: Self-Printing Program

    Spectre:

    puts [format [set s {puts [format [set s {%s}] $s]}] $s]

    Guessing the language is left as an exercise to the reader


    That's expect, you pervert. Why don't you write something in COBOL while you're at it?

  • 02-13-2008 1:50 PM In reply to

    Re: Self-Printing Program

    asuffield:

    Spectre:

    puts [format [set s {puts [format [set s {%s}] $s]}] $s]

    Guessing the language is left as an exercise to the reader


    That's expect, you pervert. Why don't you write something in COBOL while you're at it?

    Tcl actually, but I guess Expect would run it too.

    ╩юфют√ь ёЄЁрэшЎрь яюЁр эр яхэёш■.

    #TDWTF @ SlashNET was merged into #codelove @ the same network. You're still welcome to drop by. I guess.
Page 1 of 2 (65 items) 1 2 Next >
Powered by Community Server (Non-Commercial Edition), by Telligent Systems