diff --git a/doc/src/guide.rst b/doc/src/guide.rst new file mode 100644 index 0000000..25be592 --- /dev/null +++ b/doc/src/guide.rst @@ -0,0 +1,106 @@ +Guide +===== +In this guide, we're going to cover the main CCM features. +We'll first start by the base data types CCM provides, +as well as their associated operators. + +Statements VS Expressions +------------------------- +In virtually all programming languages, statements and expressions are two different things. +Most of the time, statements don't return values, but expressions do. +In CCM, everything is an expression, so a program is just a bunch of expressions that CCM evaluates +one after the other. + +Data Types +---------- +Coco Mango provides five main built-in types: numbers, booleans, strings, tuples and arrays. +All these types comes with operators such as addition and substraction, or concatenation and duplication. +Tuples and arrays are both collections of expressions. Their main difference lies in the fact +that tuples are not mutables, whereas arrays are. + +Numbers +~~~~~~~ +Let's begin by the ``num`` data type. A num represents numbers: +integers as well as floating points. It comes with the usual mathematic operations. + +.. code-block:: + :caption: num operations + + 5 + 3 + 2 - 3 + -7 + 7 * 9 + 3 / 2 + 2 ^ 3 + 15 % 4 + + +Booleans +~~~~~~~~ +The ``bool`` data type represents boolean values. It can be either ``true`` or ``false``. +It supports the logical operations: ``and``, ``or`` and ``not``. + +.. code-block:: + :caption: boolean operations + + not true # false + not false # true + + true and true # true + true and false # false + false and true # false + false and false # false + + true or true # true + true or false # true + false or true # true + false or false # false + +Strings +~~~~~~~ +A ``str`` is the immutable string type of CCM. Strings supports three main operation: +concatenation, duplication and indexing. + +We can concatenate two strings using the ``+`` operator and duplicate them using the ``*`` operator. +Indexing is syntaxically the same as in C like languages. + +.. code-block:: + :caption: string + + "hello world" + "hello " + "world" # returns "hello world" + 3 * "a" # returns "aaa" + "pizza"[0] # returns "p" + +Tuples +~~~~~~ +A ``tuple`` is an immutable collection of expression used +to group *n* semantically relevant values together (with *n* > 1). +We can extract a tuple sub-expression using the indexing operator, +and membership can be tested with the ``in`` keyword. + +.. code-block:: + :caption: tuples + + (4, 3) + ("hello", 29) + (3, 5, 2)[1] # returns 5 + 1 in (3, 2) # returns false + 2 in (3, 2) # returns true + + +Array +~~~~~ +An ``array`` is a mutable collection of expressions that supportes the same operations as +tuples, with the addition of concatenation (``+``) and duplication (``*``) operators. + +.. code-block:: + :caption: array + + [2, 4] + [2] + [3] # returns [2, 3] + [3, 6, 8][1] # returns 6 + "love" in ["love", "pizzas"] # returns true + + + diff --git a/doc/src/index.rst b/doc/src/index.rst index 558c97b..29b537c 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -1,7 +1,14 @@ CCM Documentation ================= +.. warning:: + + CCM is at an early stage of development. + + .. toctree:: + :maxdepth: 2 installation + guide