Why [rune()] is not a function, but rather a language construct for type conversion!

Hi all,
I would have more clarification about this syntax [runeVariableName := rune(int32VariableName)], I know that it converts int32VariableName to rune value and assign it in runeVariableName which type is rune. My question is why it is not considered a function despite the fact that it behaves like a function and we can assign it exactly a signature similar to functions like this ‘’‘func rune(i int32)rune {}’‘’ ?
I hope to find a convincing answer.
ChatGPT’s answers not convinced me. I think “If it quacks like a duck, walks like a duck, it’s probably a duck.” why not?

Hello there. Don’t mix type casting and functions. As in all other languages, go has reserved key words and the name of the types are one of them.

Even if you create func rune(i int32) rune {...}, you’ll immediately get the NotAType error that return type rune is a function and any other declaration of the rune in the same package will fail. Same goes for any other possible type. There are languages which do exactly the same. But also there are languages which have another way e.g., C-style type casting: num_double = (double)num_int;. That’s how developers of the language designed it. What’s left for us is just to accept and use it.

Even though it behaves like a function on an abstract level, it is just a type conversion and not a function. It will not create a call-stack, it is no garbage-collection interruption-point, there is no code which is executed and you cannot use it as value of a variable with the function-type signature.

Type conversion is a language construct which behaves different to functions if you look below the abstraction and so it would be confusing to call it a function.

Besides type coversion there are also other helpers which look like function, but are language constructs like: len(), append(), make()


This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.