V: Freeze on strconv.v_sprintf

Created on 31 May 2020  路  7Comments  路  Source: vlang/v

Hi! I'm new to V but I find it promising and hope it will become more popular.
When I execute the example in v_sprintf, it runs endlessly. Surprisingly, all tests in strconv are OK! Maybe you could add the "Hello world" example in tests?
Again, thank you for your job.

Bug

Most helpful comment

I didn't see it ;) but it is documented here : https://github.com/vlang/v/blob/master/doc/docs.md#strings .
My code is:

a := 1234
println("${a:06d}")

All 7 comments

This is due to a known bug with the implementation of main and how it interferes with varargs.
It would be fixed soon, when main is not treated as specially as it is now.
If you put the example in another function, then call it in main, it should work:
ordinary_function

The tests work since they are executed inside test_ functions not inside main.

You're right. It works outside of main.

@shnorbluk Anyway, prefer the use of string interpolation: "Hello $a"
v_sprintf it there only in orderd to simplfy C portings :)

Yes, to get compile time string concatenation. But my need was to generate numbers padded with zeros, and printf seemed the simplest way.

you can use string concatenation like this:

fn main(){
    a := 1234
    allign_l := "[${a:-10}]"
    allign_r := "[${a:10}]"
    println("$allign_l $allign_r")
}

:)

I didn't see it ;) but it is documented here : https://github.com/vlang/v/blob/master/doc/docs.md#strings .
My code is:

a := 1234
println("${a:06d}")
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cjmxp picture cjmxp  路  3Comments

markgraydev picture markgraydev  路  3Comments

elimisteve picture elimisteve  路  3Comments

PavelVozenilek picture PavelVozenilek  路  3Comments

lobotony picture lobotony  路  3Comments