
pub fn convert(temp) {
case temp {
| {"c", t} -> ((t*(9/5))+32)
| {"f", t} -> ((t-32)*5/9)
}
}
I've tried various forms of this and it seems arbitrary parenthesis are not allowed. Is this expected behavior?
Parenthesis would be nice but they would make the syntax ambiguous. Take this program:
fn run() {
name
(1 * 2)
}
Is it a discarded variable followed by a grouped expression or is it calling the function name with the argument 1 * 2? Whitespace is syntactically irreverent in Gleam so we cannot tell.
If you wish to group expression to change precedence you can use begin end, which sadly is somewhat unwieldy.
@lpil How would you approach writing ((t*(9/5))+32)? If you do t * 9 / 5 + 32 then t*9 would happen first considering order of operations, no?
That expression evalutes to the same value if all the parens are removed, but if you want to change the precedence either use begin end or extract variables.
let x = 9 / 5
t * x + 32
t * begin 9 / 5 end + 32
I'm going to close this as there's no work to be done. If you have an idea for nicer syntax here please open a new issue. Thank you :)
Is it a discarded variable followed by a grouped expression or is it calling the function name with the argument 1 * 2? Whitespace is syntactically irreverent in Gleam so we cannot tell.
Well in OCaml it would be the function name called with the single argument of 1 * 2. ^.^
OCaml is certainly more elegant here! :)
On Thu, 13 Jun 2019, 17:41 OvermindDL1, notifications@github.com wrote:
Is it a discarded variable followed by a grouped expression or is it
calling the function name with the argument 1 * 2? Whitespace is
syntactically irreverent in Gleam so we cannot tell.Well in OCaml it would be the function name called with the single
argument of 1 * 2. ^.^—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
https://github.com/lpil/gleam/issues/155?email_source=notifications&email_token=ABOZVBVNHSWR3G36RFMKW63P2J2DXA5CNFSM4HHBRHAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODXUJLGA#issuecomment-501781912,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABOZVBRIAADPNNBWF4FTJSDP2J2DXANCNFSM4HHBRHAA
.
I get an error with begin .. end. Is it no longer supported?
error: Unknown variable
┌─
│
29 │ 7 * begin 9 / 5 end + 32
│ ^^^^^ did you mean `Seattle`?
The name `begin` is not in scope here.
Hello! It use braces these days
7 * { 2 + 3 }