gleam-lang / gleam

⭐️ A friendly language for building type-safe, scalable systems!
https://gleam.run
Apache License 2.0
16.51k stars 691 forks source link

Allow arithmetic guard expressions #1756

Closed manveru closed 1 week ago

manveru commented 1 year ago

See https://www.erlang.org/doc/reference_manual/expressions.html#guard-expressions

lpil commented 1 year ago

Thank you

cdaringe commented 7 months ago

Thanks! It was pretty surprising to not be able to call very basic pure functions in gleam in guards. It's something i do quite often in ocaml. Would be rad if gleam tracked purity somehow (??maybe not possible??) and allowed a bit more capability than erlang does here... even if it means drastically different compiled output?

i dunno, i'm a rookie. don't listen to me ;)

lpil commented 7 months ago

Hello! It's not just a matter of purity, the VM only permits certain operations in guards for performance reasons. It is not possible to support arbitrary pure expressions.

Purity tracking itself would be easy :)

DanielleMaywood commented 1 week ago

I'm having a go at implementing this.