Skip to content

Commit

Permalink
DOc, strings. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
skaller committed Nov 27, 2017
1 parent 46d71c1 commit 05473b5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/tutorial/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Contents:

hello
integers
strings
pythagoras
guiindex

Expand Down
94 changes: 94 additions & 0 deletions doc/tutorial/strings.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Strings
=======

A string is basically a sequence of characters
with a definite length.

Type
----

The easiest string type to use in Felix is the one based
on C++:

.. code-block:: felix
type string = "::std::basic_string<char>"
requires Cxx_headers::string
;
Literals
--------

There are two simple forms of string literals:

.. code-block:: felix
var x = "I am a string";
var y = 'I am a string too';
using double quote delimiters and single quote delimiters.
These literals cannot exceed a single line. However
you can concatenate them by juxtaposition:

.. code-block:: felix
var verse =
"I am the first line,\n"
'and I am the second.'
;
Notice the special encoding `\n` which inserts and end of
line character into the string rather than a `\` followed
by an `n`. This is called an escape.

You can prevent escapes being translated with raw
strings like this:

.. code-block:: felix
r"This \n is retained as two chars"
Only double quoted strings can be raw.

Felix also has triple quoted strings, which span
line boundaries, and include end of lines in the
literal:

.. code-block:: felix
"""This is
a very long
string"""
which contains two end of line characters in the string, whilst
this one:

.. code-block:: felix
'''
Here is another
long string
'''
has three end of lines (one after the first triple quote).

Operations
----------

Strings can be concatenated with the infix `+` operator or
just written next to each other, juxtaposition has a higher
precedence than infix `+`.

.. code-block:: felix
var x = "middle";
var y = "Start" x + "end";
In this case, the first concatenation of x is done first,
then the second one which appends "end". The result
is independent of the ordering because concatenation
is associative, the run time performance, however, is not,
because concatenation requires coping.




0 comments on commit 05473b5

Please sign in to comment.