Can someone explain why return does not work in a stringtomessage

    MakeMessage<public><localizes>(Text:string):message = 
        return "{Text}" 

I understand it works if you do not use the return keyword. But why exactly is that?

Hey @RandomFoghorn how are you?

The reason why it doesn’t works when you use return is because, in Verse, functions written with = are expression-based, not imperative.

Here are three examples showing why and how it works:

  1. This works:
MakeMessage<public><localizes>(Text:string):message =
    "{Text}"

because the function body is a single expression, and Verse implicitly returns its value.

  1. This does not work:
MakeMessage<public><localizes>(Text:string):message =
    return "{Text}"

because return is a statement, not an expression, and expression-bodied functions in Verse only accept expressions.

For localizes, the expression style is intentional and expected, since the localization system analyzes the returned expression directly.

Hope this helps you to understand!

3 Likes