You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aiken uses {} for lexical scope, which is rather unusual as people are generally used to (). At the moment, using brackets in an unexpected location may result in a not_fn error as the compiler infers a function call due to brackets.
For example:
letfoo=bar(some_expression||True)&&baz
actually parses as:
letfoo=bar(some_expression||True)&&baz
which results in attempting to use bar as a function with some_expression || True as argument. Here, one should have written:
letfoo=bar{some_expression||True}&&baz
which is rather unusual for developers.
Possible ways forward:
Improve this particular error message to hint what I just did; re-explain how block-scope are made via {} and not brackets (), with an example.
Forbid newlines before open brackets; turn it into a parse-error (this holds for both functions and tuple definitions)
Allow use of brackets in (at least) boolean and arithmetic expressions for lexical scoping.
The text was updated successfully, but these errors were encountered:
This changes allow to use parenthesis `(` `)` to encapsulate
expressions in addition to braces `{` `}` used to define blocks.
The main use-case is for arithmetic and boolean expressions for which
developers are used to using parenthesis. For example:
```
{ 14 + 42 } * 1337
```
can now be written as:
```
( 14 + 42 ) * 1337
```
This may sound straightforward at first but wasn't necessarily trivial
in Aiken given that (a) everything is an expression, (b) whitespaces
do not generally matter and (c) there's no symbol indicating the end
of a 'statement' (because there's no statement).
Thus, we have to properly disambiguate between:
```
let foo = bar(14 + 42)
```
and
```
let foo = bar
(14 + 42)
```
Before this commit, the latter would be interpreted as a function call
and would lead to a somewhat puzzling error. Now, the newline serves
as a delimiting symbol. The trade-off being that for a function call,
the left parenthesis has to be on the same line as the function name
identifier -- which is a fair trade off. So this is still allowed:
```
let foo = bar(
14 + 42
)
```
As there's very little ambiguity about it.
This fixes#236 and would seemingly allow us to get rid of the leading
`#` in front of tuples.
This changes allow to use parenthesis `(` `)` to encapsulate
expressions in addition to braces `{` `}` used to define blocks.
The main use-case is for arithmetic and boolean expressions for which
developers are used to using parenthesis. For example:
```
{ 14 + 42 } * 1337
```
can now be written as:
```
( 14 + 42 ) * 1337
```
This may sound straightforward at first but wasn't necessarily trivial
in Aiken given that (a) everything is an expression, (b) whitespaces
do not generally matter and (c) there's no symbol indicating the end
of a 'statement' (because there's no statement).
Thus, we have to properly disambiguate between:
```
let foo = bar(14 + 42)
```
and
```
let foo = bar
(14 + 42)
```
Before this commit, the latter would be interpreted as a function call
and would lead to a somewhat puzzling error. Now, the newline serves
as a delimiting symbol. The trade-off being that for a function call,
the left parenthesis has to be on the same line as the function name
identifier -- which is a fair trade off. So this is still allowed:
```
let foo = bar(
14 + 42
)
```
As there's very little ambiguity about it.
This fixes#236 and would seemingly allow us to get rid of the leading
`#` in front of tuples.
Aiken uses
{}
for lexical scope, which is rather unusual as people are generally used to()
. At the moment, using brackets in an unexpected location may result in anot_fn
error as the compiler infers a function call due to brackets.For example:
actually parses as:
which results in attempting to use
bar
as a function withsome_expression || True
as argument. Here, one should have written:which is rather unusual for developers.
Possible ways forward:
The text was updated successfully, but these errors were encountered: