carbon-lang
carbon-lang copied to clipboard
Implement `Print`
Return is performing the same function as Print for other data types. Print on the other hand only accepts string data type rather than all data types. For instance, attempting to Print the result of the main function of "/explorer/testdata/array/nested.carbon" returns:
a type error in Print argument 0 expected: String actual: i32
return on the other hand functions the same way print does.
Wouldn't it be practical if Print supported all data types?
The current Print is just a stub while other languages features are built. I'll leave this open for tracking, but I don't think the explorer is ready yet to do it.
Hello, you can print i32 values in Print("") using {0}, value. That is an example:
fn Main() -> i32 {
var num1: i32 = 0;
var num2: i32 = 0;
Print("The sum is: {0}", num1+num2);
return 0;
}
I hope this will help you.
Understood, will give you feedback on what I see
It has worked. Is there support for f32?
Currently, it does not seem possible to declare f32 variables or even use them.
Yes. That's my experience so far with f32 as I am trying to build something in Carbon. I will keep exploring.
Note, this is blocked on #2110