= Commands

The following are commands that the Nickle interpreter understands, not actual language constructs.
They may be issued only at the top level. 

== Expressions

If an expression is issued at the top level, such as `3**4` or
``100!``, its value is printed to standard output.  If the expression
ends with a # sign and another expression, its value is printed in
whatever base the second expression evaluates to.

----

$ nickle
> 10!
3628800
> 3**4
81
> 3**4 # 3
10000
>
----

Statements, from expressions terminated by semicolons to complicated control structures, are executed but have no value to print.
Statements are not commands but actual syntax, so they may be used in scripts.
If a line is ended before it can be sensible as an expression or statement, Nickle will continue until it is a statement, e.g. 

----

$ nickle
> int x
+ = 0
+ ;
>
----

== Quit

The `quit` command exits Nickle.
An optional argument specifies the return value. 

----

$ nickle
> quit
$
----

== Print

The `print` command provides information such as visibility, type, and value, about a name.
It need not be the name of a variable; functions, namespaces, etc.
may also be printed. 

----

$ nickle
> int x = 2;
> print x
global int x = 2;
> print String
public namespace String {
    public int length (string) <builtin>
    public string new (poly) <builtin>
    public int index (string, string) <builtin>
    public string substr (string, int, int) <builtin>
    public int rindex (string target, string pattern);
    public string dirname (string name);
}
> void function hello() { printf("hello, world\n"); }
> print hello
void hello ()
{
    printf ("hello, world\n");
}
>
----

== Undefine

A defined name can be undefined, e.g. 

----

$ nickle
> print x
No symbol "x" in namespace
> int x = 0;
> print x
global int x = 0;
> undefine x
> print x
No symbol "x" in namespace
>
----

== Loading files

The `load` and `library` commands evaluate a file at runtime like the `-f` and `-l` flags, respectively. 

== Edit

The `edit` command invokes `$EDITOR` on the name given as an argument.
This is particularly useful to change a function while in interactive mode. 

----

$ nickle
> void function hello() { printf("hello, world\n"); }
> edit hello
49
3
    printf ("hello, world\n");
c
printf ("goodbye, cruel world\n");
wq
53
> print hello
void hello ()
{
    printf ("goodbye, cruel world\n");
}
>
----

== History

The `history` command retrieves the values of the last ten expressions.
With an argument, it instead retrieves the values of that many preceeding values.
With two arguments, it retrieves the specified range in history. 

----

$ nickle
...
> history
$176    20
$177    5
$178    0
$179    12
$180    12
$181    -2
$182    2
$183    2
$184    0
$185    10
$186    32
> history 3
$184    0
$185    10
$186    32
> history 180,185
$180    12
$181    -2
$182    2
$183    2
$184    0
$185    10
----

These history items may be named and used directly: 

----

> $180 ** 2
144
>
----
