Jump to content

Print itself: Difference between revisions

(J)
 
(9 intermediate revisions by 7 users not shown)
Line 13:
-V sourceFileName = fs:path:split_ext(:argv[0])[0]‘.11l’
print(File(sourceFileName).read())
</syntaxhighlight>
 
=={{header|Ada}}==
<syntaxhighlight lang="ada">
-- Print the program's source to standard output
-- J. Carter 2023 Apr
-- Apparently it's acceptable to open the source file and copy it to the output
 
with Ada.Text_IO;
 
procedure Autoprint is
Source : Ada.Text_IO.File_Type;
begin -- Autoprint
Ada.Text_IO.Open (File => Source, Mode => Ada.Text_IO.In_File, Name => "autoprint.adb");
All_Lines : loop
exit All_Lines when Ada.Text_IO.End_Of_File (Source);
Ada.Text_IO.Put_Line (Item => Ada.Text_IO.Get_Line (Source) );
end loop All_Lines;
Ada.Text_IO.Close (File => Source);
end Autoprint;
</syntaxhighlight>
 
=={{header|ALGOL 68}}==
Using standard Algol 68 transput. Assumes the source is in a file called printItself.a68 in the current directory.
<syntaxhighlight lang="algol68">
IF FILE input file;
STRING file name = "printItself.a68";
open( input file, file name, stand in channel ) /= 0
THEN
# failed to open the file #
print( ( "Unable to open """ + file name + """", newline ) )
ELSE
# file opened OK #
BOOL at eof := FALSE;
on logical file end( input file # set the EOF handler for the file #
, ( REF FILE f )BOOL:
BEGIN
# note that we reached EOF on the latest read #
# and return TRUE so processing can continue #
at eof := TRUE
END
);
WHILE STRING line;
get( input file, ( line, newline ) );
NOT at eof
DO
print( ( line, newline ) )
OD;
close( input file )
FI
</syntaxhighlight>
 
{{Trans|FreeBASIC|Alternative version, using an OS command to print the source.}}
{{works with|ALGOL 68G|Any - tested with release 2.8.3.win32}}
Assumes the source is in a file called printItself2.a68 in the current directory.
<syntaxhighlight lang="algol68">
system( "type printItself2.a68" ) # replace type with cat for Linux #
</syntaxhighlight>
 
Line 21 ⟶ 81:
</syntaxhighlight>
 
=={{header|Binary Lambda Calculus}}==
The 18 byte BLC program <code>16 46 80 05 bc bc fd f6 80 16 46 80 05 bc bc fd f6 80</code> prints itself.                                                     
=={{header|Ecstasy}}==
<syntaxhighlight lang="java">
module test {
{
@Inject Console console;
void run() {
{
console.print($./test.x);
}
}
}
</syntaxhighlight>
 
{{out}}
<pre>
module test {
{
@Inject Console console;
void run() {
{
console.print($./test.x);
}
}
}
</pre>
 
Line 52 ⟶ 110:
<syntaxhighlight lang="furor">
1 argv getfile dup sprint free
end
</syntaxhighlight>
 
=={{header|Peri}}==
<syntaxhighlight lang="peri">
###sysinclude standard.uh
###sysinclude args.uh
###sysinclude str.uh
###sysinclude io.uh
1 argv getfile dup sprint
end
</syntaxhighlight>
Line 188 ⟶ 256:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
{{works with|python3}}
with open(__file__) as f:
<syntaxhighlight lang="python">import sys
print(f.read())
with open(sys.argv[0],'r') as input:
</syntaxhighlight>
for row in input:
 
print(row, end='')</syntaxhighlight>
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery">[ this echo ]</syntaxhighlight>
 
{{out}}
 
<pre>[ this echo ]</pre>
 
=={{header|Raku}}==
Line 233 ⟶ 308:
fclose(fp)
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">
puts File.read(__FILE__)
</syntaxhighlight>
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "os" for Process
import "io" for File
 
Line 244 ⟶ 324:
Just the invoking line as remainder is, of course, as above.
<pre>
$ wren-cli self_printPrint_itself.wren
</pre>
 
56

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.