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 string concatenation when defining const values #3208

Open george-grec opened 1 month ago

george-grec commented 1 month ago

This is currently not valid syntax:

pub const foo = "foo"
pub const foo_bar = foo <> "bar"

It would be great if this would work!

slightlybelowzen commented 1 month ago

Just wondering why this isn't allowed? Is there a reason (since it seems fairly reasonable) or was it just left to be implemented later?

lpil commented 1 month ago

Thank you! Good suggestion.

@slightlybelowzen It's just something no one has implemented. The stuff that people decide to work on is the stuff that gets done.

slightlybelowzen commented 1 month ago

Fair enough, I could try to hack something together this weekend, see if I get anywhere😀

lpil commented 1 month ago

Wonderful! Thank you

DeviousStoat commented 1 month ago

I started looking into that. Not sure if @slightlybelowzen has started something too but it doesn't matter too much to me if my code doesn't go anywhere, this is a pretty cool task to start getting familiar with the code. I just had a question @lpil, do we want to support any binary operation in const statements or just the string concatenation? If foo <> "bar" is allowed shouldn't any operation on consts be allowed too?

pub const foo = 5
pub const foo_bar = foo + 5
lpil commented 3 weeks ago

Just concatenation for now as it does not require compile time code execution to implement.

DeviousStoat commented 3 weeks ago

why doesn't concatenation require compile time code execution? we should inline the concatenation operation? If so then what's the difference with inlining other operations?

lpil commented 3 weeks ago

Because that's how Erlang works.

DeviousStoat commented 3 weeks ago

yeah I don't know I was more thinking about the javascript part. sorry about the questions, I was just trying to understand a bit more. I will try to make a PR anyway, we'll see

lpil commented 3 weeks ago

Thank you 💜