Skip to content
Abe Pralle edited this page Sep 7, 2022 · 3 revisions

Defines

Syntax

$define IDENTIFIER expression
$localDefine IDENTIFIER expression

Description

$define

Similar to C's #define.

When one file includes another, all defines in the directly or indirectly-included files are available for use before the original file continues being parsed.

Defines are applied recursively.

$localDefine

Like $define, but scope-limited to the remainder of the current file.

Examples

$define HELLO "Hello World!"
$define HW println HELLO
HW  # Prints: "Hello World!"

Macros

Syntax

$macro SINGLE_LINE_MACRO<<$placeholder1,...>> expression_using($placeholder1,etc)

$macro MULTI_LINE_MACRO<<$placeholders,...>>
  statements
  ...
$endMacro

$localMacro SINGLE_LINE_LOCAL_MACRO<<...>> statements

$localMacro MULTI_LINE_LOCAL_MACRO<<...>>
  statements
  ...
$endLocalMacro

Description

Similar to C macros, Rogue macros allow a block of code to be templated with placeholder parameters. A template-style reference to a macro replaces the placeholders with the call arguments and then substitutes the entire call with the specialized code.

A standard macro (AKA global macro) applies to all code in the remainder of the current file as well as all files subsequently included with $include or uses.

A local macro applies to all code in the remainder of the current file but does not affect other files.

Unlike C, multiple macros can be defined with the same name but different parameter counts.

Macros and Defines are applied recursively.

Example

$macro SWAP<<$a,$b>>
  block temp = $a
    $a = $b
    $b = temp
  endBlock
$endMacro

local x=3, y=4
SWAP<<x,y>>
println "x:$, y:$"(x,y)  # x:4, y:3
Clone this wiki locally