← All examples

quine.raku

A program that prints its own source.

A quine: a program whose output is its own source code, exactly, without reading any file. The entire source is held once in the string $s; printf feeds $s back into itself, using %c (codepoint 39) for the quote marks that wrap it and %s for the text. diff <(./build/rakupp examples/quine.raku) examples/quine.raku shows no differences.

The program

Edit it and press Run — it executes in your browser.

#!/usr/bin/env raku
# A quine: this program prints its own source exactly and reads nothing
# from disk. The whole source is stored once in the string $s, and printf
# feeds $s back into itself, filling in the quote marks and the text.
my $s = '#!/usr/bin/env raku
# A quine: this program prints its own source exactly and reads nothing
# from disk. The whole source is stored once in the string $s, and printf
# feeds $s back into itself, filling in the quote marks and the text.
my $s = %c%s%c;
printf $s, 39, $s, 39;
';
printf $s, 39, $s, 39;
Output
#!/usr/bin/env raku
# A quine: this program prints its own source exactly and reads nothing
# from disk. The whole source is stored once in the string $s, and printf
# feeds $s back into itself, filling in the quote marks and the text.
my $s = '#!/usr/bin/env raku
# A quine: this program prints its own source exactly and reads nothing
# from disk. The whole source is stored once in the string $s, and printf
# feeds $s back into itself, filling in the quote marks and the text.
my $s = %c%s%c;
printf $s, 39, $s, 39;
';
printf $s, 39, $s, 39;

Feature focus: string self-reference.