Include a file: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 14: | Line 14: | ||
=={{header|360 Assembly}}== |
=={{header|360 Assembly}}== |
||
The COPY instruction includes source statements from the SYSLIB library. |
The COPY instruction includes source statements from the SYSLIB library. |
||
< |
<syntaxhighlight lang="360asm"> COPY member</syntaxhighlight> |
||
=={{header|6502 Assembly}}== |
=={{header|6502 Assembly}}== |
||
There are two different directives for including files: <code>include</code> and <code>incbin</code>. <code>include</code> is for assembly code that will be converted to machine code that the computer can run. <code>incbin</code> is for binary data such as graphics, which the assembler will convert as-is to binary and does not attempt to translate it into machine code. |
There are two different directives for including files: <code>include</code> and <code>incbin</code>. <code>include</code> is for assembly code that will be converted to machine code that the computer can run. <code>incbin</code> is for binary data such as graphics, which the assembler will convert as-is to binary and does not attempt to translate it into machine code. |
||
Line 20: | Line 20: | ||
For this example, the file "foo.txt" is a file containing only the following: <code>RTS</code> |
For this example, the file "foo.txt" is a file containing only the following: <code>RTS</code> |
||
< |
<syntaxhighlight lang="6502asm">;main.asm |
||
org $8000 |
org $8000 |
||
include "foo.txt" |
include "foo.txt" |
||
;eof</ |
;eof</syntaxhighlight> |
||
A hexdump of the resulting machine code would look like this: |
A hexdump of the resulting machine code would look like this: |
||
Line 32: | Line 32: | ||
Now compare it to the following: |
Now compare it to the following: |
||
< |
<syntaxhighlight lang="6502asm">;main.asm |
||
org $8000 |
org $8000 |
||
incbin "foo.txt" |
incbin "foo.txt" |
||
;eof</ |
;eof</syntaxhighlight> |
||
<pre> |
<pre> |
||
Line 51: | Line 51: | ||
*<code>include</code>/<code>incbin</code> statements can be nested, i.e. an included file can contain its own included files, but there is a limit with how deep you can go. Nesting includes is never actually required, as the example below demonstrates: |
*<code>include</code>/<code>incbin</code> statements can be nested, i.e. an included file can contain its own included files, but there is a limit with how deep you can go. Nesting includes is never actually required, as the example below demonstrates: |
||
< |
<syntaxhighlight lang="6502asm">;main.asm |
||
include "Subroutines.asm" |
include "Subroutines.asm" |
||
;eof |
;eof |
||
Line 60: | Line 60: | ||
;math.asm |
;math.asm |
||
;eof</ |
;eof</syntaxhighlight> |
||
The above is assembled identically to: |
The above is assembled identically to: |
||
< |
<syntaxhighlight lang="6502asm">;main.asm |
||
include "Subroutines.asm" |
include "Subroutines.asm" |
||
include "math.asm" |
include "math.asm" |
||
;eof</ |
;eof</syntaxhighlight> |
||
=={{header|68000 Assembly}}== |
=={{header|68000 Assembly}}== |
||
Line 75: | Line 75: | ||
Unless you're using a linker to arrange your various files into an executable, the location of your <code>include</code> and <code>incbin</code> directives ''imply the memory location of the code or data you're including.'' For example: |
Unless you're using a linker to arrange your various files into an executable, the location of your <code>include</code> and <code>incbin</code> directives ''imply the memory location of the code or data you're including.'' For example: |
||
< |
<syntaxhighlight lang="68000devpac">org $00000000 |
||
;512 bytes containing anything really |
;512 bytes containing anything really |
||
include "myFile.asm" ;assuming no org or align directives are in this file, |
include "myFile.asm" ;assuming no org or align directives are in this file, |
||
;its starting memory location is guaranteed to be $00000200 (512 in decimal)</ |
;its starting memory location is guaranteed to be $00000200 (512 in decimal)</syntaxhighlight> |
||
This can become a problem if you have data that is not intended to be executed directly after a block of code, with nothing preventing "fallthrough." For example: |
This can become a problem if you have data that is not intended to be executed directly after a block of code, with nothing preventing "fallthrough." For example: |
||
< |
<syntaxhighlight lang="68000devpac">foo: |
||
LEA myData,A0 |
LEA myData,A0 |
||
MOVE.W (A0)+,D0 |
MOVE.W (A0)+,D0 |
||
MyData: |
MyData: |
||
include "dataTables.inc" ;a list of defined data constants that aren't supposed to be executed as instructions</ |
include "dataTables.inc" ;a list of defined data constants that aren't supposed to be executed as instructions</syntaxhighlight> |
||
Since there was no control flow instruction stopping the program counter from reaching the included file, ''the bytes stored in it will be executed as though they were genuine Motorola 68000 CPU instructions, even if they're not.'' The CPU cannot tell the difference between data and instructions, and thus the programmer must ensure that the program counter never reaches anything that wasn't meant to be executed. The easiest fix for this would be: |
Since there was no control flow instruction stopping the program counter from reaching the included file, ''the bytes stored in it will be executed as though they were genuine Motorola 68000 CPU instructions, even if they're not.'' The CPU cannot tell the difference between data and instructions, and thus the programmer must ensure that the program counter never reaches anything that wasn't meant to be executed. The easiest fix for this would be: |
||
< |
<syntaxhighlight lang="68000devpac">foo: |
||
LEA myData,A0 |
LEA myData,A0 |
||
MOVE.W (A0)+,D0 |
MOVE.W (A0)+,D0 |
||
Line 96: | Line 96: | ||
MyData: |
MyData: |
||
include "dataTables.inc" ;a list of defined data constants that aren't supposed to be executed as instructions</ |
include "dataTables.inc" ;a list of defined data constants that aren't supposed to be executed as instructions</syntaxhighlight> |
||
=={{header|AArch64 Assembly}}== |
=={{header|AArch64 Assembly}}== |
||
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
{{works with|as|Raspberry Pi 3B version Buster 64 bits}} |
||
<syntaxhighlight lang="aarch64 assembly"> |
|||
<lang AArch64 Assembly> |
|||
'file constant include : includeConstantesARM64.inc' |
'file constant include : includeConstantesARM64.inc' |
||
/*******************************************/ |
/*******************************************/ |
||
Line 528: | Line 528: | ||
.include "../includeARM64.inc" |
.include "../includeARM64.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ACL2}}== |
=={{header|ACL2}}== |
||
For files containing only events (definitions and similar; no top-level function calls) which are admissible (note the lack of file extension): |
For files containing only events (definitions and similar; no top-level function calls) which are admissible (note the lack of file extension): |
||
< |
<syntaxhighlight lang="lisp">(include-book "filename")</syntaxhighlight> |
||
For all other files: |
For all other files: |
||
< |
<syntaxhighlight lang="lisp">(ld "filename.lisp")</syntaxhighlight> |
||
=={{header|Action!}}== |
=={{header|Action!}}== |
||
< |
<syntaxhighlight lang="action!">INCLUDE "D2:REAL.ACT" ;from the Action! Tool Kit |
||
PROC Main() |
PROC Main() |
||
RETURN</ |
RETURN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Include_a_file.png Screenshot from Atari 8-bit computer] |
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Include_a_file.png Screenshot from Atari 8-bit computer] |
||
Line 551: | Line 551: | ||
Some remarks are necessary here. |
Some remarks are necessary here. |
||
Ada does not define how the source code is stored in files. The language rather talks about compilation units. A compilation unit "imports" another compilation unit by using context clauses - these have the syntax "with CU1, CU2, ...;". All compilers I know of require in their standard mode exactly one compilation unit per file; also file naming conventions vary. However GNAT e.g. has a mode that can deal with files holding several compilation units and any file name conventions. |
Ada does not define how the source code is stored in files. The language rather talks about compilation units. A compilation unit "imports" another compilation unit by using context clauses - these have the syntax "with CU1, CU2, ...;". All compilers I know of require in their standard mode exactly one compilation unit per file; also file naming conventions vary. However GNAT e.g. has a mode that can deal with files holding several compilation units and any file name conventions. |
||
< |
<syntaxhighlight lang="ada">with Ada.Text_IO, Another_Package; use Ada.Text_IO; |
||
-- the with-clause tells the compiler to include the Text_IO package from the Ada standard |
-- the with-clause tells the compiler to include the Text_IO package from the Ada standard |
||
-- and Another_Package. Subprograms from these packages may be called as follows: |
-- and Another_Package. Subprograms from these packages may be called as follows: |
||
Line 557: | Line 557: | ||
-- Another_Package.Do_Something("some text"); |
-- Another_Package.Do_Something("some text"); |
||
-- The use-clause allows the program author to write a subprogram call shortly as |
-- The use-clause allows the program author to write a subprogram call shortly as |
||
-- Put_Line("some text");</ |
-- Put_Line("some text");</syntaxhighlight> |
||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
Line 569: | Line 569: | ||
==={{header|ALGOL 68G}}=== |
==={{header|ALGOL 68G}}=== |
||
In the simplest case a file can be included as follows: |
In the simplest case a file can be included as follows: |
||
< |
<syntaxhighlight lang="algol68">PR read "file.a68" PR</syntaxhighlight> |
||
But in the Algol68 formal reports - it appears - the intention was to have a more structure approach. |
But in the Algol68 formal reports - it appears - the intention was to have a more structure approach. |
||
Line 575: | Line 575: | ||
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}} |
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.7 algol68g-2.7].}} |
||
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}} |
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}} |
||
'''File: prelude/test.a68'''< |
'''File: prelude/test.a68'''<syntaxhighlight lang="algol68"># -*- coding: utf-8 -*- # |
||
BEGIN |
BEGIN |
||
# Exception setup code: # |
# Exception setup code: # |
||
on value error(stand out, (REF FILE f)BOOL: GOTO value error not mended); |
on value error(stand out, (REF FILE f)BOOL: GOTO value error not mended); |
||
# Block setup code: # |
# Block setup code: # |
||
printf(($"Prelude test:"l$))</ |
printf(($"Prelude test:"l$))</syntaxhighlight>'''File: postlude/test.a68'''<syntaxhighlight lang="algol68"># -*- coding: utf-8 -*- # |
||
# Block teardown code: # |
# Block teardown code: # |
||
printf(($"Postlude test."l$)) |
printf(($"Postlude test."l$)) |
||
Line 586: | Line 586: | ||
# Exception code: # |
# Exception code: # |
||
value error not mended: SKIP |
value error not mended: SKIP |
||
END</ |
END</syntaxhighlight>'''File: test/include.a68'''<syntaxhighlight lang="algol68">#!/usr/bin/a68g --script # |
||
# -*- coding: utf-8 -*- # |
# -*- coding: utf-8 -*- # |
||
PR read "prelude/test.a68" PR; |
PR read "prelude/test.a68" PR; |
||
printf($4x"Hello, world!"l$); |
printf($4x"Hello, world!"l$); |
||
PR read "postlude/test.a68" PR</ |
PR read "postlude/test.a68" PR</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
Line 647: | Line 647: | ||
''' Example of <code>ENVIRON</code> clause '''<br> |
''' Example of <code>ENVIRON</code> clause '''<br> |
||
A file called ''mylib.a68'': |
A file called ''mylib.a68'': |
||
< |
<syntaxhighlight lang="algol68">BEGIN |
||
INT dim = 3; # a constant # |
INT dim = 3; # a constant # |
||
INT a number := 120; # a variable # |
INT a number := 120; # a variable # |
||
Line 655: | Line 655: | ||
a number := ENVIRON EXAMPLE2; |
a number := ENVIRON EXAMPLE2; |
||
print((a number)) |
print((a number)) |
||
END</ |
END</syntaxhighlight> |
||
''' Example of <code>USING</code> clause '''<br> |
''' Example of <code>USING</code> clause '''<br> |
||
A file called ''usemylib.a68'': |
A file called ''usemylib.a68'': |
||
< |
<syntaxhighlight lang="algol68">USING EXAMPLE2 FROM "mylib" |
||
BEGIN |
BEGIN |
||
MATRIX m2; # example only # |
MATRIX m2; # example only # |
||
Line 666: | Line 666: | ||
ENVIRON EXAMPLE3; # ENVIRONs can be nested # |
ENVIRON EXAMPLE3; # ENVIRONs can be nested # |
||
666 |
666 |
||
END</ |
END</syntaxhighlight> |
||
=={{header|AntLang}}== |
=={{header|AntLang}}== |
||
AntLang is made for interactive programming, but a way to load files exists. |
AntLang is made for interactive programming, but a way to load files exists. |
||
Even if it is really primitive, i. e. file get's current environment and manipulates it. |
Even if it is really primitive, i. e. file get's current environment and manipulates it. |
||
< |
<syntaxhighlight lang="antlang">load["script.ant"]</syntaxhighlight> |
||
=={{header|Applesoft BASIC}}== |
=={{header|Applesoft BASIC}}== |
||
Chain PROGRAM TWO to PROGRAM ONE. First create and save PROGRAM TWO. Then, create PROGRAM ONE and run it. PROGRAM ONE runs and then "includes" PROGRAM TWO which is loaded and run using the Binary program CHAIN from the DOS 3.3 System Master. Variables from PROGRAM ONE are not cleared so they can be used in PROGRAM TWO. User defined functions should be redefined in PROGRAM TWO. See "Applesoft: CHAIN and user-defined functions Issues" http://support.apple.com/kb/TA41069 |
Chain PROGRAM TWO to PROGRAM ONE. First create and save PROGRAM TWO. Then, create PROGRAM ONE and run it. PROGRAM ONE runs and then "includes" PROGRAM TWO which is loaded and run using the Binary program CHAIN from the DOS 3.3 System Master. Variables from PROGRAM ONE are not cleared so they can be used in PROGRAM TWO. User defined functions should be redefined in PROGRAM TWO. See "Applesoft: CHAIN and user-defined functions Issues" http://support.apple.com/kb/TA41069 |
||
< |
<syntaxhighlight lang="applesoftbasic}"> 10 REMPROGRAM TWO |
||
20 DEF FN A(X) = X * Y |
20 DEF FN A(X) = X * Y |
||
30 PRINT FN A(2) |
30 PRINT FN A(2) |
||
SAVE PROGRAM TWO</ |
SAVE PROGRAM TWO</syntaxhighlight> |
||
< |
<syntaxhighlight lang="applesoftbasic}"> 10 REMPROGRAM ONE |
||
20 Y = 6 |
20 Y = 6 |
||
30 DEF FN A(X) = X * Y |
30 DEF FN A(X) = X * Y |
||
Line 690: | Line 690: | ||
SAVE PROGRAM ONE |
SAVE PROGRAM ONE |
||
RUN</ |
RUN</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 701: | Line 701: | ||
=={{header|ARM Assembly}}== |
=={{header|ARM Assembly}}== |
||
{{works with|as|Raspberry Pi}} |
{{works with|as|Raspberry Pi}} |
||
<syntaxhighlight lang="arm assembly"> |
|||
<lang ARM Assembly> |
|||
'file constantes.inc' |
'file constantes.inc' |
||
/************************************/ |
/************************************/ |
||
Line 1,141: | Line 1,141: | ||
.include "./affichage.inc" |
.include "./affichage.inc" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Arturo}}== |
=={{header|Arturo}}== |
||
< |
<syntaxhighlight lang="rebol">; import a file |
||
do.import {file.art} |
do.import {file.art} |
||
; import another file |
; import another file |
||
; from relative folder location |
; from relative folder location |
||
do.import relative "another_file.art"</ |
do.import relative "another_file.art"</syntaxhighlight> |
||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
<syntaxhighlight lang="autohotkey"> |
|||
<lang AutoHotkey> |
|||
#Include FileOrDirName |
#Include FileOrDirName |
||
#IncludeAgain FileOrDirName |
#IncludeAgain FileOrDirName |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
Line 1,162: | Line 1,162: | ||
The awk extraction and reporting language does not support the use of include files. However, it is possible to provide the name of more than one source file at the command line: |
The awk extraction and reporting language does not support the use of include files. However, it is possible to provide the name of more than one source file at the command line: |
||
< |
<syntaxhighlight lang="sh">awk -f one.awk -f two.awk</syntaxhighlight> |
||
The functions defined in different source files will be visible from other scripts called from the same command line: |
The functions defined in different source files will be visible from other scripts called from the same command line: |
||
< |
<syntaxhighlight lang="awk"># one.awk |
||
BEGIN { |
BEGIN { |
||
sayhello() |
sayhello() |
||
Line 1,174: | Line 1,174: | ||
function sayhello() { |
function sayhello() { |
||
print "Hello world" |
print "Hello world" |
||
}</ |
}</syntaxhighlight> |
||
However, it is not permissible to pass the name of additional source files through a hashbang line, so the following will will not work: |
However, it is not permissible to pass the name of additional source files through a hashbang line, so the following will will not work: |
||
Line 1,183: | Line 1,183: | ||
GNU Awk has an <code>@include</code> which can include another awk source file at that point in the code. |
GNU Awk has an <code>@include</code> which can include another awk source file at that point in the code. |
||
< |
<syntaxhighlight lang="awk">@include "filename.awk"</syntaxhighlight> |
||
This is a parser-level construct and so must be a literal filename, not a variable or expression. If the filename is not absolute then it's sought in an <code>$AWKPATH</code> list of directories. See [http://www.gnu.org/software/gawk/manual/html_node/Include-Files.html the gawk manual] for more. |
This is a parser-level construct and so must be a literal filename, not a variable or expression. If the filename is not absolute then it's sought in an <code>$AWKPATH</code> list of directories. See [http://www.gnu.org/software/gawk/manual/html_node/Include-Files.html the gawk manual] for more. |
||
Line 1,189: | Line 1,189: | ||
=={{header|Axe}}== |
=={{header|Axe}}== |
||
This will cause the program called OTHER to be parsed as if it was contained in the source code instead of this line. |
This will cause the program called OTHER to be parsed as if it was contained in the source code instead of this line. |
||
<lang |
<syntaxhighlight lang="axe">prgmOTHER</syntaxhighlight> |
||
=={{header|BaCon}}== |
=={{header|BaCon}}== |
||
''other.bac'' |
''other.bac'' |
||
< |
<syntaxhighlight lang="freebasic">other = 42</syntaxhighlight> |
||
''including.bac'' |
''including.bac'' |
||
< |
<syntaxhighlight lang="freebasic">' Include a file |
||
INCLUDE "other.bac" |
INCLUDE "other.bac" |
||
PRINT other</ |
PRINT other</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,214: | Line 1,214: | ||
Note that this will ''not'' work under QBasic. |
Note that this will ''not'' work under QBasic. |
||
< |
<syntaxhighlight lang="qbasic">REM $INCLUDE: 'file.bi' |
||
'$INCLUDE: 'file.bi'</ |
'$INCLUDE: 'file.bi'</syntaxhighlight> |
||
See also: [[#BBC BASIC|BBC BASIC]], [[#Gambas|Gambas]], [[#IWBASIC|IWBASIC]], [[#PowerBASIC|PowerBASIC]], [[#PureBasic|PureBasic]], [[#Run BASIC|Run BASIC]], [[#ZX Spectrum Basic|ZX Spectrum Basic]] |
See also: [[#BBC BASIC|BBC BASIC]], [[#Gambas|Gambas]], [[#IWBASIC|IWBASIC]], [[#PowerBASIC|PowerBASIC]], [[#PureBasic|PureBasic]], [[#Run BASIC|Run BASIC]], [[#ZX Spectrum Basic|ZX Spectrum Basic]] |
||
=={{header|Batch File}}== |
=={{header|Batch File}}== |
||
< |
<syntaxhighlight lang="dos"> |
||
call file2.bat |
call file2.bat |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|BBC BASIC}}== |
=={{header|BBC BASIC}}== |
||
{{works with|BBC BASIC for Windows}} |
{{works with|BBC BASIC for Windows}} |
||
<lang |
<syntaxhighlight lang="bbcbasic"> CALL filepath$</syntaxhighlight> |
||
The file is loaded into memory at run-time, executed, and then discarded. It must be in 'tokenised' (internal) .BBC format. |
The file is loaded into memory at run-time, executed, and then discarded. It must be in 'tokenised' (internal) .BBC format. |
||
=={{header|Bracmat}}== |
=={{header|Bracmat}}== |
||
< |
<syntaxhighlight lang="bracmat">get$"<i>module</i>"</syntaxhighlight> |
||
=={{header|C}} / {{header|C++}}== |
=={{header|C}} / {{header|C++}}== |
||
Line 1,236: | Line 1,236: | ||
In C and C++, inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
In C and C++, inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
||
< |
<syntaxhighlight lang="c">/* Standard and other library header names are enclosed between chevrons */ |
||
#include <stdlib.h> |
#include <stdlib.h> |
||
/* User/in-project header names are usually enclosed between double-quotes */ |
/* User/in-project header names are usually enclosed between double-quotes */ |
||
#include "myutil.h" |
#include "myutil.h" |
||
</syntaxhighlight> |
|||
</lang> |
|||
< |
<syntaxhighlight lang="cpp">/* In C++20,you can use the import statement */ |
||
import <iostream>; |
import <iostream>; |
||
</syntaxhighlight> |
|||
</lang> |
|||
Although it is often conventional and idiomatic for a project to use its own headers in the style described on the second line above, it's also possible to tell most compilers using various flags (e. g. GCC and Clang accept <tt>-I</tt>) to treat an arbitrary directory as a system/library include folder, thereby allowing any contained files to be included using the angle bracket syntax. |
Although it is often conventional and idiomatic for a project to use its own headers in the style described on the second line above, it's also possible to tell most compilers using various flags (e. g. GCC and Clang accept <tt>-I</tt>) to treat an arbitrary directory as a system/library include folder, thereby allowing any contained files to be included using the angle bracket syntax. |
||
=={{header|C sharp}}== |
=={{header|C sharp}}== |
||
< |
<syntaxhighlight lang="csharp">/* The C# language specification does not give a mechanism for 'including' one source file within another, |
||
* likely because there is no need - all code compiled within one 'assembly' (individual IDE projects |
* likely because there is no need - all code compiled within one 'assembly' (individual IDE projects |
||
* are usually compiled to separate assemblies) can 'see' all other code within that assembly. |
* are usually compiled to separate assemblies) can 'see' all other code within that assembly. |
||
*/</ |
*/</syntaxhighlight> |
||
=={{header|ChucK}}== |
=={{header|ChucK}}== |
||
<lang>Machine.add(me.dir() + "/MyOwnClassesDefinitions.ck");</ |
<syntaxhighlight lang="text">Machine.add(me.dir() + "/MyOwnClassesDefinitions.ck");</syntaxhighlight> |
||
=={{header|Clipper}}== |
=={{header|Clipper}}== |
||
The inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
The inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
||
< |
<syntaxhighlight lang="clipper"> #include "inkey.ch" </syntaxhighlight> |
||
=={{header|Clojure}}== |
=={{header|Clojure}}== |
||
Just as in Common Lisp: |
Just as in Common Lisp: |
||
< |
<syntaxhighlight lang="clojure">(load "path/to/file")</syntaxhighlight> |
||
This would rarely be used for loading code though, since Clojure supports modularisation (like most modern languages) through [http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html namespaces] and code is typically located/loaded via related abstractions. It's probably more often used to load data or used for quick-and-dirty experiments in the [https://en.wikipedia.org/wiki/Read–eval–print_loop REPL]. |
This would rarely be used for loading code though, since Clojure supports modularisation (like most modern languages) through [http://blog.8thlight.com/colin-jones/2010/12/05/clojure-libs-and-namespaces-require-use-import-and-ns.html namespaces] and code is typically located/loaded via related abstractions. It's probably more often used to load data or used for quick-and-dirty experiments in the [https://en.wikipedia.org/wiki/Read–eval–print_loop REPL]. |
||
Line 1,269: | Line 1,269: | ||
=={{header|COBOL}}== |
=={{header|COBOL}}== |
||
In COBOL, code is included from other files by the <code>COPY</code> statement. The files are called copybooks, normally end with the file extension '.cpy' and may contain ''any'' valid COBOL syntax. The <code>COPY</code> statement takes an optional <code>REPLACING</code> clause allows any text within the copybook to be replaced with something else. |
In COBOL, code is included from other files by the <code>COPY</code> statement. The files are called copybooks, normally end with the file extension '.cpy' and may contain ''any'' valid COBOL syntax. The <code>COPY</code> statement takes an optional <code>REPLACING</code> clause allows any text within the copybook to be replaced with something else. |
||
< |
<syntaxhighlight lang="cobol">COPY "copy.cpy". *> The full stop is mandatory, wherever the COPY is. |
||
COPY "another-copy.cpy" REPLACING foo BY bar |
COPY "another-copy.cpy" REPLACING foo BY bar |
||
SPACE BY ZERO |
SPACE BY ZERO |
||
==text to replace== BY ==replacement text==.</ |
==text to replace== BY ==replacement text==.</syntaxhighlight> |
||
=={{header|Common Lisp}}== |
=={{header|Common Lisp}}== |
||
< |
<syntaxhighlight lang="lisp">(load "path/to/file")</syntaxhighlight> |
||
=={{header|Crystal}}== |
=={{header|Crystal}}== |
||
< |
<syntaxhighlight lang="crystal">require "socket" # includes a file from standard library or /lib relative to current directory |
||
require "./myfile" # includes a file relative to current directory</ |
require "./myfile" # includes a file relative to current directory</syntaxhighlight> |
||
=={{header|D}}== |
=={{header|D}}== |
||
D has a module system, so usually there is no need of a textual inclusion of a text file: |
D has a module system, so usually there is no need of a textual inclusion of a text file: |
||
<lang |
<syntaxhighlight lang="d">import std.stdio;</syntaxhighlight> |
||
To perform a textual inclusion: |
To perform a textual inclusion: |
||
< |
<syntaxhighlight lang="d">mixin(import("code.txt"));</syntaxhighlight> |
||
At the expression level, e.g for large ubyte and char arrays: |
At the expression level, e.g for large ubyte and char arrays: |
||
< |
<syntaxhighlight lang="d">static immutable array = import("data.txt");</syntaxhighlight> |
||
=={{header|Delphi}}== |
=={{header|Delphi}}== |
||
< |
<syntaxhighlight lang="delphi">uses SysUtils; // Lets you use the contents of SysUtils.pas from the current unit |
||
{$Include Common} // Inserts the contents of Common.pas into the current unit |
{$Include Common} // Inserts the contents of Common.pas into the current unit |
||
{$I Common} // Same as the previous line, but in a shorter form</ |
{$I Common} // Same as the previous line, but in a shorter form</syntaxhighlight> |
||
=={{header|Dragon}}== |
=={{header|Dragon}}== |
||
Line 1,301: | Line 1,301: | ||
Just this would be enough. |
Just this would be enough. |
||
<lang>func my(){ |
<syntaxhighlight lang="text">func my(){ |
||
showln "hello" |
showln "hello" |
||
//this is program.dgn |
//this is program.dgn |
||
}</ |
}</syntaxhighlight> |
||
<lang> |
<syntaxhighlight lang="text"> |
||
include "program.dgn" |
include "program.dgn" |
||
my() // output : hello |
my() // output : hello |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|DWScript}}== |
=={{header|DWScript}}== |
||
In addition to straight inclusion, there is a filtered inclusion, in which the include file goes through a pre-processing filter. |
In addition to straight inclusion, there is a filtered inclusion, in which the include file goes through a pre-processing filter. |
||
<syntaxhighlight lang="delphi"> |
|||
<lang Delphi> |
|||
{$INCLUDE Common} // Inserts the contents of Common.pas into the current unit |
{$INCLUDE Common} // Inserts the contents of Common.pas into the current unit |
||
{$I Common} // Same as the previous line, but in a shorter form |
{$I Common} // Same as the previous line, but in a shorter form |
||
Line 1,320: | Line 1,320: | ||
{$FILTER Common} // Inserts the contents of Common.pas into the current unit after filtering |
{$FILTER Common} // Inserts the contents of Common.pas into the current unit after filtering |
||
{$F Common} // Same as the previous line, but in a shorter form |
{$F Common} // Same as the previous line, but in a shorter form |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Déjà Vu}}== |
=={{header|Déjà Vu}}== |
||
< |
<syntaxhighlight lang="dejavu">#with the module system: |
||
!import!foo |
!import!foo |
||
#passing a file name (only works with compiled bytecode files): |
#passing a file name (only works with compiled bytecode files): |
||
!run-file "/path/file.vu"</ |
!run-file "/path/file.vu"</syntaxhighlight> |
||
=={{header|Emacs Lisp}}== |
=={{header|Emacs Lisp}}== |
||
Write this code in: file1.el |
Write this code in: file1.el |
||
<syntaxhighlight lang="emacs lisp"> |
|||
<lang Emacs Lisp> |
|||
(defun sum (ls) |
(defun sum (ls) |
||
(apply '+ ls) ) |
(apply '+ ls) ) |
||
</syntaxhighlight> |
|||
</lang> |
|||
In the directory of file1.el, we write this new code in: file2.el |
In the directory of file1.el, we write this new code in: file2.el |
||
<syntaxhighlight lang="emacs lisp"> |
|||
<lang Emacs Lisp> |
|||
(add-to-list 'load-path "./") |
(add-to-list 'load-path "./") |
||
(load "./file1.el") |
(load "./file1.el") |
||
(insert (format "%d" (sum (number-sequence 1 100) ))) |
(insert (format "%d" (sum (number-sequence 1 100) ))) |
||
</syntaxhighlight> |
|||
</lang> |
|||
<b>Output:</b> |
<b>Output:</b> |
||
<pre> |
<pre> |
||
Line 1,347: | Line 1,347: | ||
=={{header|Erlang}}== |
=={{header|Erlang}}== |
||
<syntaxhighlight lang="erlang"> |
|||
<lang Erlang> |
|||
-include("my_header.hrl"). % Includes the file at my_header.erl |
-include("my_header.hrl"). % Includes the file at my_header.erl |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Euphoria}}== |
=={{header|Euphoria}}== |
||
<syntaxhighlight lang="euphoria"> |
|||
<lang Euphoria> |
|||
include my_header.e |
include my_header.e |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Factor}}== |
=={{header|Factor}}== |
||
<syntaxhighlight lang="factor"> |
|||
<lang Factor> |
|||
USING: vocaba vocabb... ; |
USING: vocaba vocabb... ; |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Forth}}== |
=={{header|Forth}}== |
||
<lang |
<syntaxhighlight lang="forth">include matrix.fs</syntaxhighlight> |
||
Other Forth systems have a smarter word, which protects against multiple inclusion. The name varies: '''USES''', '''REQUIRE''', '''NEEDS'''. |
Other Forth systems have a smarter word, which protects against multiple inclusion. The name varies: '''USES''', '''REQUIRE''', '''NEEDS'''. |
||
=={{header|Fortran}}== |
=={{header|Fortran}}== |
||
<lang |
<syntaxhighlight lang="fortran">include ''char-literal-constant''</syntaxhighlight> |
||
"The interpretation of char-literal-constant is processor dependent. An example of a possible valid interpretation is that char-literal-constant is the name of a file that contains the source text to be included." |
"The interpretation of char-literal-constant is processor dependent. An example of a possible valid interpretation is that char-literal-constant is the name of a file that contains the source text to be included." |
||
Line 1,378: | Line 1,378: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
File to be included : |
File to be included : |
||
< |
<syntaxhighlight lang="freebasic">' person.bi file |
||
Type Person |
Type Person |
||
name As String |
name As String |
||
Line 1,387: | Line 1,387: | ||
Operator Person.Cast() As String |
Operator Person.Cast() As String |
||
Return "[" + This.name + ", " + Str(This.age) + "]" |
Return "[" + This.name + ", " + Str(This.age) + "]" |
||
End Operator</ |
End Operator</syntaxhighlight> |
||
Main file : |
Main file : |
||
< |
<syntaxhighlight lang="freebasic">' FB 1.05.0 Win 64 |
||
' main.bas file |
' main.bas file |
||
Line 1,401: | Line 1,401: | ||
Print |
Print |
||
Print "Press any key to quit" |
Print "Press any key to quit" |
||
Sleep</ |
Sleep</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,419: | Line 1,419: | ||
=={{header|FutureBasic}}== |
=={{header|FutureBasic}}== |
||
FB has powerful tools to include files in a project. Its "include resources" statement allows you to specify any number of files for copying into the built application package's Contents/Resources/ directory. |
FB has powerful tools to include files in a project. Its "include resources" statement allows you to specify any number of files for copying into the built application package's Contents/Resources/ directory. |
||
< |
<syntaxhighlight lang="futurebasic"> |
||
include resources "SomeImage.png" |
include resources "SomeImage.png" |
||
include resources "SomeMovie.mpeg" |
include resources "SomeMovie.mpeg" |
||
Line 1,425: | Line 1,425: | ||
include resources "SomeIcon.icns" |
include resources "SomeIcon.icns" |
||
include resources "Info.plist" //Custom preference file to replace FB's generic app preferences |
include resources "Info.plist" //Custom preference file to replace FB's generic app preferences |
||
</syntaxhighlight> |
|||
</lang> |
|||
Including C or Objective-C headers (i.e. files with the .h extension) or source files (files with the .c or .m extension) requires a different 'include' syntax: |
Including C or Objective-C headers (i.e. files with the .h extension) or source files (files with the .c or .m extension) requires a different 'include' syntax: |
||
<pre> |
<pre> |
||
Line 1,489: | Line 1,489: | ||
Here a file is loaded into a variable |
Here a file is loaded into a variable |
||
< |
<syntaxhighlight lang="gambas">Public Sub Form_Open() |
||
Dim sFile As String |
Dim sFile As String |
||
Line 1,495: | Line 1,495: | ||
End |
End |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|GAP}}== |
=={{header|GAP}}== |
||
< |
<syntaxhighlight lang="gap">Read("file");</syntaxhighlight> |
||
=={{header|Gnuplot}}== |
=={{header|Gnuplot}}== |
||
< |
<syntaxhighlight lang="gnuplot">load "filename.gnuplot"</syntaxhighlight> |
||
This is the same as done for each file named on the command line. Special filename <code>"-"</code> reads from standard input. |
This is the same as done for each file named on the command line. Special filename <code>"-"</code> reads from standard input. |
||
< |
<syntaxhighlight lang="gnuplot">load "-" # read standard input</syntaxhighlight> |
||
If the system has <code>popen</code> then piped output from another program can be loaded, |
If the system has <code>popen</code> then piped output from another program can be loaded, |
||
< |
<syntaxhighlight lang="gnuplot">load "< myprogram" # run myprogram, read its output |
||
load "< echo print 123"</ |
load "< echo print 123"</syntaxhighlight> |
||
<code>call</code> is the same as <code>load</code> but takes parameters which are then available to the sub-script as <code>$0</code> through <code>$9</code> |
<code>call</code> is the same as <code>load</code> but takes parameters which are then available to the sub-script as <code>$0</code> through <code>$9</code> |
||
< |
<syntaxhighlight lang="gnuplot">call "filename.gnuplot" 123 456 "arg3"</syntaxhighlight> |
||
=={{header|Go}}== |
=={{header|Go}}== |
||
Line 1,520: | Line 1,520: | ||
Instead one can simply give the other source code file(s) the same package name as the 'main' file, copy them to the same directory and build them all together. For example: |
Instead one can simply give the other source code file(s) the same package name as the 'main' file, copy them to the same directory and build them all together. For example: |
||
< |
<syntaxhighlight lang="go">// main.go |
||
package main |
package main |
||
Line 1,532: | Line 1,532: | ||
hello() |
hello() |
||
hello2() |
hello2() |
||
}</ |
}</syntaxhighlight> |
||
< |
<syntaxhighlight lang="go">// main2.go |
||
package main |
package main |
||
Line 1,541: | Line 1,541: | ||
func hello2() { |
func hello2() { |
||
fmt.Println("Hello from main2.go") |
fmt.Println("Hello from main2.go") |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,553: | Line 1,553: | ||
=={{header|Harbour}}== |
=={{header|Harbour}}== |
||
The inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
The inclusion of other files is achieved via a preprocessor. The <code>#include</code> preprocessor directive tells the compiler to incorporate code from the included file. This is normally used near the top of a source file and is usually used to tell the compiler to include header files for the function libraries. |
||
< |
<syntaxhighlight lang="visualfoxpro">#include "inkey.ch"</syntaxhighlight> |
||
=={{header|Haskell}}== |
=={{header|Haskell}}== |
||
< |
<syntaxhighlight lang="haskell">-- Due to Haskell's module system, textual includes are rarely needed. In |
||
-- general, one will import a module, like so: |
-- general, one will import a module, like so: |
||
import SomeModule |
import SomeModule |
||
Line 1,563: | Line 1,563: | ||
-- Haskell Compiler runs the C preprocessor on source code, so #include may be |
-- Haskell Compiler runs the C preprocessor on source code, so #include may be |
||
-- used: |
-- used: |
||
#include "SomeModule.hs"</ |
#include "SomeModule.hs"</syntaxhighlight> |
||
=={{header|HTML}}== |
=={{header|HTML}}== |
||
Line 1,569: | Line 1,569: | ||
Current HTML specifications do not provide an include tag, Currently, in order to include content from another file, it is necessary to include content via an iframe. However, this is not supported in some browsers and looks very untidy in other browsers: |
Current HTML specifications do not provide an include tag, Currently, in order to include content from another file, it is necessary to include content via an iframe. However, this is not supported in some browsers and looks very untidy in other browsers: |
||
< |
<syntaxhighlight lang="html"><iframe src="foobar.html"> |
||
Sorry: Your browser cannot show the included content.</iframe></ |
Sorry: Your browser cannot show the included content.</iframe></syntaxhighlight> |
||
There is an unofficial tag, but this will be ignored by most browsers: |
There is an unofficial tag, but this will be ignored by most browsers: |
||
<lang |
<syntaxhighlight lang="html"><include>foobar.html</include></syntaxhighlight> |
||
=={{header|Icon}} and {{header|Unicon}}== |
=={{header|Icon}} and {{header|Unicon}}== |
||
Include another file of source code using the preprocessor statement: < |
Include another file of source code using the preprocessor statement: <syntaxhighlight lang="icon">$include "filename.icn"</syntaxhighlight> |
||
=={{header|IWBASIC}}== |
=={{header|IWBASIC}}== |
||
< |
<syntaxhighlight lang="iwbasic">$INCLUDE "ishelllink.inc"</syntaxhighlight> |
||
Further, external library or object files can be specified with the $USE statement, which is a compiler preprocessor command: |
Further, external library or object files can be specified with the $USE statement, which is a compiler preprocessor command: |
||
< |
<syntaxhighlight lang="iwbasic">$USE "libraries\\mylib.lib"</syntaxhighlight> |
||
IWBASIC also allows resources, files and data that are compiled with an application and embedded in the executable. However, resources in IWBASIC may be used only for projects, i.e., programs that have more than one source file. |
IWBASIC also allows resources, files and data that are compiled with an application and embedded in the executable. However, resources in IWBASIC may be used only for projects, i.e., programs that have more than one source file. |
||
Line 1,591: | Line 1,591: | ||
Various resources are loaded as follows: |
Various resources are loaded as follows: |
||
< |
<syntaxhighlight lang="iwbasic">Success=LOADRESOURCE(ID,Type,Variable)</syntaxhighlight> |
||
<code>ID</code> is either a numeric or string identifier to the resource, <code>TYPE</code> is a numeric or string type and it stores the info in variable. The standard Windows resource types can be specified and loaded in raw form using the following constants: |
<code>ID</code> is either a numeric or string identifier to the resource, <code>TYPE</code> is a numeric or string type and it stores the info in variable. The standard Windows resource types can be specified and loaded in raw form using the following constants: |
||
< |
<syntaxhighlight lang="iwbasic">@RESCURSOR |
||
@RESBITMAP |
@RESBITMAP |
||
@RESICON |
@RESICON |
||
Line 1,606: | Line 1,606: | ||
@RESGROUPCURSOR |
@RESGROUPCURSOR |
||
@RESGROUPICON |
@RESGROUPICON |
||
@RESVERSION</ |
@RESVERSION</syntaxhighlight> |
||
=={{header|J}}== |
=={{header|J}}== |
||
Line 1,612: | Line 1,612: | ||
The usual approach for a file named 'myheader.ijs' would be: |
The usual approach for a file named 'myheader.ijs' would be: |
||
<lang |
<syntaxhighlight lang="j">require 'myheader.ijs'</syntaxhighlight> |
||
However, this has "include once" semantics, and if the requirement is to include the file even if it has been included earlier you would instead use: |
However, this has "include once" semantics, and if the requirement is to include the file even if it has been included earlier you would instead use: |
||
<lang |
<syntaxhighlight lang="j">load 'myheader.ijs'</syntaxhighlight> |
||
That said, the raw mechanism here would be <lang |
That said, the raw mechanism here would be <syntaxhighlight lang="j">0!:0<'myheader.ijs'</syntaxhighlight> and this form might be used in the unusual circumstance where the file <tt>myheader.ijs</tt> defined local variables and the scope of those local names was meant be larger than the context of the <code>load</code> verb. |
||
=={{header|Java}}== |
=={{header|Java}}== |
||
Line 1,624: | Line 1,624: | ||
Just this would be enough. |
Just this would be enough. |
||
< |
<syntaxhighlight lang="java">public class Class1 extends Class2 |
||
{ |
{ |
||
//code here |
//code here |
||
}</ |
}</syntaxhighlight> |
||
You could also consider creating an instance of Class2 within Class1, and then using the instance methods. |
You could also consider creating an instance of Class2 within Class1, and then using the instance methods. |
||
< |
<syntaxhighlight lang="java">public class Class1 |
||
{ |
{ |
||
Class2 c2=new Class2(); |
Class2 c2=new Class2(); |
||
Line 1,638: | Line 1,638: | ||
c2.func2(); |
c2.func2(); |
||
} |
} |
||
}</ |
}</syntaxhighlight> |
||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |
||
Line 1,644: | Line 1,644: | ||
===Pure JavaScript in browsers with the DOM=== |
===Pure JavaScript in browsers with the DOM=== |
||
Following example, if loaded in an HTML file, loads the [http://jquery.com/ jQuery] library from a remote site |
Following example, if loaded in an HTML file, loads the [http://jquery.com/ jQuery] library from a remote site |
||
< |
<syntaxhighlight lang="javascript">var s = document.createElement('script'); |
||
s.type = 'application/javascript'; |
s.type = 'application/javascript'; |
||
// path to the desired file |
// path to the desired file |
||
s.src = 'http://code.jquery.com/jquery-1.6.2.js'; |
s.src = 'http://code.jquery.com/jquery-1.6.2.js'; |
||
document.body.appendChild(s);</ |
document.body.appendChild(s);</syntaxhighlight> |
||
Most be noted that it can also request [[HTTP]] source and eval() the source |
Most be noted that it can also request [[HTTP]] source and eval() the source |
||
===With jQuery=== |
===With jQuery=== |
||
{{libheader|jQuery}} |
{{libheader|jQuery}} |
||
< |
<syntaxhighlight lang="javascript">$.getScript("http://example.com/script.js");</syntaxhighlight> |
||
===With AMD (require.js)=== |
===With AMD (require.js)=== |
||
< |
<syntaxhighlight lang="javascript">require(["jquery"], function($) { /* ... */ });</syntaxhighlight> |
||
===CommonJS style with node.js (or browserify)=== |
===CommonJS style with node.js (or browserify)=== |
||
{{libheader|node.js}} |
{{libheader|node.js}} |
||
< |
<syntaxhighlight lang="javascript">var $ = require('$');</syntaxhighlight> |
||
===ES6 Modules=== |
===ES6 Modules=== |
||
< |
<syntaxhighlight lang="javascript">import $ from "jquery";</syntaxhighlight> |
||
=={{header|jq}}== |
=={{header|jq}}== |
||
Line 1,678: | Line 1,678: | ||
'''Include_a_file.jq''' |
'''Include_a_file.jq''' |
||
< |
<syntaxhighlight lang="jq">include "gort"; |
||
hello</ |
hello</syntaxhighlight> |
||
'''gort.jq''' |
'''gort.jq''' |
||
<lang>def hello: "Klaatu barada nikto";</ |
<syntaxhighlight lang="text">def hello: "Klaatu barada nikto";</syntaxhighlight> |
||
{{ out }} |
{{ out }} |
||
< |
<syntaxhighlight lang="sh">$ jq -n -c -f Include_a_file.jq |
||
Klaatu barada nikto.</ |
Klaatu barada nikto.</syntaxhighlight> |
||
=={{header|Jsish}}== |
=={{header|Jsish}}== |
||
''jsish'' can include other source via '''System.source('filename');'''. Versioned moduled can be included via '''System.require('module', version);'''. Methods in the ''System'' object are automatically exported as top level globals (and the module version argument defaults to 1), so those can be shortened to |
''jsish'' can include other source via '''System.source('filename');'''. Versioned moduled can be included via '''System.require('module', version);'''. Methods in the ''System'' object are automatically exported as top level globals (and the module version argument defaults to 1), so those can be shortened to |
||
< |
<syntaxhighlight lang="javascript">source('file'); |
||
require('module');</ |
require('module');</syntaxhighlight> |
||
Compiled code can also be included via '''System.load('shlib');''', but that feature requires a known named init function, Jsi_Init[shlib] to be an exported symbol in the Dynamic Shared Object file. |
Compiled code can also be included via '''System.load('shlib');''', but that feature requires a known named init function, Jsi_Init[shlib] to be an exported symbol in the Dynamic Shared Object file. |
||
Line 1,699: | Line 1,699: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
Julia's <code>include</code> function executes code from an arbitrary file: |
Julia's <code>include</code> function executes code from an arbitrary file: |
||
< |
<syntaxhighlight lang="julia">include("foo.jl")</syntaxhighlight> |
||
or alternatively <code>include_string</code> executes code in a string as if it were a file (and can optionally accept a filename to use in error messages etcetera). |
or alternatively <code>include_string</code> executes code in a string as if it were a file (and can optionally accept a filename to use in error messages etcetera). |
||
Julia also has a module system: |
Julia also has a module system: |
||
<lang |
<syntaxhighlight lang="julia">import MyModule</syntaxhighlight> |
||
imports the content of the module <code>MyModule.jl</code> (which should be of the form <code>module MyModule ... end</code>, whose symbols can be accessed as <code>MyModule.variable</code>, or alternatively |
imports the content of the module <code>MyModule.jl</code> (which should be of the form <code>module MyModule ... end</code>, whose symbols can be accessed as <code>MyModule.variable</code>, or alternatively |
||
<lang |
<syntaxhighlight lang="julia">using MyModule</syntaxhighlight> |
||
will import the module and all of its exported symbols |
will import the module and all of its exported symbols |
||
Line 1,714: | Line 1,714: | ||
For example: |
For example: |
||
< |
<syntaxhighlight lang="scala">fun f() = println("f called")</syntaxhighlight> |
||
We can now import and invoke this from code in the default package as follows: |
We can now import and invoke this from code in the default package as follows: |
||
< |
<syntaxhighlight lang="scala">// version 1.1.2 |
||
import package1.f // import f from package `package1` |
import package1.f // import f from package `package1` |
||
Line 1,724: | Line 1,724: | ||
fun main(args: Array<String>) { |
fun main(args: Array<String>) { |
||
f() // invoke f without qualification |
f() // invoke f without qualification |
||
}</ |
}</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 1,733: | Line 1,733: | ||
=={{header|LabVIEW}}== |
=={{header|LabVIEW}}== |
||
In LabVIEW, any VI can be used as a "SubVI" by changing the icon and wiring the terminals to the front panel. This cannot be explained concisely in code; instead, see the [http://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/creating_subvis/ documentation]. =={{header|LabVIEW}}== |
In LabVIEW, any VI can be used as a "SubVI" by changing the icon and wiring the terminals to the front panel. This cannot be explained concisely in code; instead, see the [http://zone.ni.com/reference/en-XX/help/371361E-01/lvconcepts/creating_subvis/ documentation]. =={{header|LabVIEW}}== |
||
< |
<syntaxhighlight lang="lasso">web_response -> include('my_file.inc')</syntaxhighlight> |
||
=={{header|Lasso}}== |
=={{header|Lasso}}== |
||
< |
<syntaxhighlight lang="lasso">include('myfile.lasso')</syntaxhighlight> |
||
=={{header|Lingo}}== |
=={{header|Lingo}}== |
||
< |
<syntaxhighlight lang="lingo">-- load Lingo code from file |
||
fp = xtra("fileIO").new() |
fp = xtra("fileIO").new() |
||
fp.openFile(_movie.path&"someinclude.ls", 1) |
fp.openFile(_movie.path&"someinclude.ls", 1) |
||
Line 1,752: | Line 1,752: | ||
-- use it instantly in the current script (i.e. the script that contained the above include code) |
-- use it instantly in the current script (i.e. the script that contained the above include code) |
||
script("someinclude").foo()</ |
script("someinclude").foo()</syntaxhighlight> |
||
=={{header|Logtalk}}== |
=={{header|Logtalk}}== |
||
< |
<syntaxhighlight lang="logtalk"> |
||
:- object(foo). |
:- object(foo). |
||
Line 1,761: | Line 1,761: | ||
:- end_object. |
:- end_object. |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
Line 1,767: | Line 1,767: | ||
To include a header file myheader.lua: |
To include a header file myheader.lua: |
||
< |
<syntaxhighlight lang="lua"> require "myheader" </syntaxhighlight> |
||
=={{header|M2000 Interpreter}}== |
=={{header|M2000 Interpreter}}== |
||
Without use of New in Load we get any cached file with same name. Using load from M2000 command line we always load file, but from code interpreter use a cache to hold it for next load. |
Without use of New in Load we get any cached file with same name. Using load from M2000 command line we always load file, but from code interpreter use a cache to hold it for next load. |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
Document A$={ |
Document A$={ |
||
Module Global Beta { |
Module Global Beta { |
||
Line 1,795: | Line 1,795: | ||
\\ now Beta erased (after return form Checkit) |
\\ now Beta erased (after return form Checkit) |
||
Print Module(Beta)=False |
Print Module(Beta)=False |
||
</syntaxhighlight> |
|||
</lang> |
|||
Running code of a module, as code is inline and not in that module. Now X is a variable in CheckIt |
Running code of a module, as code is inline and not in that module. Now X is a variable in CheckIt |
||
<syntaxhighlight lang="m2000 interpreter"> |
|||
<lang M2000 Interpreter> |
|||
\\ we can delete global |
\\ we can delete global |
||
Module Global alfa { |
Module Global alfa { |
||
Line 1,809: | Line 1,809: | ||
} |
} |
||
Checkit |
Checkit |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|m4}}== |
=={{header|m4}}== |
||
<lang |
<syntaxhighlight lang="m4">include(filename)</syntaxhighlight> |
||
=={{header|Maple}}== |
=={{header|Maple}}== |
||
For textual inclusion, analogous to the C preprocessor, use the "$include" preprocessor directive. (The preprocessor is not a separate program, however.) This is frequently useful for large project development. |
For textual inclusion, analogous to the C preprocessor, use the "$include" preprocessor directive. (The preprocessor is not a separate program, however.) This is frequently useful for large project development. |
||
<lang |
<syntaxhighlight lang="maple">$include <somefile></syntaxhighlight> |
||
Or |
Or |
||
< |
<syntaxhighlight lang="maple">$include "somefile"</syntaxhighlight> |
||
It is also possible to read a file, using the "read" statement. This has rather different semantics. |
It is also possible to read a file, using the "read" statement. This has rather different semantics. |
||
< |
<syntaxhighlight lang="maple">read "somefile":</syntaxhighlight> |
||
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
=={{header|Mathematica}} / {{header|Wolfram Language}}== |
||
< |
<syntaxhighlight lang="mathematica"> Get["myfile.m"] </syntaxhighlight> |
||
=={{header|MATLAB}} / {{header|Octave}}== |
=={{header|MATLAB}} / {{header|Octave}}== |
||
Line 1,832: | Line 1,832: | ||
New functions can be included, either by storing a new function in an existing path, or by extending the existing path to a new directory. When two functions have the same name, the function found first in the path takes precedence. The later is shown here: |
New functions can be included, either by storing a new function in an existing path, or by extending the existing path to a new directory. When two functions have the same name, the function found first in the path takes precedence. The later is shown here: |
||
< |
<syntaxhighlight lang="matlab"> % add a new directory at the end of the path |
||
path(path,newdir); |
path(path,newdir); |
||
addpath(newdir,'-end'); % same as before |
addpath(newdir,'-end'); % same as before |
||
Line 1,838: | Line 1,838: | ||
% add a new directory at the beginning |
% add a new directory at the beginning |
||
addpath(newdir); |
addpath(newdir); |
||
path(newdir,path); % same as before</ |
path(newdir,path); % same as before</syntaxhighlight> |
||
=={{header|Maxima}}== |
=={{header|Maxima}}== |
||
< |
<syntaxhighlight lang="maxima">load("c:/.../source.mac")$ |
||
/* or if source.mac is in Maxima search path (see ??file_search_maxima), simply */ |
/* or if source.mac is in Maxima search path (see ??file_search_maxima), simply */ |
||
load(source)$</ |
load(source)$</syntaxhighlight> |
||
=={{header|Modula-2}}== |
=={{header|Modula-2}}== |
||
< |
<syntaxhighlight lang="modula2">IMPORT InOut, NumConv, Strings;</syntaxhighlight> |
||
=={{header|Modula-3}}== |
=={{header|Modula-3}}== |
||
< |
<syntaxhighlight lang="modula3">IMPORT IO, Text AS Str; |
||
FROM Str IMPORT T</ |
FROM Str IMPORT T</syntaxhighlight> |
||
=={{header|Nanoquery}}== |
=={{header|Nanoquery}}== |
||
< |
<syntaxhighlight lang="nanoquery">import "filename.nq"</syntaxhighlight> |
||
=={{header|Nemerle}}== |
=={{header|Nemerle}}== |
||
To include classes, static methods etc. from other namespaces, include those namespaces with the <tt>using</tt> keyword |
To include classes, static methods etc. from other namespaces, include those namespaces with the <tt>using</tt> keyword |
||
<lang |
<syntaxhighlight lang="nemerle">using System.Console;</syntaxhighlight> |
||
<tt>using</tt> is for accessing code that has already been compiled into libraries. Nemerle also allows for creating |
<tt>using</tt> is for accessing code that has already been compiled into libraries. Nemerle also allows for creating |
||
<tt>partial</tt> classes (and structs), the source code of which may be split amongst several files as long as the class is |
<tt>partial</tt> classes (and structs), the source code of which may be split amongst several files as long as the class is |
||
marked as <tt>partial</tt> in each place that part of it is defined. An interesting feature of partial classes in |
marked as <tt>partial</tt> in each place that part of it is defined. An interesting feature of partial classes in |
||
Nemerle is that some parts of partial classes may be written in C# while others are written in Nemerle. |
Nemerle is that some parts of partial classes may be written in C# while others are written in Nemerle. |
||
< |
<syntaxhighlight lang="nemerle">public partial class Foo : Bar // all parts of a partial class must have same access modifier; |
||
{ // the class that a partial class inherits from only needs to |
{ // the class that a partial class inherits from only needs to |
||
... // be specified in one location |
... // be specified in one location |
||
}</ |
}</syntaxhighlight> |
||
=={{header|NewLISP}}== |
=={{header|NewLISP}}== |
||
< |
<syntaxhighlight lang="newlisp">;; local file |
||
(load "file.lsp") |
(load "file.lsp") |
||
;; URLs (both http:// and file:// URLs are supported) |
;; URLs (both http:// and file:// URLs are supported) |
||
(load "http://www.newlisp.org/code/modules/ftp.lsp")</ |
(load "http://www.newlisp.org/code/modules/ftp.lsp")</syntaxhighlight> |
||
=={{header|Nim}}== |
=={{header|Nim}}== |
||
As other modular languages, accessing from a module to symbols of other modules is done by importation.<br/> |
As other modular languages, accessing from a module to symbols of other modules is done by importation.<br/> |
||
After <code>import someModule</code> an exported symbol <code>x</code> can be accessed as <code>x</code> and as <code>someModule.x</code>. |
After <code>import someModule</code> an exported symbol <code>x</code> can be accessed as <code>x</code> and as <code>someModule.x</code>. |
||
< |
<syntaxhighlight lang="nim">import someModule |
||
import strutils except parseInt |
import strutils except parseInt |
||
import strutils as su, sequtils as qu # su.x works |
import strutils as su, sequtils as qu # su.x works |
||
import pure/os, "pure/times" # still strutils.x</ |
import pure/os, "pure/times" # still strutils.x</syntaxhighlight> |
||
But Nim provides also a way to include the content of a file, using the <code>include</code> statement: |
But Nim provides also a way to include the content of a file, using the <code>include</code> statement: |
||
<lang |
<syntaxhighlight lang="nim">include someFile</syntaxhighlight> |
||
The import statement is only allowed at top level whereas the include statement can be used at any level as it simply includes the text (at the appropriate indentation level). Here is an example from the Nim manual: |
The import statement is only allowed at top level whereas the include statement can be used at any level as it simply includes the text (at the appropriate indentation level). Here is an example from the Nim manual: |
||
< |
<syntaxhighlight lang="nim"># Module A |
||
echo "Hello World!"</ |
echo "Hello World!"</syntaxhighlight> |
||
<br/> |
<br/> |
||
< |
<syntaxhighlight lang="nim"># Module B |
||
proc main() = |
proc main() = |
||
include A |
include A |
||
main() # => Hello World!</ |
main() # => Hello World!</syntaxhighlight> |
||
=={{header|OASYS Assembler}}== |
=={{header|OASYS Assembler}}== |
||
Line 1,902: | Line 1,902: | ||
In script mode and in the interactive loop (the toplevel) we can use: |
In script mode and in the interactive loop (the toplevel) we can use: |
||
< |
<syntaxhighlight lang="ocaml">#use "some_file.ml"</syntaxhighlight> |
||
In compile mode (compiled to bytecode or compiled to native code) we can use: |
In compile mode (compiled to bytecode or compiled to native code) we can use: |
||
<lang |
<syntaxhighlight lang="ocaml">include Name_of_a_module</syntaxhighlight> |
||
=={{header|Oforth}}== |
=={{header|Oforth}}== |
||
In order to load a file with name filename : |
In order to load a file with name filename : |
||
< |
<syntaxhighlight lang="oforth">"filename" load</syntaxhighlight> |
||
In order to load a package with name pack : |
In order to load a package with name pack : |
||
<lang |
<syntaxhighlight lang="oforth">import: pack</syntaxhighlight> |
||
=={{header|Ol}}== |
=={{header|Ol}}== |
||
Ol has a module system, so usually there is no need of a textual inclusion of a text file. |
Ol has a module system, so usually there is no need of a textual inclusion of a text file. |
||
< |
<syntaxhighlight lang="scheme"> |
||
(import (otus random!)) |
(import (otus random!)) |
||
</syntaxhighlight> |
|||
</lang> |
|||
You can do a textual inclusion from the global scope using REPL command ",load" (not a part of core language itself, but a REPL extension). |
You can do a textual inclusion from the global scope using REPL command ",load" (not a part of core language itself, but a REPL extension). |
||
< |
<syntaxhighlight lang="scheme"> |
||
,load "otus/random!.scm" |
,load "otus/random!.scm" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|ooRexx}}== |
=={{header|ooRexx}}== |
||
ooRexx has a package system and no ability for textual inclusion of other text files. Importing of other packages is done via the ::requires directive. |
ooRexx has a package system and no ability for textual inclusion of other text files. Importing of other packages is done via the ::requires directive. |
||
< |
<syntaxhighlight lang="oorexx"> ::requires "regex.cls"</syntaxhighlight> |
||
=={{header|OpenEdge/Progress}}== |
=={{header|OpenEdge/Progress}}== |
||
Curly braces indicate that a file should be included. The file is searched across all PROPATH directory entries. |
Curly braces indicate that a file should be included. The file is searched across all PROPATH directory entries. |
||
<lang |
<syntaxhighlight lang="progress">{file.i}</syntaxhighlight> |
||
Arguments can be passed to the file being included: |
Arguments can be passed to the file being included: |
||
<lang |
<syntaxhighlight lang="progress">{file.i super}</syntaxhighlight> |
||
=={{header|Openscad}}== |
=={{header|Openscad}}== |
||
< |
<syntaxhighlight lang="openscad">//Include and run the file foo.scad |
||
include <foo.scad>; |
include <foo.scad>; |
||
//Import modules and functions, but do not execute |
//Import modules and functions, but do not execute |
||
use <bar.scad>;</ |
use <bar.scad>;</syntaxhighlight> |
||
=={{header|PARI/GP}}== |
=={{header|PARI/GP}}== |
||
Line 1,960: | Line 1,960: | ||
main.perl: |
main.perl: |
||
< |
<syntaxhighlight lang="perl">#!/usr/bin/perl |
||
do "include.pl"; # Utilize source from another file |
do "include.pl"; # Utilize source from another file |
||
sayhello();</ |
sayhello();</syntaxhighlight> |
||
include.pl: |
include.pl: |
||
< |
<syntaxhighlight lang="perl">sub sayhello { |
||
print "Hello World!"; |
print "Hello World!"; |
||
}</ |
}</syntaxhighlight> |
||
From documentation:<pre> |
From documentation:<pre> |
||
Line 1,978: | Line 1,978: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
{{libheader|Phix/basics}} |
{{libheader|Phix/basics}} |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
Phix also supports relative directory includes, for instance if you include "..\demo\pGUI\demo.ew" then anything demo.ew includes is looked for in the same location. |
Phix also supports relative directory includes, for instance if you include "..\demo\pGUI\demo.ew" then anything demo.ew includes is looked for in the same location. |
||
The following remarks have been copied verbatim from the [[Compiler/Simple_file_inclusion_pre_processor#Phix]] entry:<br> |
The following remarks have been copied verbatim from the [[Compiler/Simple_file_inclusion_pre_processor#Phix]] entry:<br> |
||
Phix ships with a bunch of standard files in a builtins directory, most of which it knows how to "autoinclude", but some must be explicitly included ([http://phix.x10.mx/docs/html/include.htm full docs]). You can explicitly specify the builtins directory or not (obviously without it will look in the project directory first), and use the same mechanism for files you have written yourself. There is no limit to the number or depth of files than can be included. Relative directories are honoured, so if you specify a (partial) directory that is where it will look first for any sub-includes. You can also use single line "stub includes" to redirect include statements to different directories/versions. Note that namespaces are not supported by pwa/p2js. You can optionally use double quotes, but may then need to escape backslashes. Includes occur at compile time, as opposed to dynamically. |
Phix ships with a bunch of standard files in a builtins directory, most of which it knows how to "autoinclude", but some must be explicitly included ([http://phix.x10.mx/docs/html/include.htm full docs]). You can explicitly specify the builtins directory or not (obviously without it will look in the project directory first), and use the same mechanism for files you have written yourself. There is no limit to the number or depth of files than can be included. Relative directories are honoured, so if you specify a (partial) directory that is where it will look first for any sub-includes. You can also use single line "stub includes" to redirect include statements to different directories/versions. Note that namespaces are not supported by pwa/p2js. You can optionally use double quotes, but may then need to escape backslashes. Includes occur at compile time, as opposed to dynamically. |
||
<!--< |
<!--<syntaxhighlight lang="phix">--> |
||
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #004080;">complex</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
<span style="color: #008080;">include</span> <span style="color: #000000;">builtins</span><span style="color: #0000FF;">/</span><span style="color: #004080;">complex</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> |
||
<span style="color: #008080;">include</span> <span style="color: #004080;">complex</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- also valid</span> |
<span style="color: #008080;">include</span> <span style="color: #004080;">complex</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span> <span style="color: #000080;font-style:italic;">-- also valid</span> |
||
<span style="color: #008080;">include</span> <span style="color: #008000;">"builtins\\complex.e"</span> <span style="color: #000080;font-style:italic;">-- ditto</span> |
<span style="color: #008080;">include</span> <span style="color: #008000;">"builtins\\complex.e"</span> <span style="color: #000080;font-style:italic;">-- ditto</span> |
||
<!--</ |
<!--</syntaxhighlight>--> |
||
If the compiler detects that some file has already been included it does not do it again (from the same directory, two or more files of the same name can be included from different directories). I should perhaps also state that include handling is part of normal compilation/interpretation, as opposed to a separate "preprocessing" step, and that each file is granted a new private scope, and while of course there is only one "global" scope, it will use the implicit include hierarchy to automatically resolve any clashes that might arise to the most appropriate one, aka "if it works standalone it should work exactly the same when included in as part of a larger application". |
If the compiler detects that some file has already been included it does not do it again (from the same directory, two or more files of the same name can be included from different directories). I should perhaps also state that include handling is part of normal compilation/interpretation, as opposed to a separate "preprocessing" step, and that each file is granted a new private scope, and while of course there is only one "global" scope, it will use the implicit include hierarchy to automatically resolve any clashes that might arise to the most appropriate one, aka "if it works standalone it should work exactly the same when included in as part of a larger application". |
||
=={{header|PHP}}== |
=={{header|PHP}}== |
||
There are different ways to do this in PHP. You can use a basic include: |
There are different ways to do this in PHP. You can use a basic include: |
||
< |
<syntaxhighlight lang="php">include("file.php")</syntaxhighlight> |
||
You can be safe about it and make sure it's not included more than once: |
You can be safe about it and make sure it's not included more than once: |
||
< |
<syntaxhighlight lang="php">include_once("file.php")</syntaxhighlight> |
||
You can crash the code at this point if the include fails for any reason by using require: |
You can crash the code at this point if the include fails for any reason by using require: |
||
< |
<syntaxhighlight lang="php">require("file.php")</syntaxhighlight> |
||
And you can use the require statement, with the safe _once method: |
And you can use the require statement, with the safe _once method: |
||
< |
<syntaxhighlight lang="php">require_once("file.php")</syntaxhighlight> |
||
=={{header|Picat}}== |
=={{header|Picat}}== |
||
===cl/1=== |
===cl/1=== |
||
<code>cl/1</code> compiles a Picat program to a byte code file (<code>.qi</code>) and load that. |
<code>cl/1</code> compiles a Picat program to a byte code file (<code>.qi</code>) and load that. |
||
< |
<syntaxhighlight lang="picat">cl("include_file.pi")</syntaxhighlight> |
||
The extension (<code>.pi</code>) can be omitted: |
The extension (<code>.pi</code>) can be omitted: |
||
<lang |
<syntaxhighlight lang="picat">cl(include_file)</syntaxhighlight> |
||
===load/1=== |
===load/1=== |
||
<code>load/1</code> loads a byte code file. If the byte code files does not exist, the program is first compiled. |
<code>load/1</code> loads a byte code file. If the byte code files does not exist, the program is first compiled. |
||
<lang |
<syntaxhighlight lang="picat">load(include_file)</syntaxhighlight> |
||
===import=== |
===import=== |
||
A Picat module is loaded with <code>import module</code>, which must be placed before any other definitions in the program. |
A Picat module is loaded with <code>import module</code>, which must be placed before any other definitions in the program. |
||
<lang |
<syntaxhighlight lang="picat">import cp, util.</syntaxhighlight> |
||
=={{header|PicoLisp}}== |
=={{header|PicoLisp}}== |
||
The function '[http://software-lab.de/doc/refL.html#load load]' is used for recursively executing the contents of files. |
The function '[http://software-lab.de/doc/refL.html#load load]' is used for recursively executing the contents of files. |
||
< |
<syntaxhighlight lang="picolisp">(load "file1.l" "file2.l" "file3.l")</syntaxhighlight> |
||
=={{header|Pike}}== |
=={{header|Pike}}== |
||
Line 2,031: | Line 2,031: | ||
compile() and compile_file() functions can be used. |
compile() and compile_file() functions can be used. |
||
< |
<syntaxhighlight lang="pike">#include "foo.txt"</syntaxhighlight> |
||
=={{header|PL/I}}== |
=={{header|PL/I}}== |
||
<lang |
<syntaxhighlight lang="pli">%include myfile;</syntaxhighlight> |
||
=={{header|PL/M}}== |
=={{header|PL/M}}== |
||
The original PL/M compiler did not have file inclusion, however PL/M 386 and possibly other versions, had a "$INCLUDE" compiler control statement. The "$" had to appear in the first column. Nesting of include files was possible, to a depth of 5 (in PL/M 386). |
The original PL/M compiler did not have file inclusion, however PL/M 386 and possibly other versions, had a "$INCLUDE" compiler control statement. The "$" had to appear in the first column. Nesting of include files was possible, to a depth of 5 (in PL/M 386). |
||
<lang |
<syntaxhighlight lang="plm">$INCLUDE (fileName.inc)</syntaxhighlight> |
||
=={{header|PowerBASIC}}== |
=={{header|PowerBASIC}}== |
||
Line 2,045: | Line 2,045: | ||
Note also that <code>#INCLUDE</code> and <code>$INCLUDE</code> function identically. |
Note also that <code>#INCLUDE</code> and <code>$INCLUDE</code> function identically. |
||
< |
<syntaxhighlight lang="powerbasic">#INCLUDE "Win32API.inc" |
||
#INCLUDE ONCE "Win32API.inc"</ |
#INCLUDE ONCE "Win32API.inc"</syntaxhighlight> |
||
=={{header|PowerShell}}== |
=={{header|PowerShell}}== |
||
<syntaxhighlight lang="powershell"> |
|||
<lang PowerShell> |
|||
<# |
<# |
||
A module is a set of related Windows PowerShell functionalities, grouped together as a convenient unit (usually saved in a |
A module is a set of related Windows PowerShell functionalities, grouped together as a convenient unit (usually saved in a |
||
Line 2,064: | Line 2,064: | ||
#> |
#> |
||
. .\MyFunctions.ps1 |
. .\MyFunctions.ps1 |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Processing}}== |
=={{header|Processing}}== |
||
Line 2,085: | Line 2,085: | ||
Processing also supports the `import` keyword for explicitly including Processing / Java 8 library files. This can be used to import standard part of Java 8, for example the Map class: |
Processing also supports the `import` keyword for explicitly including Processing / Java 8 library files. This can be used to import standard part of Java 8, for example the Map class: |
||
<lang |
<syntaxhighlight lang="processing">import java.util.Map;</syntaxhighlight> |
||
It can also be used to import contributed libraries, which may be installed via PDE Contributions Manager or locally on the Processing Libraries path. For example, if the G4P library is installed, its files are then imported into a sketch with: |
It can also be used to import contributed libraries, which may be installed via PDE Contributions Manager or locally on the Processing Libraries path. For example, if the G4P library is installed, its files are then imported into a sketch with: |
||
<lang |
<syntaxhighlight lang="processing">import g4p_controls.*;</syntaxhighlight> |
||
3. Local Java JAR files may be added to the sketch /code subfolder, then imported with `import`. For example, if you have a file code/test.jar: |
3. Local Java JAR files may be added to the sketch /code subfolder, then imported with `import`. For example, if you have a file code/test.jar: |
||
Line 2,100: | Line 2,100: | ||
...and it contains a Java class file `foo/bar/Test.class`, then that can be imported from the file. The specific jar file name does _not_ need to be identified -- any resource in any jar file can be imported so long as you specify the in-jar path and class name in the import statement. |
...and it contains a Java class file `foo/bar/Test.class`, then that can be imported from the file. The specific jar file name does _not_ need to be identified -- any resource in any jar file can be imported so long as you specify the in-jar path and class name in the import statement. |
||
<lang |
<syntaxhighlight lang="processing">import foo.bar.Test;</syntaxhighlight> |
||
==={{header|Processing Python mode}}=== |
==={{header|Processing Python mode}}=== |
||
Line 2,116: | Line 2,116: | ||
One can write: |
One can write: |
||
< |
<syntaxhighlight lang="python">import one # note there is no .py sufix |
||
# then you may use |
# then you may use |
||
# one.one_function() |
# one.one_function() |
||
# object = one.OneClass()</ |
# object = one.OneClass()</syntaxhighlight> |
||
otherwise use |
otherwise use |
||
<lang |
<syntaxhighlight lang="python">from one import *</syntaxhighlight> |
||
or, recommended style: |
or, recommended style: |
||
< |
<syntaxhighlight lang="python">from one import OneClass, one_function |
||
# then you may use |
# then you may use |
||
# one_function() |
# one_function() |
||
# object = OneClass()</ |
# object = OneClass()</syntaxhighlight> |
||
=={{header|Prolog}}== |
=={{header|Prolog}}== |
||
<lang |
<syntaxhighlight lang="prolog">consult('filename').</syntaxhighlight> |
||
=={{header|PureBasic}}== |
=={{header|PureBasic}}== |
||
IncludeFile will include the named source file at the current place in the code. |
IncludeFile will include the named source file at the current place in the code. |
||
< |
<syntaxhighlight lang="purebasic">IncludeFile "Filename"</syntaxhighlight> |
||
XIncludeFile is exactly the same except it avoids including the same file several times. |
XIncludeFile is exactly the same except it avoids including the same file several times. |
||
< |
<syntaxhighlight lang="purebasic">XIncludeFile "Filename"</syntaxhighlight> |
||
IncludeBinary will include a named file of any type at the current place in the code. |
IncludeBinary will include a named file of any type at the current place in the code. |
||
IncludeBinary don't have to, but should preferably be done inside a [http://www.purebasic.com/documentation/reference/data.html data block]. |
IncludeBinary don't have to, but should preferably be done inside a [http://www.purebasic.com/documentation/reference/data.html data block]. |
||
< |
<syntaxhighlight lang="purebasic">IncludeBinary "Filename"</syntaxhighlight> |
||
=={{header|Python}}== |
=={{header|Python}}== |
||
Python supports the use of [http://docs.python.org/library/functions.html#execfile execfile] to allow code from arbitrary files to be executed from a program (without using its modules system). |
Python supports the use of [http://docs.python.org/library/functions.html#execfile execfile] to allow code from arbitrary files to be executed from a program (without using its modules system). |
||
<lang |
<syntaxhighlight lang="python">import mymodule</syntaxhighlight> |
||
includes the content of mymodule.py |
includes the content of mymodule.py |
||
Line 2,155: | Line 2,155: | ||
Names in this module can be accessed as attributes: |
Names in this module can be accessed as attributes: |
||
<lang |
<syntaxhighlight lang="python">mymodule.variable</syntaxhighlight> |
||
=={{header|QB64}}== |
=={{header|QB64}}== |
||
<lang |
<syntaxhighlight lang="vb">'$INCLUDE:'filename.bas'</syntaxhighlight> |
||
=={{header|Quackery}}== |
=={{header|Quackery}}== |
||
Line 2,164: | Line 2,164: | ||
To load and compile a file called <code>myfile.qky</code>: |
To load and compile a file called <code>myfile.qky</code>: |
||
< |
<syntaxhighlight lang="quackery">$ "myfile.qky" loadfile</syntaxhighlight> |
||
To load and compile a file called <code>myfile.qky</code> whilst loading and compiling another file: |
To load and compile a file called <code>myfile.qky</code> whilst loading and compiling another file: |
||
< |
<syntaxhighlight lang="quackery">[ $ "myfile.qky" loadfile ] now!</syntaxhighlight> |
||
To prevent a file called <code>myfile.qky</code> from being loaded and compiled more than once during a Quackery session (e.g. a library module that may be invoked during compilation of several other files) define a word called <code>myfile.qky</code> in the file <code>myfile.qky</code>. By convention, use this definition as the first line of the file: |
To prevent a file called <code>myfile.qky</code> from being loaded and compiled more than once during a Quackery session (e.g. a library module that may be invoked during compilation of several other files) define a word called <code>myfile.qky</code> in the file <code>myfile.qky</code>. By convention, use this definition as the first line of the file: |
||
<lang |
<syntaxhighlight lang="quackery">[ this ] is myfile.qky</syntaxhighlight> |
||
=={{header|R}}== |
=={{header|R}}== |
||
< |
<syntaxhighlight lang="r">source("filename.R")</syntaxhighlight> |
||
=={{header|Racket}}== |
=={{header|Racket}}== |
||
Line 2,182: | Line 2,182: | ||
Including files is usually discouraged in favor of using modules, but it is still possible: |
Including files is usually discouraged in favor of using modules, but it is still possible: |
||
< |
<syntaxhighlight lang="racket"> |
||
#lang racket |
#lang racket |
||
(include "other-file.rkt") |
(include "other-file.rkt") |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |
||
Line 2,192: | Line 2,192: | ||
Raku provides a module system that is based primarily on importation of symbols rather than |
Raku provides a module system that is based primarily on importation of symbols rather than |
||
on inclusion of textual code: |
on inclusion of textual code: |
||
<lang |
<syntaxhighlight lang="raku" line>use MyModule;</syntaxhighlight> |
||
However, one can evaluate code from a file: |
However, one can evaluate code from a file: |
||
<lang |
<syntaxhighlight lang="raku" line>require 'myfile.p6';</syntaxhighlight> |
||
One can even do that at compile time: |
One can even do that at compile time: |
||
<lang |
<syntaxhighlight lang="raku" line>BEGIN require 'myfile.p6'</syntaxhighlight> |
||
None of these are true inclusion, unless the <tt>require</tt> cheats and modifies the current input string of the parser. To get a true textual inclusion, one could define an unhygienic textual macro like this: |
None of these are true inclusion, unless the <tt>require</tt> cheats and modifies the current input string of the parser. To get a true textual inclusion, one could define an unhygienic textual macro like this: |
||
<lang |
<syntaxhighlight lang="raku" line>macro include(AST $file) { slurp $file.eval } |
||
include('myfile.p6');</ |
include('myfile.p6');</syntaxhighlight> |
||
=={{header|RapidQ}}== |
=={{header|RapidQ}}== |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
$INCLUDE "RAPIDQ.INC" |
$INCLUDE "RAPIDQ.INC" |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Retro}}== |
=={{header|Retro}}== |
||
<lang |
<syntaxhighlight lang="retro">'filename include</syntaxhighlight> |
||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
Line 2,218: | Line 2,218: | ||
The REXX Compiler for CMS and TSO supports a directive to include program text before compiling the program |
The REXX Compiler for CMS and TSO supports a directive to include program text before compiling the program |
||
<lang |
<syntaxhighlight lang="rexx">/*%INCLUDE member */</syntaxhighlight> |
||
===Including a file at time of execution=== |
===Including a file at time of execution=== |
||
Line 2,224: | Line 2,224: | ||
{{works with|ARexx}} |
{{works with|ARexx}} |
||
{{works with|REGINA 3.8 and later, with options: AREXX_BIFS and AREXX_SEMANTICS}} |
{{works with|REGINA 3.8 and later, with options: AREXX_BIFS and AREXX_SEMANTICS}} |
||
< |
<syntaxhighlight lang="rexx"> |
||
/* Include a file and INTERPRET it; this code uses ARexx file IO BIFs */ |
/* Include a file and INTERPRET it; this code uses ARexx file IO BIFs */ |
||
say 'This is a program running.' |
say 'This is a program running.' |
||
Line 2,239: | Line 2,239: | ||
say 'The usual program resumes here.' |
say 'The usual program resumes here.' |
||
exit 0 |
exit 0 |
||
</syntaxhighlight> |
|||
</lang> |
|||
Note: due to the way most REXX interpreters work, functions and jumps (SIGNALs) inside an INTERPRETED program won't work. Neither are ''labels'' recognized, which would then exclude the use of those subroutines/functions. |
Note: due to the way most REXX interpreters work, functions and jumps (SIGNALs) inside an INTERPRETED program won't work. Neither are ''labels'' recognized, which would then exclude the use of those subroutines/functions. |
||
Line 2,250: | Line 2,250: | ||
'''Program1.rexx''' |
'''Program1.rexx''' |
||
< |
<syntaxhighlight lang="rexx"> |
||
/* This is program 1 */ |
/* This is program 1 */ |
||
say 'This is program 1 writing on standard output.' |
say 'This is program 1 writing on standard output.' |
||
Line 2,256: | Line 2,256: | ||
say 'Thank you, program 1 is now ending.' |
say 'Thank you, program 1 is now ending.' |
||
exit 0 |
exit 0 |
||
</syntaxhighlight> |
|||
</lang> |
|||
'''Program2.rexx''' |
'''Program2.rexx''' |
||
< |
<syntaxhighlight lang="rexx"> |
||
/* This is program 2 */ |
/* This is program 2 */ |
||
say 'This is program 2 writing on standard output.' |
say 'This is program 2 writing on standard output.' |
||
say 'We now return to the caller.' |
say 'We now return to the caller.' |
||
return |
return |
||
</syntaxhighlight> |
|||
</lang> |
|||
If a REXX interpreter finds a function call, it first looks in the current program for a function or procedure by that name, then it looks in the standard function library (so you may replace the standard functions with your own versions inside a program), then it looks for a program by the same name in the standard paths. This means that including a file in your program is usually not necessary, unless you want them to share global variables. |
If a REXX interpreter finds a function call, it first looks in the current program for a function or procedure by that name, then it looks in the standard function library (so you may replace the standard functions with your own versions inside a program), then it looks for a program by the same name in the standard paths. This means that including a file in your program is usually not necessary, unless you want them to share global variables. |
||
=={{header|Ring}}== |
=={{header|Ring}}== |
||
< |
<syntaxhighlight lang="ring">Load 'file.ring'</syntaxhighlight> |
||
=={{header|RPG}}== |
=={{header|RPG}}== |
||
Line 2,273: | Line 2,273: | ||
{{works with|ILE RPG}} |
{{works with|ILE RPG}} |
||
< |
<syntaxhighlight lang="rpg"> // fully qualified syntax: |
||
/include library/file,member |
/include library/file,member |
||
Line 2,285: | Line 2,285: | ||
/copy library/file,member |
/copy library/file,member |
||
//... farther like "include"</ |
//... farther like "include"</syntaxhighlight> |
||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
Note that in Ruby, you don't use the file extension. Ruby will first check for a Ruby (.rb) file of the specified name and load it as a source file. If an .rb file is not found it will search for files in .so, .o, .dll or other shared-library formats and load them as Ruby extension. <code>require</code> will search in a series of pre-determined folders, while <code>require_relative</code> behaves the same way but searches in the current folder, or another specified folder. |
Note that in Ruby, you don't use the file extension. Ruby will first check for a Ruby (.rb) file of the specified name and load it as a source file. If an .rb file is not found it will search for files in .so, .o, .dll or other shared-library formats and load them as Ruby extension. <code>require</code> will search in a series of pre-determined folders, while <code>require_relative</code> behaves the same way but searches in the current folder, or another specified folder. |
||
<lang |
<syntaxhighlight lang="ruby">require 'file'</syntaxhighlight> |
||
=={{header|Run BASIC}}== |
=={{header|Run BASIC}}== |
||
You don't use the file extension. .bas is assumed. |
You don't use the file extension. .bas is assumed. |
||
< |
<syntaxhighlight lang="runbasic">run SomeProgram.bas",#include ' this gives it a handle of #include |
||
render #include ' render will RUN the program with handle #include</ |
render #include ' render will RUN the program with handle #include</syntaxhighlight> |
||
=={{header|Rust}}== |
=={{header|Rust}}== |
||
The compiler will include either a 'test.rs' or a 'test/mod.rs' (if the first one doesn't exist) file. |
The compiler will include either a 'test.rs' or a 'test/mod.rs' (if the first one doesn't exist) file. |
||
< |
<syntaxhighlight lang="rust">mod test; |
||
fn main() { |
fn main() { |
||
test::some_function(); |
test::some_function(); |
||
}</ |
}</syntaxhighlight> |
||
Additionally, third-party libraries (called <code>crates</code> in rust) can be declared thusly: |
Additionally, third-party libraries (called <code>crates</code> in rust) can be declared thusly: |
||
< |
<syntaxhighlight lang="rust">extern crate foo; |
||
fn main() { |
fn main() { |
||
foo::some_function(); |
foo::some_function(); |
||
}</ |
}</syntaxhighlight> |
||
=={{header|Scala}}== |
=={{header|Scala}}== |
||
Line 2,316: | Line 2,316: | ||
In a Scala REPL[https://docs.scala-lang.org/overviews/repl/overview.html] it's possible to save and load source code. |
In a Scala REPL[https://docs.scala-lang.org/overviews/repl/overview.html] it's possible to save and load source code. |
||
=={{header|Scheme}}== |
=={{header|Scheme}}== |
||
< |
<syntaxhighlight lang="scheme">(load "filename")</syntaxhighlight> |
||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
Line 2,322: | Line 2,322: | ||
Therefore seed7_05.s7i must be included before other language features can be used (only comments can be used before). |
Therefore seed7_05.s7i must be included before other language features can be used (only comments can be used before). |
||
The first include directive (the one which includes seed7_05.s7i) is special and it must be introduced with the $ character. |
The first include directive (the one which includes seed7_05.s7i) is special and it must be introduced with the $ character. |
||
< |
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";</syntaxhighlight> |
||
All following include directives don't need a $ to introduce them. |
All following include directives don't need a $ to introduce them. |
||
The [http://seed7.sourceforge.net/libraries/float.htm float.s7i] |
The [http://seed7.sourceforge.net/libraries/float.htm float.s7i] |
||
[http://seed7.sourceforge.net/libraries library] can be included with: |
[http://seed7.sourceforge.net/libraries library] can be included with: |
||
< |
<syntaxhighlight lang="seed7"> include "float.s7i";</syntaxhighlight> |
||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
Include a file in the current namespace: |
Include a file in the current namespace: |
||
<lang |
<syntaxhighlight lang="ruby">include 'file.sf';</syntaxhighlight> |
||
Include a file as module (file must exists in '''SIDEF_INC''' as '''Some/Name.sm'''): |
Include a file as module (file must exists in '''SIDEF_INC''' as '''Some/Name.sm'''): |
||
< |
<syntaxhighlight lang="ruby">include Some::Name; |
||
# variables are available here as: Some::Name::var_name</ |
# variables are available here as: Some::Name::var_name</syntaxhighlight> |
||
=={{header|Smalltalk}}== |
=={{header|Smalltalk}}== |
||
there is no such thing as source-file inclusion in Smalltalk. However, in a REPL or anywhere in code, source code can be loaded with: |
there is no such thing as source-file inclusion in Smalltalk. However, in a REPL or anywhere in code, source code can be loaded with: |
||
<lang |
<syntaxhighlight lang="smalltalk">aFilename asFilename readStream fileIn</syntaxhighlight> |
||
or: |
or: |
||
<lang |
<syntaxhighlight lang="smalltalk">Smalltalk fileIn: aFilename</syntaxhighlight> |
||
In Smalltalk/X, which supports binary code loading, aFilename may either be sourcecode or a dll containing a precompiled class library. |
In Smalltalk/X, which supports binary code loading, aFilename may either be sourcecode or a dll containing a precompiled class library. |
||
Line 2,346: | Line 2,346: | ||
{{Works with|SNOBOL4}} |
{{Works with|SNOBOL4}} |
||
{{Works with|Spitbol}} |
{{Works with|Spitbol}} |
||
< |
<syntaxhighlight lang="snobol4">-INCLUDE "path/to/filename.inc"</syntaxhighlight> |
||
=={{header|SPL}}== |
=={{header|SPL}}== |
||
<lang |
<syntaxhighlight lang="spl">$include.txt</syntaxhighlight> |
||
=={{header|Standard ML}}== |
=={{header|Standard ML}}== |
||
{{Works with|SML/NJ}} |
{{Works with|SML/NJ}} |
||
< |
<syntaxhighlight lang="sml">use "path/to/file";</syntaxhighlight> |
||
=={{header|Tcl}}== |
=={{header|Tcl}}== |
||
The built-in <code>source</code> command does exactly inclusion of code into the currently executing scope, subject to minor requirements of being well-formed Tcl script that is sourced in the first place (and the ability to introspect via <code>info script</code>): |
The built-in <code>source</code> command does exactly inclusion of code into the currently executing scope, subject to minor requirements of being well-formed Tcl script that is sourced in the first place (and the ability to introspect via <code>info script</code>): |
||
< |
<syntaxhighlight lang="tcl">source "foobar.tcl"</syntaxhighlight> |
||
Note that it is more usually considered good practice to arrange code into ''packages'' that can be loaded in with more regular semantics (including version handling, only-once semantics, integration of code written in other languages such as [[C]], etc.) |
Note that it is more usually considered good practice to arrange code into ''packages'' that can be loaded in with more regular semantics (including version handling, only-once semantics, integration of code written in other languages such as [[C]], etc.) |
||
<lang |
<syntaxhighlight lang="tcl">package require foobar 1.3</syntaxhighlight> |
||
In the case of packages that are implemented using Tcl code, these will actually be incorporated into the program using the <code>source</code> command, though this is formally an implementation detail of those packages. |
In the case of packages that are implemented using Tcl code, these will actually be incorporated into the program using the <code>source</code> command, though this is formally an implementation detail of those packages. |
||
Line 2,368: | Line 2,368: | ||
{{works with|Bourne Shell}} |
{{works with|Bourne Shell}} |
||
< |
<syntaxhighlight lang="bash">. myfile.sh # Include the contents of myfile.sh </syntaxhighlight> |
||
==={{header|C Shell}}=== |
==={{header|C Shell}}=== |
||
<lang |
<syntaxhighlight lang="csh">source myfile.csh</syntaxhighlight> |
||
==={{header|Bash}}=== |
==={{header|Bash}}=== |
||
< |
<syntaxhighlight lang="shell">. myfile.sh |
||
source myfile.sh</ |
source myfile.sh</syntaxhighlight> |
||
GNU Bash has both <code>.</code> and the C-Shell style <code>source</code>. See [http://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-source Bash manual on <code>source</code>] |
GNU Bash has both <code>.</code> and the C-Shell style <code>source</code>. See [http://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-source Bash manual on <code>source</code>] |
||
Line 2,381: | Line 2,381: | ||
=={{header|Ursa}}== |
=={{header|Ursa}}== |
||
Ursa can read in and execute another file using the import statement, similar to Python. |
Ursa can read in and execute another file using the import statement, similar to Python. |
||
< |
<syntaxhighlight lang="ursa">import "filename.u"</syntaxhighlight> |
||
=={{header|Vala}}== |
=={{header|Vala}}== |
||
Line 2,390: | Line 2,390: | ||
Functions can be called then using Gee.<function> calls: |
Functions can be called then using Gee.<function> calls: |
||
< |
<syntaxhighlight lang="vala">var map = new Gee.HashMap<string, int> ();</syntaxhighlight> |
||
or with a using statement: |
or with a using statement: |
||
< |
<syntaxhighlight lang="vala">using Gee; |
||
var map = new HashMap<string, int>();</ |
var map = new HashMap<string, int>();</syntaxhighlight> |
||
=={{header|VBScript}}== |
=={{header|VBScript}}== |
||
VBScript doesn't come with an explicit include (unless you use the wsf form). Fortunately vbscript has the Execute and ExecuteGlobal commands which allow you to add code dynamically into the local (disappears when the code goes out of scope) or global namespaces. Thus, all you have to do to include code from a file is read the file into memory and ExecuteGlobal on that code. Just pass the filename to this sub and all is golden. If you want an error to occur if the file is not found then just remove the FileExists test. |
VBScript doesn't come with an explicit include (unless you use the wsf form). Fortunately vbscript has the Execute and ExecuteGlobal commands which allow you to add code dynamically into the local (disappears when the code goes out of scope) or global namespaces. Thus, all you have to do to include code from a file is read the file into memory and ExecuteGlobal on that code. Just pass the filename to this sub and all is golden. If you want an error to occur if the file is not found then just remove the FileExists test. |
||
<syntaxhighlight lang="vb"> |
|||
<lang vb> |
|||
Include "D:\include\pad.vbs" |
Include "D:\include\pad.vbs" |
||
Line 2,409: | Line 2,409: | ||
if fso.FileExists(file) then ExecuteGlobal fso.OpenTextFile(file).ReadAll |
if fso.FileExists(file) then ExecuteGlobal fso.OpenTextFile(file).ReadAll |
||
End Sub |
End Sub |
||
</syntaxhighlight> |
|||
</lang> |
|||
If you use the wsf form you can include a file by |
If you use the wsf form you can include a file by |
||
< |
<syntaxhighlight lang="vbscript"> |
||
<script id="Connections" language="VBScript" src="D:\include\ConnectionStrings.vbs"/> |
<script id="Connections" language="VBScript" src="D:\include\ConnectionStrings.vbs"/> |
||
</syntaxhighlight> |
|||
</lang> |
|||
If you use the following form then you can define an environment variable, %INCLUDE% and make your include library more portable as in |
If you use the following form then you can define an environment variable, %INCLUDE% and make your include library more portable as in |
||
< |
<syntaxhighlight lang="vbscript"> |
||
Include "%INCLUDE%\StrFuncs.vbs" |
Include "%INCLUDE%\StrFuncs.vbs" |
||
Line 2,426: | Line 2,426: | ||
ExecuteGlobal(fso.OpenTextFile(wso.ExpandEnvironmentStrings(file)).ReadAll) |
ExecuteGlobal(fso.OpenTextFile(wso.ExpandEnvironmentStrings(file)).ReadAll) |
||
End Function |
End Function |
||
</syntaxhighlight> |
|||
</lang> |
|||
=={{header|Verbexx}}== |
=={{header|Verbexx}}== |
||
< |
<syntaxhighlight lang="verbexx">/******************************************************************************* |
||
* /# @INCLUDE file:"filename.filetype" |
* /# @INCLUDE file:"filename.filetype" |
||
* - file: is just the filename |
* - file: is just the filename |
||
Line 2,461: | Line 2,461: | ||
Not in preprocessor -- include_counter = 3 |
Not in preprocessor -- include_counter = 3 |
||
Not in preprocessor -- include_counter = 3 |
Not in preprocessor -- include_counter = 3 |
||
Not in preprocessor -- include_counter = 3</ |
Not in preprocessor -- include_counter = 3</syntaxhighlight> |
||
=={{header|Wren}}== |
=={{header|Wren}}== |
||
Line 2,477: | Line 2,477: | ||
Here's a simple example. |
Here's a simple example. |
||
< |
<syntaxhighlight lang="ecmascript">import "./fmt" for Fmt // imports the Fmt module and makes the 'Fmt' class available |
||
import "./math" for Int // imports the Math module and makes the 'Int' class available |
import "./math" for Int // imports the Math module and makes the 'Int' class available |
||
Fmt.print("The maximum safe integer in Wren is $,d.", Int.maxSafe)</ |
Fmt.print("The maximum safe integer in Wren is $,d.", Int.maxSafe)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,490: | Line 2,490: | ||
{{works with|FASM on Windows}} |
{{works with|FASM on Windows}} |
||
<lang |
<syntaxhighlight lang="asm">include 'MyFile.INC'</syntaxhighlight> |
||
{{works with|nasm}} |
{{works with|nasm}} |
||
< |
<syntaxhighlight lang="asm">%include "MyFile.INC"</syntaxhighlight> |
||
=={{header|XPL0}}== |
=={{header|XPL0}}== |
||
< |
<syntaxhighlight lang="xpl0">include c:\cxpl\stdlib; |
||
DateOut(0, GetDate)</ |
DateOut(0, GetDate)</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
Line 2,513: | Line 2,513: | ||
What ''not'' to do: |
What ''not'' to do: |
||
< |
<syntaxhighlight lang="z80">org &1000 |
||
include "\source\mathLibrary.asm" |
include "\source\mathLibrary.asm" |
||
main: |
main: |
||
ld a,&42 |
ld a,&42 |
||
ret</ |
ret</syntaxhighlight> |
||
In assembly, the order you arrange your code is typically the same as its layout in memory, unless you're using a linker. In the above example, execution will begin at the ORG directive and "fall through" into your math Library, rather than starting at main. Unless your program has a header that jumps to main (something that [[C]] generates for you automatically), you're going to have some undesired effects if you don't "trap" the program counter. |
In assembly, the order you arrange your code is typically the same as its layout in memory, unless you're using a linker. In the above example, execution will begin at the ORG directive and "fall through" into your math Library, rather than starting at main. Unless your program has a header that jumps to main (something that [[C]] generates for you automatically), you're going to have some undesired effects if you don't "trap" the program counter. |
||
The right way: |
The right way: |
||
< |
<syntaxhighlight lang="z80">org &1000 |
||
main: |
main: |
||
ld a,&42 |
ld a,&42 |
||
ret |
ret |
||
include "\source\mathLibrary.asm"</ |
include "\source\mathLibrary.asm"</syntaxhighlight> |
||
You'll have to take this with a grain of salt, as it's hardware-dependent (the above was for Amstrad CPC or other similar home computers where your program is CALLed from BASIC.) If you're defining your own ROM header for something like Game Boy things will be a bit different. |
You'll have to take this with a grain of salt, as it's hardware-dependent (the above was for Amstrad CPC or other similar home computers where your program is CALLed from BASIC.) If you're defining your own ROM header for something like Game Boy things will be a bit different. |
||
=={{header|zkl}}== |
=={{header|zkl}}== |
||
< |
<syntaxhighlight lang="zkl">include(vm.h.zkl, compiler.h.zkl, zkl.h.zkl, opcode.h.zkl);</syntaxhighlight> |
||
=={{header|ZX Spectrum Basic}}== |
=={{header|ZX Spectrum Basic}}== |
||
Line 2,537: | Line 2,537: | ||
It is possible to include the contents of another program using the merge command. However, line numbers that coincide with those of the original program shall be overwritten, so it is best to reserve a block of line numbers for merged code: |
It is possible to include the contents of another program using the merge command. However, line numbers that coincide with those of the original program shall be overwritten, so it is best to reserve a block of line numbers for merged code: |
||
< |
<syntaxhighlight lang="zxbasic">10 GO TO 9950 |
||
5000 REM We reserve line numbers 5000 to 8999 for merged code |
5000 REM We reserve line numbers 5000 to 8999 for merged code |
||
9000 STOP: REM In case our line numbers are wrong |
9000 STOP: REM In case our line numbers are wrong |
||
Line 2,543: | Line 2,543: | ||
9955 MERGE "MODULE" |
9955 MERGE "MODULE" |
||
9960 REM Jump to the merged code. Pray it has the right line numbers! |
9960 REM Jump to the merged code. Pray it has the right line numbers! |
||
9965 GO TO 5000 </ |
9965 GO TO 5000 </syntaxhighlight> |
||