Pragmatic directives: Difference between revisions

Content added Content deleted
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
(Added Wren)
Line 696: Line 696:
<lang sh>set -vx # Activate both script line output and command line arguments pragma
<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</lang>

=={{header|Wren}}==
The closest thing Wren has to a pragmatic directive is its '''import''' statement which loads a module, executes its source code and imports variable names from that module into the current scope.

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 */

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

<lang ecmascript>/* linux.wren */

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

<lang ecmascript>/*pragmatic_directives.wren*/

import "os" for Platform

var os
if (Platform.isWindows) {
import "/windows" for Windows
os = Windows
} else {
import "/linux" for Linux
os = Linux
}
System.print("%(os.message) which has a \"%(os.lineSeparator)\" line separator.")</lang>

{{out}}
From the last script, when run on a Linux system.
<pre>
$ wren_cli pragmatic_directives.wren
Using Linux which has a "\n" line separator.
</pre>


{{omit from|AWK}}
{{omit from|AWK}}