I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Print itself

From Rosetta Code
Print itself is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Create a program, which prints its source code to the stdout!

Related tasks


1 argv getfile dup sprint free


package main
import (
func main() {
self := path.Base(os.Args[0]) + ".go"
bytes, err := ioutil.ReadFile(self)
if err != nil {

Just the invoking line as remainder is, of course, as above.

$ go run self_print.go


You can drop the substitute() if you plan to interpret rather than compile it.
It will not work, obviously, if you compile it (say test.exw) to test.exe and then either rename the executable or move it to some directory where there is no test.exw

>p test ;; or p -c test


Works with: Rakudo version 2020.05

Not really sure what the point of this task is.

Is it supposed to be a quine?

my &f = {say $^s, $^s.raku;}; f "my \&f = \{say \$^s, \$^s.raku;}; f "

Or just a program that when executed echoes its source to STDOUT? (Here's probably the simplest valid program that when executed, echoes its source to STDOUT. It is exceptionally short: zero bytes; and when executed echoes zero bytes to STDOUT.)


Or are we supposed to demonstrate how to locate the currently executing source code file and incidentally, print it.

print $*PROGRAM.slurp

Whatever. Any of these satisfy the rather vague specifications.


/*REXX program  prints  its own multi─line source to the  standard output  (stdout).    */
do j=1 for sourceline()
call lineout , sourceline(j)
end /*j*/ /*stick a fork in it, we're all done. */


import "os" for Process
import "io" for File
var args = Process.allArguments

Just the invoking line as remainder is, of course, as above.

$ wren self_print.wren