carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Implement `Print`

Open CodeKitty-max opened this issue 3 years ago • 6 comments

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?

CodeKitty-max avatar Jul 28 '22 13:07 CodeKitty-max

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.

jonmeow avatar Jul 28 '22 14:07 jonmeow

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.

Zhanytrix avatar Jul 28 '22 17:07 Zhanytrix

Understood, will give you feedback on what I see

CodeKitty-max avatar Jul 28 '22 17:07 CodeKitty-max

It has worked. Is there support for f32?

CodeKitty-max avatar Jul 28 '22 17:07 CodeKitty-max

Currently, it does not seem possible to declare f32 variables or even use them.

Zhanytrix avatar Jul 28 '22 17:07 Zhanytrix

Yes. That's my experience so far with f32 as I am trying to build something in Carbon. I will keep exploring.

CodeKitty-max avatar Jul 28 '22 17:07 CodeKitty-max

Note, this is blocked on #2110

jonmeow avatar Oct 17 '22 16:10 jonmeow