Print itself: Difference between revisions

From Rosetta Code
Content added Content deleted
m (corrected three misspellings in the task's preamble, added a :Related task.)
Line 11: Line 11:


=={{header|Furor}}==
=={{header|Furor}}==
1 argv getfile dup sprint free
A very short solution, using some special features of Furor:
end
<lang Furor>
<lang Furor>
"#s sto selfstring QUOTE @selfstring dup print QUOTE NL printnl end { „selfstring” }"
#s sto selfstring QUOTE @selfstring dup print QUOTE NL printnl end { „selfstring” }
</lang>
And behold, here is a more complex but "traditional" solution of this famous task, solved by 3 loops:
<lang Furor>
#g §vége §eleje - tokensize / sto maxlines
#s
7 {| {} §eleje[] printnl |}
@maxlines {| {} §eleje[] QUOTE print QUOTE NL |}
7 @maxlines {|| {} §eleje[] printnl |}
end
eleje:
"#g §vége §eleje - tokensize / sto maxlines"
"#s"
"7 {| {} §eleje[] printnl |}"
" @maxlines {| {} §eleje[] QUOTE print QUOTE NL |}"
"7 @maxlines {|| {} §eleje[] printnl |}"
"end"
"eleje:"
"vége:"
"{ „selfstring” }"
"{ „maxlines” }"
vége:
{ „selfstring” }
{ „maxlines” }
</lang>


=={{header|Go}}==
=={{header|Go}}==

Revision as of 20:50, 8 June 2020

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!

DO NOT USE the source file of the program! It is the running program itself which has to contain it's source code somehow, without reading the source file!


Related task



Furor

1 argv getfile dup sprint free end <lang Furor>

Go

<lang go>package main

import (

   "fmt"
   "io/ioutil"
   "log"
   "os"
   "path"

)

func main() {

   self := path.Base(os.Args[0]) + ".go"
   bytes, err := ioutil.ReadFile(self)
   if err != nil {
       log.Fatal(err)
   }
   fmt.Print(string(bytes))

}</lang>

Output:

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

$ go run self_print.go

REXX

<lang rexx>/*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. */</lang>

Wren

<lang ecmascript>import "os" for Process import "io" for File

var args = Process.allArguments System.write(File.read(args[1]))</lang>

Output:

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

$ wren self_print.wren