1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
<sect1><title>Commands</title>
<para>
The following are commands that the Nickle interpreter understands, not actual language constructs.
They may be issued only at the top level.
</para>
<sect2><title>Expressions</title>
<para>
If an expression is issued at the top level, such as <literal>3**4</literal> or <literal>100!,</literal>, 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.
<informalexample><screen>
$ nickle
> 10!
3628800
> 3**4
81
> 3**4 # 3
10000
>
</screen></informalexample>
</para>
<para>
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.
<informalexample><screen>
$ nickle
> int x
+ = 0
+ ;
>
</screen></informalexample>
</para>
</sect2>
<sect2><title>Quit</title>
<para>
The <literal>quit</literal> command exits Nickle.
An optional argument specifies the return value.
<informalexample><screen>
$ nickle
> quit
$
</screen></informalexample>
</para>
</sect2>
<sect2><title>Print</title>
<para>
The <literal>print</literal> 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.
<informalexample><screen><![CDATA[
$ 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");
}
>
]]></screen></informalexample>
</para>
</sect2>
<sect2><title>Undefine</title>
<para>
A defined name can be undefined, e.g.
<informalexample><screen>
$ 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
>
</screen></informalexample>
</para>
</sect2>
<sect2><title>Loading files</title>
<para>
The <literal>load</literal> and <literal>library</literal> commands evaluate a file at runtime like the <literal>-f</literal> and <literal>-l</literal> flags, respectively.
</para>
</sect2>
<sect2><title>Edit</title>
<para>
The <literal>edit</literal> command invokes <literal>$EDITOR</literal> on the name given as an argument.
This is particularly useful to change a function while in interactive mode.
<informalexample><screen>
$ 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");
}
>
</screen></informalexample>
</para>
</sect2>
<sect2><title>History</title>
<para>
The <literal>history</literal> 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.
<informalexample><screen>
$ 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
</screen></informalexample>
</para>
<para>
These history items may be named and used directly:
<informalexample><screen>
> $180 ** 2
144
>
</screen></informalexample>
</para>
</sect2>
</sect1>
|