Pragmatic directives: Difference between revisions

Content added Content deleted
(→‎{{header|Lua}}: added Lua solution)
m (syntax highlighting fixup automation)
Line 17: Line 17:
* <code>ifdef</code>/<code>ifndef</code>/<code>else</code>/<code>endif</code>: The assembler will skip anything inside an IFDEF block if the designated label wasn't defined. IFNDEF and ELSE are the opposite. To make an IFDEF statement true, you only need to have that label defined in your source. (The value doesn't matter as long as it appears.) Here's an example:
* <code>ifdef</code>/<code>ifndef</code>/<code>else</code>/<code>endif</code>: The assembler will skip anything inside an IFDEF block if the designated label wasn't defined. IFNDEF and ELSE are the opposite. To make an IFDEF statement true, you only need to have that label defined in your source. (The value doesn't matter as long as it appears.) Here's an example:


<lang 6502asm>NMOS_6502 equ 1
<syntaxhighlight lang="6502asm">NMOS_6502 equ 1
ifdef NMOS_6502
ifdef NMOS_6502
txa
txa
Line 23: Line 23:
else
else
phx ;NMOS_6502 doesn't have this instruction.
phx ;NMOS_6502 doesn't have this instruction.
endif ; every ifdef/ifndef needs an endif</lang>
endif ; every ifdef/ifndef needs an endif</syntaxhighlight>


* <code>db</code>/<code>dw</code>/<code>byte</code>/<code>word</code>: Defines a data block. The assembler treats these values as arbitrary bytes rather than machine instructions. Used for tables of values, etc.
* <code>db</code>/<code>dw</code>/<code>byte</code>/<code>word</code>: Defines a data block. The assembler treats these values as arbitrary bytes rather than machine instructions. Used for tables of values, etc.
Line 74: Line 74:
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.3.5 algol68g-2.3.5] - most compiler directives are permitted as '''pragma'''s options - also ' '''pr''' read "filename.a68" '''pr''' ' is permitted to "include" a file.}}
{{works with|ALGOL 68G|Any - tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-2.3.5 algol68g-2.3.5] - most compiler directives are permitted as '''pragma'''s options - also ' '''pr''' read "filename.a68" '''pr''' ' is permitted to "include" a file.}}
{{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 implementation specific PRAGMA.}}
{{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 implementation specific PRAGMA.}}
'''File: Pragmatic_directives.a68'''<lang algol68>#!/usr/local/bin/a68g --script #
'''File: Pragmatic_directives.a68'''<syntaxhighlight lang="algol68">#!/usr/local/bin/a68g --script #


PRAGMAT portcheck PRAGMAT
PRAGMAT portcheck PRAGMAT
Line 85: Line 85:
PROC (REAL)REAL s = sin();
PROC (REAL)REAL s = sin();


SKIP</lang>'''Output:'''
SKIP</syntaxhighlight>'''Output:'''
<pre>
<pre>
10 PROC (REAL)REAL s = sin();
10 PROC (REAL)REAL s = sin();
Line 99: Line 99:
{{works with|GWBASIC}}
{{works with|GWBASIC}}


<lang basic>10 TRON: REM activate system trace pragma
<syntaxhighlight lang="basic">10 TRON: REM activate system trace pragma
20 TROFF: REM deactivate system trace pragma</lang>
20 TROFF: REM deactivate system trace pragma</syntaxhighlight>
'''
'''
'''
'''


==={{header|IS-BASIC}}===
==={{header|IS-BASIC}}===
<lang IS-BASIC>TRACE ON
<syntaxhighlight lang="is-basic">TRACE ON
TRACE OFF</lang>
TRACE OFF</syntaxhighlight>


==={{header|QBasic}}===
==={{header|QBasic}}===
<lang qbasic>TRON : REM activate system trace pragma
<syntaxhighlight lang="qbasic">TRON : REM activate system trace pragma
TROFF : REM deactivate system trace pragma
TROFF : REM deactivate system trace pragma
REM QBasic debugging features make these instructions unnecessary
REM QBasic debugging features make these instructions unnecessary
END</lang>
END</syntaxhighlight>




=={{header|C}}==
=={{header|C}}==
The C Preprocessor is well explained on the [https://gcc.gnu.org/onlinedocs/cpp/index.html#Top GNU] site. The pragma page is [https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html here].
The C Preprocessor is well explained on the [https://gcc.gnu.org/onlinedocs/cpp/index.html#Top GNU] site. The pragma page is [https://gcc.gnu.org/onlinedocs/cpp/Pragmas.html here].
<syntaxhighlight lang="c">
<lang C>
/*Almost every C program has the below line,
/*Almost every C program has the below line,
the #include preprocessor directive is used to
the #include preprocessor directive is used to
Line 157: Line 157:


/*Enlightened ?*/
/*Enlightened ?*/
</syntaxhighlight>
</lang>
On compilation and output, the compiler type is detected rather than the actual OS :
On compilation and output, the compiler type is detected rather than the actual OS :
<pre>
<pre>
Line 246: Line 246:
Go has a feature called [http://golang.org/pkg/go/build/#overview build constraints] that work on the level of whole files. A comment line reading
Go has a feature called [http://golang.org/pkg/go/build/#overview build constraints] that work on the level of whole files. A comment line reading


<lang go>// +build <expression></lang>
<syntaxhighlight lang="go">// +build <expression></syntaxhighlight>


will cause the entire file to be excluded from a build unless <expression> is true. The elements, called tags, in the expression are typically things like the target operating system or hardware architecture. For example
will cause the entire file to be excluded from a build unless <expression> is true. The elements, called tags, in the expression are typically things like the target operating system or hardware architecture. For example


<lang go>// +build linux</lang>
<syntaxhighlight lang="go">// +build linux</syntaxhighlight>


will include the file if the target OS is linux, but will exclude the file otherwise. Arbitrary tags can be passed on the command line of the go command. A file could begin
will include the file if the target OS is linux, but will exclude the file otherwise. Arbitrary tags can be passed on the command line of the go command. A file could begin


<lang go>// +build Tuesday</lang>
<syntaxhighlight lang="go">// +build Tuesday</syntaxhighlight>


and the build command
and the build command


<lang bash>go install -tags `date +%A`</lang>
<syntaxhighlight lang="bash">go install -tags `date +%A`</syntaxhighlight>


would only include the file on Tuesdays.
would only include the file on Tuesdays.
Line 264: Line 264:
=={{header|Icon}} and {{header|Unicon}}==
=={{header|Icon}} and {{header|Unicon}}==
Icon and Unicon have a number of pragmatic modes. Most of these are controlled via keywords (See [[Special_variables#Icon_and_Unicon]])).
Icon and Unicon have a number of pragmatic modes. Most of these are controlled via keywords (See [[Special_variables#Icon_and_Unicon]])).
<lang Icon>&trace # controls execution tracing
<syntaxhighlight lang="icon">&trace # controls execution tracing
&error # controls error handling</lang>
&error # controls error handling</syntaxhighlight>


Additionally, tracing can be controlled via the environment variable 'TRACE'.
Additionally, tracing can be controlled via the environment variable 'TRACE'.
Line 299: Line 299:
For example,
For example,


<lang j> 9!:25]1</lang>
<syntaxhighlight lang="j"> 9!:25]1</syntaxhighlight>


disables access to the file system (and disables some other features, including the ability to exit the program, because the system exit mechanism is a system feature and thus not trusted). You cannot turn this off after it has been turned on (so you will need to shut down J and start it again if you want to use those features).
disables access to the file system (and disables some other features, including the ability to exit the program, because the system exit mechanism is a system feature and thus not trusted). You cannot turn this off after it has been turned on (so you will need to shut down J and start it again if you want to use those features).
Line 305: Line 305:
Or, for example, y is the usual name for the right argument of a verb.
Or, for example, y is the usual name for the right argument of a verb.


<lang j> 3 :'y' 8
<syntaxhighlight lang="j"> 3 :'y' 8
8</lang>
8</syntaxhighlight>


But y is also a regular variable. So J also offers a reserved word y. which serves the same role. But this is disabled by default (because mostly it's just an unnecessary complication).
But y is also a regular variable. So J also offers a reserved word y. which serves the same role. But this is disabled by default (because mostly it's just an unnecessary complication).


<lang j> 3 :'y.' 8
<syntaxhighlight lang="j"> 3 :'y.' 8
|spelling error</lang>
|spelling error</syntaxhighlight>


But you can enable the reserved word mechanism:
But you can enable the reserved word mechanism:


<lang j> 9!:49]1
<syntaxhighlight lang="j"> 9!:49]1
3 :'y.' 8
3 :'y.' 8
8
8
Line 321: Line 321:
8
8
3 :'y.]y=.7' 8
3 :'y.]y=.7' 8
7</lang>
7</syntaxhighlight>


=={{header|Julia}}==
=={{header|Julia}}==
Julia has a number of macros which act as compiler directives. For example, the <code>@inbounds</code> macro disables runtime checking of array bounds within a block of code marked by this macro, which sometimes improves performance. Example:
Julia has a number of macros which act as compiler directives. For example, the <code>@inbounds</code> macro disables runtime checking of array bounds within a block of code marked by this macro, which sometimes improves performance. Example:
<lang julia>x = rand(100, 100)
<syntaxhighlight lang="julia">x = rand(100, 100)
y = rand(100, 100)
y = rand(100, 100)


Line 336: Line 336:
end
end
end
end
</syntaxhighlight>
</lang>


=={{header|Kotlin}}==
=={{header|Kotlin}}==
The closest things which Kotlin has to pragmatic directives are annotations which always begin with the @ character. For example, the following code would normally produce a compiler warning that the variable 's' is never used. However, the presence of the @Suppress annotation suppresses the warning:
The closest things which Kotlin has to pragmatic directives are annotations which always begin with the @ character. For example, the following code would normally produce a compiler warning that the variable 's' is never used. However, the presence of the @Suppress annotation suppresses the warning:
<lang scala>// version 1.0.6
<syntaxhighlight lang="scala">// version 1.0.6


@Suppress("UNUSED_VARIABLE")
@Suppress("UNUSED_VARIABLE")
Line 346: Line 346:
fun main(args: Array<String>) {
fun main(args: Array<String>) {
val s = "To be suppressed"
val s = "To be suppressed"
}</lang>
}</syntaxhighlight>


=={{header|Lua}}==
=={{header|Lua}}==
Lua itself really doesn't have anything equivalent. However, if being used in a mixed/hosted/embedded environment, the <code>ffi</code> library might be encountered, which supports <code>pragma pack</code> to facilitate native type interchange:
Lua itself really doesn't have anything equivalent. However, if being used in a mixed/hosted/embedded environment, the <code>ffi</code> library might be encountered, which supports <code>pragma pack</code> to facilitate native type interchange:
<lang lua>ffi = require("ffi")
<syntaxhighlight lang="lua">ffi = require("ffi")
ffi.cdef[[
ffi.cdef[[
#pragma pack(1)
#pragma pack(1)
Line 358: Line 358:
]]
]]
print(ffi.sizeof(ffi.new("foo")))
print(ffi.sizeof(ffi.new("foo")))
print(ffi.sizeof(ffi.new("bar")))</lang>
print(ffi.sizeof(ffi.new("bar")))</syntaxhighlight>
{{out}}
{{out}}
<pre>5
<pre>5
Line 371: Line 371:
NetRexx provides three pragma-like instructions: <tt>OPTIONS</tt>, <tt>NUMERIC</tt> and <tt>TRACE</tt>.
NetRexx provides three pragma-like instructions: <tt>OPTIONS</tt>, <tt>NUMERIC</tt> and <tt>TRACE</tt>.
* '''<tt>OPTIONS</tt>''' provides the ability to pass special requests to the language processor (i.e. a compiler or interpreter).
* '''<tt>OPTIONS</tt>''' provides the ability to pass special requests to the language processor (i.e. a compiler or interpreter).
:The syntax is:<lang NetRexx>options wordlist;</lang>
:The syntax is:<syntaxhighlight lang="netrexx">options wordlist;</syntaxhighlight>
:where ''wordlist'' is one or more symbols separated by blanks. The individual words in ''wordlist'' might control optimizations, enforce standards, enable implementation-dependent features, etc.
:where ''wordlist'' is one or more symbols separated by blanks. The individual words in ''wordlist'' might control optimizations, enforce standards, enable implementation-dependent features, etc.
:The current default settings of <tt>OPTIONS</tt> is:<lang NetRexx>options -
:The current default settings of <tt>OPTIONS</tt> is:<syntaxhighlight lang="netrexx">options -
nobinary nocomments nocompact console crossref decimal nodiag noexplicit noformat java logo noreplace nosavelog nosourcedir -
nobinary nocomments nocompact console crossref decimal nodiag noexplicit noformat java logo noreplace nosavelog nosourcedir -
nostrictargs nostrictassign nostrictcase nostrictimport nostrictprops nostrictsignal nosymbols trace2 noutf8 verbose3</lang>
nostrictargs nostrictassign nostrictcase nostrictimport nostrictprops nostrictsignal nosymbols trace2 noutf8 verbose3</syntaxhighlight>
* '''<tt>NUMERIC</tt>''' is used to change the way in which arithmetic operations are carried out by a program.
* '''<tt>NUMERIC</tt>''' is used to change the way in which arithmetic operations are carried out by a program.
:The syntax is:<lang NetRexx>numeric digits [exprd];
:The syntax is:<syntaxhighlight lang="netrexx">numeric digits [exprd];
numeric form [scientific | engineering];</lang>
numeric form [scientific | engineering];</syntaxhighlight>
:*'''<tt>numeric digits</tt>''' controls the precision under which arithmetic operations will be evaluated. The default for ''exprd'' is '''9''' i.e. '''<tt>numeric digits 9</tt>'''.<br />There is normally no limit to the value for <tt>'''numeric digits'''</tt> (except the constraints imposed by the amount of storage and other resources available) but note that high precisions are likely to be expensive in processing time.
:*'''<tt>numeric digits</tt>''' controls the precision under which arithmetic operations will be evaluated. The default for ''exprd'' is '''9''' i.e. '''<tt>numeric digits 9</tt>'''.<br />There is normally no limit to the value for <tt>'''numeric digits'''</tt> (except the constraints imposed by the amount of storage and other resources available) but note that high precisions are likely to be expensive in processing time.
:*'''<tt>numeric form</tt>''' controls which form of exponential notation is to be used for the results of operations.
:*'''<tt>numeric form</tt>''' controls which form of exponential notation is to be used for the results of operations.
* '''<tt>TRACE</tt>''' is used to control the tracing of the execution of NetRexx methods, and is primarily used for debugging.
* '''<tt>TRACE</tt>''' is used to control the tracing of the execution of NetRexx methods, and is primarily used for debugging.
:The Syntax is:<lang NetRexx>trace tracesetting
:The Syntax is:<syntaxhighlight lang="netrexx">trace tracesetting
trace var [varlist]</lang>
trace var [varlist]</syntaxhighlight>
:where ''tracesetting'' is one of:
:where ''tracesetting'' is one of:
:*'''<tt>all</tt>'''
:*'''<tt>all</tt>'''
Line 416: Line 416:


And here are some examples:
And here are some examples:
<lang Nim>{.checks: off, optimization: speed.} # Checks are deactivated and code is generated for speed.
<syntaxhighlight lang="nim">{.checks: off, optimization: speed.} # Checks are deactivated and code is generated for speed.


# Define a type Color as pure which implies that value names are declared in their own scope
# Define a type Color as pure which implies that value names are declared in their own scope
Line 444: Line 444:
...
...
{.pop.}
{.pop.}
# From here, checks are deactivated again.</lang>
# From here, checks are deactivated again.</syntaxhighlight>


=={{header|Perl}}==
=={{header|Perl}}==
Line 467: Line 467:
Pragmatic modules have local scope and are utilized using the use directive:
Pragmatic modules have local scope and are utilized using the use directive:


<lang perl>use warnings; # use warnings pragma module
<syntaxhighlight lang="perl">use warnings; # use warnings pragma module
use strict; # use strict pragma module</lang>
use strict; # use strict pragma module</syntaxhighlight>


To disable behaviour of a pragmatic module:
To disable behaviour of a pragmatic module:


<lang perl>no warnings; # disable warnings pragma module
<syntaxhighlight lang="perl">no warnings; # disable warnings pragma module
no strict; # disable strict pragma module</lang>
no strict; # disable strict pragma module</syntaxhighlight>


=={{header|Phix}}==
=={{header|Phix}}==
Line 528: Line 528:


While technically code rather than a directive, the requires() builtin can hopefully avoid fruitless efforts to run something where it is simply never going to work, eg
While technically code rather than a directive, the requires() builtin can hopefully avoid fruitless efforts to run something where it is simply never going to work, eg
<!--<lang Phix>(phixonline)-->
<!--<syntaxhighlight lang="phix">(phixonline)-->
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #004600;">JS</span><span style="color: #0000FF;">)</span>
<span style="color: #000080;font-style:italic;">--requires(WINDOWS) -- (one of only, or
<span style="color: #000080;font-style:italic;">--requires(WINDOWS) -- (one of only, or
Line 534: Line 534:
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.2"</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #000000;">32</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- or 64</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #000000;">32</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- or 64</span>
<!--</lang>-->
<!--</syntaxhighlight>-->


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==
Line 551: Line 551:
an array.
an array.
For example:
For example:
<lang pli> declare (t(100),i) fixed binary;
<syntaxhighlight lang="pli"> declare (t(100),i) fixed binary;
i=101;
i=101;
t(i)=0;</lang>
t(i)=0;</syntaxhighlight>
will cause unpredictible results.
will cause unpredictible results.
And :
And :
<lang pli> (SubscriptRange): begin;
<syntaxhighlight lang="pli"> (SubscriptRange): begin;
declare (t(100),i) fixed binary;
declare (t(100),i) fixed binary;
i=101;
i=101;
t(i)=0;
t(i)=0;
end;</lang>
end;</syntaxhighlight>
will issue the message : "The SubscriptRange condition was raised." at execution time.
will issue the message : "The SubscriptRange condition was raised." at execution time.
<br>Or, it can be handle by an on-unit.
<br>Or, it can be handle by an on-unit.
<lang pli> (SubscriptRange): begin;
<syntaxhighlight lang="pli"> (SubscriptRange): begin;
declare (t(100),i) fixed binary;
declare (t(100),i) fixed binary;
i=101;
i=101;
Line 569: Line 569:
t(i)=0;
t(i)=0;
e:on SubscriptRange system; /* default dehaviour */
e:on SubscriptRange system; /* default dehaviour */
end;</lang>
end;</syntaxhighlight>
<br>And the same way for a string,
<br>And the same way for a string,
the '''StringRange''' condition is raised when a substring reference is beyond
the '''StringRange''' condition is raised when a substring reference is beyond
Line 587: Line 587:
You can use #Requires statements in any script. You cannot use them in
You can use #Requires statements in any script. You cannot use them in
functions, cmdlets, or snap-ins.
functions, cmdlets, or snap-ins.
<syntaxhighlight lang="powershell">
<lang PowerShell>
#Requires -Version <N>[.<n>]
#Requires -Version <N>[.<n>]
#Requires –PSSnapin <PSSnapin-Name> [-Version <N>[.<n>]]
#Requires –PSSnapin <PSSnapin-Name> [-Version <N>[.<n>]]
Line 593: Line 593:
#Requires –ShellId <ShellId>
#Requires –ShellId <ShellId>
#Requires -RunAsAdministrator
#Requires -RunAsAdministrator
</syntaxhighlight>
</lang>
For a full description:
For a full description:
<syntaxhighlight lang="powershell">
<lang PowerShell>
Get-Help about_Requires
Get-Help about_Requires
</syntaxhighlight>
</lang>


=={{header|Python}}==
=={{header|Python}}==
Line 603: Line 603:


;Python 3.2:
;Python 3.2:
<lang python>Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32
<syntaxhighlight lang="python">Python 3.2 (r32:88445, Feb 20 2011, 21:30:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
Type "copyright", "credits" or "license()" for more information.
>>> import __future__
>>> import __future__
>>> __future__.all_feature_names
>>> __future__.all_feature_names
['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals', 'barry_as_FLUFL']
['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals', 'barry_as_FLUFL']
>>> </lang>
>>> </syntaxhighlight>


('barry_as_FLUFL' is an April fools [http://www.python.org/dev/peps/pep-0401/ joke])
('barry_as_FLUFL' is an April fools [http://www.python.org/dev/peps/pep-0401/ joke])


;Python 2.7:
;Python 2.7:
<lang python>Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
<syntaxhighlight lang="python">Python 2.7.2 (default, Jun 12 2011, 14:24:46) [MSC v.1500 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
Type "copyright", "credits" or "license()" for more information.
>>> import __future__
>>> import __future__
>>> __future__.all_feature_names
>>> __future__.all_feature_names
['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals']
['nested_scopes', 'generators', 'division', 'absolute_import', 'with_statement', 'print_function', 'unicode_literals']
>>> </lang>
>>> </syntaxhighlight>


=={{header|Racket}}==
=={{header|Racket}}==
Line 628: Line 628:
{{works with|rakudo|2015-10-20}}
{{works with|rakudo|2015-10-20}}
The Perl 6 pragma mechanism is nearly identical to Perl 5's, piggybacking on the notation for importing modules (pragmas are distinguished by case from normal modules, which are generally of mixed case). By convention pragmas are lowercase, unless they are indicating the use of an unsafe feature, in which case they are in all caps.
The Perl 6 pragma mechanism is nearly identical to Perl 5's, piggybacking on the notation for importing modules (pragmas are distinguished by case from normal modules, which are generally of mixed case). By convention pragmas are lowercase, unless they are indicating the use of an unsafe feature, in which case they are in all caps.
<lang perl6>use MONKEY-TYPING;
<syntaxhighlight lang="raku" line>use MONKEY-TYPING;
augment class Int {
augment class Int {
method times (&what) { what() xx self } # pretend like we're Ruby
method times (&what) { what() xx self } # pretend like we're Ruby
}</lang>
}</syntaxhighlight>
Unlike Perl 5, there is no <tt>use strict;</tt> pragma, however, since Perl 6 is strict by default. Importation of a pragma is lexically scoped as in Perl 5, but note that unlike in Perl 5, <i>all</i> importation is lexical in Perl 6, so pragmas are not special that way.
Unlike Perl 5, there is no <tt>use strict;</tt> pragma, however, since Perl 6 is strict by default. Importation of a pragma is lexically scoped as in Perl 5, but note that unlike in Perl 5, <i>all</i> importation is lexical in Perl 6, so pragmas are not special that way.


Line 801: Line 801:
=={{header|Scala}}==
=={{header|Scala}}==
===tailrec===
===tailrec===
<lang Scala>@inline
<syntaxhighlight lang="scala">@inline
@tailrec</lang>
@tailrec</syntaxhighlight>


=={{header|Tcl}}==
=={{header|Tcl}}==
Line 829: Line 829:
Pragmatic directives remain effective, until they are deactivated, or the end of the script is reached:
Pragmatic directives remain effective, until they are deactivated, or the end of the script is reached:


<lang sh>set -vx # Activate both script line output and command line arguments pragma
<syntaxhighlight lang="sh">set -vx # Activate both script line output and command line arguments pragma
set +vx # Deactivate both pragmatic directives</lang>
set +vx # Deactivate both pragmatic directives</syntaxhighlight>


=={{header|Wren}}==
=={{header|Wren}}==
Line 837: Line 837:
Import statements can appear anywhere a variable declaration is allowed and in particular within conditional structures. This enables us to do things such as the following:
Import statements can appear anywhere a variable declaration is allowed and in particular within conditional structures. This enables us to do things such as the following:


<lang ecmascript>/* windows.wren */
<syntaxhighlight lang="ecmascript">/* windows.wren */


class Windows {
class Windows {
static message { "Using Windows" }
static message { "Using Windows" }
static lineSeparator { "\\r\\n" }
static lineSeparator { "\\r\\n" }
}</lang>
}</syntaxhighlight>


<lang ecmascript>/* linux.wren */
<syntaxhighlight lang="ecmascript">/* linux.wren */


class Linux {
class Linux {
static message { "Using Linux" }
static message { "Using Linux" }
static lineSeparator { "\\n" }
static lineSeparator { "\\n" }
}</lang>
}</syntaxhighlight>


<lang ecmascript>/*pragmatic_directives.wren*/
<syntaxhighlight lang="ecmascript">/*pragmatic_directives.wren*/


import "os" for Platform
import "os" for Platform
Line 863: Line 863:
os = Linux
os = Linux
}
}
System.print("%(os.message) which has a \"%(os.lineSeparator)\" line separator.")</lang>
System.print("%(os.message) which has a \"%(os.lineSeparator)\" line separator.")</syntaxhighlight>


{{out}}
{{out}}