ExpandCollapsePrev Next Index

+ 7.1 Standard Types

To move on it is convenient to use some of the stuff already in the Felix system. The types we introduce here and the functions and procedures that operate on them, are all defined in the Standard library by bindings similar to those in chapter 1. This is probably not surprising by now!

It may come as a surprise however, that the literal values we illustrate below, are also defined in the library, and not built in to the compiler. You can probably guess this is done in the grammar with complicated Scheme codes, and you'd be right!

We're not ready to examine the codes or the exact rules, so we'll just present examples.

+ 7.1.1 Type int

This type is bound to the underlying C++ int type. It is a signed type with most of the operators C provides except for bit masking operations, which are representation dependent.

  // type int = "int";
  var i1 : int = 42;
  var i2 : int = i1+1;

And as you might guess, we also have negation {-}, infix {-}, {*}, {/}, {%} as in C. We also have shift operators {<<} and {>>} because these are simply multiplication or division by a power of two, and hence representation independent. Remember to put spaces around infix {-}!

We also have the comparisons {<}, {<=}, {>=}, {>}, {==} and {!=} as in C.

+ 7.1.2 Type uint

This is an unsigned integer type bound to {unsigned int}. It provides the same operators as int an by fixing the representation to the usual power series we also define bitwise and {\&}, bitwise or {\|} bitwise exclusive or {\^} and complement {~}.

  var ui1 = 123u;
  var ui2 = 0xFF80u;

+ 7.1.3 Type double

Double precision float.

  // type double = "double";
  var d1 : double = 4.2;
  var d2 : double = d1 * 2.3E7;
  var d3 = sin d2 + log d2;

+ 7.1.4 Type string

C++ standard string type.

  // type string = "::std::string";
  var s1 = "hello";
  var s2 = 'world';
  var newline = "\n";
  var s3 =
    'Hello '
    'World' newline
  var manylines = 
  """Poetry can
  in Felix be done""";

+ 7.1.5 Type char

  // type char = "char";
  var c1 = char "A";
  println$ str d1 + " " + str c1;

4.2 A

Strings follow Python. There is no char literal, but you can specify the first character of a string.