Print itself: Difference between revisions

Content added Content deleted
(Added Algol 68)
Line 36: Line 36:
Ada.Text_IO.Close (File => Source);
Ada.Text_IO.Close (File => Source);
end Autoprint;
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>
</syntaxhighlight>