# Standard Functions

These functions represent the core functionality of the G language.

## @all

Inputs: one or more boolean strings (TRUE or FALSE)

Returns TRUE if all of its arguments are TRUE.

``````>>> @all(TRUE|TRUE|TRUE)
TRUE
>>> @all(TRUE|FALSE|TRUE)
FALSE
``````

## @any

Inputs: one or more boolean strings (TRUE or FALSE)

Returns TRUE if any of its arguments is TRUE.

``````>>> @any(FALSE|TRUE|FALSE)
TRUE
>>> @any(FALSE|FALSE|FALSE)
FALSE
``````

## @dice

Inputs: a dice expression string. Ex: 1d6, 2d10, 4d7, etc.

Returns the result of a the given dice roll.

Dice rolls are expressed in the format [number of dice]d[sides per dice].

``````>>> @dice(3d6)
12
>>> @dice(1d4)
4
``````

## @equals

Inputs: any two strings

Returns TRUE if the arguments are equivalent. False otherwise.

``````>>> @equals(hi there|hi there)
TRUE
>>> @equals(hi there|bye there)
FALSE
``````

## @exit

Inputs: no inputs

Terminates execution.

``````>>> @exit()
\$
``````

## @fn

Inputs: any number of ordered arguments:

1. a list of identifiers, e.g. `@a|@b|@c`
2. a function definition
``````>>> @fn(@a|@b|@c|@add(@add(@a|@b)|@c))
``````

There’s a better way to write this in G, though. We can use bracket notation:

``````>>> @addThree: @fn(@a|@b|@c) {
...        @add( `a | `b )
...        | `c
...    )
... }
6
``````

Functions can accept strings, tables, and other functions as inputs.

``````>>> @doMath: @fn(@a|@b|@c) {
...    @c(@a|@b)
... }
3
>>> @doMath(1|2|@subtract)
-1
>>> @doMath(1|2|@multiply)
2
``````

## @if

Inputs: Three ordered arguments

1. Boolean expression
2. Expression
3. Expression

If the first argument evaluates to TRUE, evaluate and return the first second argument. If the first argument does not evaluate to true, check for a third argument. If it exists, evaluate and return it. Otherwise, return nothing.

@if is short-circuited.

``````>>> @if(TRUE
...    | hi there
...    | @print(oh no)
... )
hi there
``````

## @import

Inputs: a filename string

Executes the given file, loading its context into the existing context.

``````>>> @import(./colors.gn)
>>> `color
blue
``````

## @not

Inputs: a boolean string (TRUE or FALSE)

Returns FALSE if the argument is TRUE. Otherwise, TRUE.

``````>>> @not(TRUE)
FALSE
>>> @not(FALSE)
TRUE
``````

## @print

Inputs: any string

Outputs the given string.

Note that the interpreter supports bare words and prints the return value of each expression by default, so @print is often not necessary.

``````>>> @print(hi there!)
hi there!
``````

## @table

Inputs: one or more expressions

Returns a table object.

``````>>> @a: @table(
...    A
...    | B
...    | C
...    | D
...    )
>>> `a
C
``````