<?xml version="1.0" ?>
<?xml-stylesheet type="text/css" href="stylesheet.css" ?>

<!-- Copyright 2003 Steve Folta -->

<cleet-doc>

<title> Expressions </title>

<header> Primary Expressions </header>

<p>
Primary expressions are the most basic kind of expression.  First
of all, there are various literals:
</p>

<code>"String literal"
'String literal'
34
12.5
nil
true
false</code>


<p>
Next there are identifiers:
</p>

<code>some-identifier
SomeClass</code>

<p>
An identifier might refer to a local variable, to a field of the current
object, to a class object, or to a namespace.  Identifiers start with a
letter, and may contain letters, numbers, and hyphens.  An identifier may
not end with a hyphen.  By convention, almost all identifiers are all
lowercase and use hyphens to separate words.  The exceptions are class names
and namespace names, which are capitalized and use intercaps to separate
words.
</p>

<code>this
super</code>

<p>
"this" and "super" both refer to the current object.  The difference is
that if a function call is made on "super", it will use the method defined
in the superclass, not the one in the current object's class that overrides
it.
</p>

<p>
There are expressions to create a new object:
</p>

<code>new SomeClass
new SomeClass(argument-1, argument-2)</code>

<p>
Creating a new object (almost) always includes calling a
<id>create()</id> function on the new object, so you can pass the
arguments for that function call.
</p>


<header> Dot Expressions </header>

<p>
Once you've got a reference to an object, you can access its fields or
call its functions using the dot operator:
</p>

<code>some-object.some-field
some-object.some-function(argument-1, argument-2)
"A string".length
(3).string</code>

<p>
Note the last two examples; they show that literals are objects just like
any other, and that you don't need an argument list -- not even the
parentheses -- to call a function that has no arguments.  (A function with
no arguments is called a "nullary" function.)  But you can include the
parentheses if you want:
</p>

<code>"Hello world.\n".write()</code>

<p>
There is a convention about when to use the parentheses when calling a
nullary function:  If you're calling the function just to find out
something about the object, don't use the parentheses.  If you're calling
the function because it's going to <i>do</i> something, use the parentheses.
</p>

<p>
The name of the function can also be given as a string literal instead of
as an identifier:
</p>

<code>some-object."some-function"()
some-object."+"(some-other-object)</code>

<p>
Class fields and functions can be accessed without having an object of
the class.  Just give the class name, a dot, and the field or function:
</p>

<code>System.system</code>



<header> Operators </header>

<p>
Most of the operators available in C and C++ are also available in Cleet,
and result in function calls.  So the following pairs of expressions are
equivalent:
</p>

<code>3 + 4
(3)."+"(4)

some-object[some-index-1, some-index-2]
some-object."[]"(some-index-1, some-index-2)</code>

<p>
The exceptions are the "short-circuit" logical operators:
<id>&amp;&amp;</id>, <id>||</id>, and <id>!</id>.  These are not
function calls.  Neither is the "=" operator; see below for the
explanation of how that is handled.
</p>

<p>
Precedence is the same as in C/C++:
</p>

<code>=
||
&amp;&amp;
|
^
&amp;
== !=
&lt; &gt; &lt;= &gt;=
&lt;&lt; &gt;&gt;
+ -
* / %
! unary+ unary- ~
[]</code>

<p>
(Note that unlike C/C++, Cleet has no pre-/post- increment/decrement operators,
conditional expressions, or comma operator.)
</p>


<header> Assignment and the "=" operator </header>

<p>
Most of the time, the "=" operator is used to assign to a local variable
or a field:
</p>

<code>some-local = some-value
some-field-of-current-object = some-value
some-object.some-field = some-value</code>

<p>
But it can also be used with functions, in which case the function name
has "-set" appended to it and the value is the last argument.  So the
following pairs of expressions are equivalent:
</p>

<code>some-object.some-function(some-argument) = some-value
some-object.some-function-set(some-argument, some-value)

some-object[some-index] = some-value
some-object."[]-set"(some-index, some-value)</code>

<p>
Most of the binary operators have an associated operator that makes the
function call and assigns the result in one step:
</p>

<code>x += 1</code>

<p>
(These have the same precedence as the "=" operator.)
</p>

</cleet-doc>
