Next: , Previous: Translating C into L, Up: Translating C into L


2.1.1.1 Variables declaration

You have to precede all your local variable definitions with a let :

     int
     foo(int a, int b)
     {
       let int c = a + b;
       return a * c;
     }

I can already hear some old UNIX hackers already yelling : so L is more verbose than C, even more verbose than Java?

No: in L, type annotations are optional. That is, you can define exactly the same function if you use:

     int
     foo(int a, int b)
     {
       let c = a + b;
       return a * c;
     }

Type annotations are useful for the programmers for as checks of what is going on; you can see them as partial specifications of your program.

Passing the types of the parameters (and knowing the types of the different global variables) is in fact sufficient for deducing the types of all local variables; that's why type annotation is useless for the compiler.

Thus you avoid things like:

     BufferedInputStream bufferedInputStream = new BufferInputStream(....);

which are quite redundant, and for which the type of the variable is obvious.

C's type qualifiers also have a different syntax: UNIMPLEMENTED

let Int : extern global_variable; let Float : static other_global_variable;

This “:” syntax will become clearer when we have seen Type classes.