Protean-Labs / mesh

The Mesh Engine that implements the Mesh Language, a computational language for web3.
Apache License 2.0
1 stars 0 forks source link

ELet type doesn't have a representation for its scope #34

Closed ThierryBleau closed 3 years ago

ThierryBleau commented 3 years ago

Currently, ELet is defined as ELet(pattern, expr) where the expr values are bound to variables declared in pattern. This doesn't define the scope where these variables should be bound. Simple fix: Redefine ELet to have the scope as a second expression -> ELet(pattern, expr, expr).

cvauclair commented 3 years ago

@ThierryBleau What about the following Mesh code:

let x = 0;
x + 2;

let y = "hello";
y ++ " world";

Should it be parsed as:

  1. A list of two expressions (i.e.: two ELet expressions with x+2 and y ++ " world" as their respective scopes)
  2. A single ELet expression where the scope includes the second ELet
  3. Parsing error
cvauclair commented 3 years ago

Moreover, defining the let binding AST node as ELet(pattern, expr, expr) implies that the following mesh code is invalid:

let x = 2;
let y = "hello";
let z = true;
ThierryBleau commented 3 years ago

@ThierryBleau What about the following Mesh code:

let x = 0;
x + 2;

let y = "hello";
y ++ " world";

Should it be parsed as:

  1. A list of two expressions (i.e.: two ELet expressions with x+2 and y ++ " world" as their respective scopes)
  2. A single ELet expression where the scope includes the second ELet
  3. Parsing error

Should be the second option

ThierryBleau commented 3 years ago

Moreover, defining the let binding AST node as ELet(pattern, expr, expr) implies that the following mesh code is invalid:

let x = 2;
let y = "hello";
let z = true;

How so?

cvauclair commented 3 years ago

As it currently stands, since the parser expects a list of expressions (with let bindings being defined as ELet(pattern, expr), the "scope" of a let binding is all the expressions of the list after the let binding.

ThierryBleau commented 3 years ago

Is there a way to access the list of subsequent expressions during type inference?