Differences with Solidity

Eclair is based on the Solidity syntax but behaves differently in many aspects. It is worth nothing that at this point, Eclair only implements a subset of the Solidity language.

This section highlights some of the differences between Eclair and Solidity.

Static vs dynamic typing

Solidity is statically typed, meaning that the type of each variable must be known at compile time and the compiler will check that the types are used correctly. On the other hand, Eclair is dynamically typed and variables are only checked at runtime. Furthermore, variables do not need to be declared explicitly.

>> a = 1; // a is an integer
>> a + 2
3
>> a + "bar"
Error: cannot add uint256 and string
>> a = "foo"; // a is now a string
>> a + "bar"
"foobar"

Scopes

Eclair has a different scoping mechanism compared to Solidity. In particular, Eclair only creates a new scope for function, not for blocks. This means that the following code will work in Eclair but not in Solidity:

if (true) {
    a = 1;
} else {
    a = 2;
}
console.log(a);

However, the following code will not work:

>> function foo() { a = 1; }
>> console.log(a)
Error: a is not defined

First-class functions and types

Internally, almost everything in Eclair returns a value. This means that functions and types can be passed around as arguments to other functions. For example, the following is valid in Eclair:

>> usdc = ERC20(0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48)
>> usdcBalance = usdc.balanceOf
>> usdcBalance(0x47ac0Fb4F2D84898e4D9E7b4DaB3C24507a6D503)
542999999840000
>> tu16 = type(uint16)
>> tu16.max
65535

Anonymous functions

Eclair supports anonymous functions, which are functions that are not bound to a name. These functions are quite limited in features since they need to be written as a valid Solidity expression. We adopted the following syntax:

>> (x) >> x + 1
function(any x)

This is particularly helpful when using higher-order functions like map and filter:

>> [1, 2, 3].map((x) >> x + 1)
[2, 3, 4]
>> [1, 2, 3].filter((x) >> (x % 2 == 0))
[2]

Note that because >> is parsed as the right shift operator, you need to wrap the anonymous function in parentheses if it contains an operator with a lower priority than >>, such as ==.