919338e3648ee3c1555807077c9b0e5db687d953
[cc1516.git] / deliverables / report / ext.tex
1 \section{Extensions}
2 \subsection{Higher order functions}
3
4 \subsection{Syntactic sugars}
5 Several small syntactic sugars have been added on several levels of processing
6 to make writing programs more easy.
7
8 \subsubsection{Literal strings}
9 While there are no literal strings one can print lists of characters. Entering
10 lists of characters can be cumbersome and therefore a shorthand notation is
11 added to define literal strings using double quotes. During the lexing phase
12 the string is lexed as a single token and during parsing the token is
13 transformed to a equal character list representation. The following example
14 shows the syntax before transformation and the syntax after. Note that just as
15 in characters, literal strings can contain escape characters.
16
17 \begin{SPLCode}
18 //Before transformation
19 var a = "Hello world!";
20 //After transformation
21 var a = 'H':'e':'l':'l':'o':' ':'w':'o':'r':'l':'d':'!':[]
22 \end{SPLCode}
23
24 \subsubsection{Anonymous functions}
25 %TODO
26
27 \subsubsection{Variable arguments printing}
28 To ease the programmer we have included a parse-level transformation that
29 transforms \SI{print} with multiple arguments to multiple \SI{print} function
30 calls with a single argument. The following example shows the syntax before the
31 transformation and the syntax after the transformation.
32
33 \begin{SPLCode}
34 //Before transformation
35 print("abc", 42, 'c', "da\n");
36
37 //After transformation
38 print('a':'b':'c':[]);
39 print(42);
40 print('c');
41 print('d':'a':'\n':[]);
42 \end{SPLCode}