Print itself: Difference between revisions

(add Ruby)
 
(5 intermediate revisions by 5 users not shown)
Line 36:
Ada.Text_IO.Close (File => Source);
end Autoprint;
print(row, end='')</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="pythonalgol68">import sys
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 44 ⟶ 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 221 ⟶ 256:
 
=={{header|Python}}==
<syntaxhighlight lang="python">
{{works with|python3}}
with open(sys.argv[0],'r'__file__) as inputf:
<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 273 ⟶ 315:
 
=={{header|Wren}}==
<syntaxhighlight lang="ecmascriptwren">import "os" for Process
import "io" for File
 
Line 282 ⟶ 324:
Just the invoking line as remainder is, of course, as above.
<pre>
$ wren-cli self_printPrint_itself.wren
</pre>
 
56

edits