gleam-lang/suggestions

Adding an else block for conditional compilation.

Opened this issue · 0 comments

Writing this up as it was discussed in discord.
example:

if erlang {
  pub external fn length(of: List(a)) -> Int =
    "erlang" "length"
} else {
  pub fn length(of of: List(a)) -> Int {
    fold(of, 0, fn(_, count) { count + 1})
  }
}

This might be useful if gleam supports other targets, so potentially in the future but not very soon.
else should be limited to only pure gleam, i.e. no calls to external as that is the only way it is guaranteed to continue working when new targets are added.