M
Modular9mo ago
Xcur

Alias does not work with raises String methods

I have a string i know at compile time and I was writing a function to split it into each of the new lines, but because split has a raises flag it cannot be run at compile time and stored as an alias. I noticed there is a TODO to allow this, and im curious when will alias work with potentially raising functions? Here is my sample code:
alias string: String = \
"""Hello World
Hello World
Hello World"""

# does not work due to raises flag
alias lines = string.split("\n")

fn main() raises:
# uncomment and this works
# let lines = string.split("\n")

for i in range(len(lines)):
print(lines[i])
alias string: String = \
"""Hello World
Hello World
Hello World"""

# does not work due to raises flag
alias lines = string.split("\n")

fn main() raises:
# uncomment and this works
# let lines = string.split("\n")

for i in range(len(lines)):
print(lines[i])
1 Reply
shib
shib9mo ago
This isn't on the timeline, but it's something we're keeping an eye on. It would be a very useful feature for metaprogramming. The idea is that if a function raises inside a parameter context, it just becomes a compilation error
Want results from more Discord servers?
Add your server