vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`strconv.v_sprintf` broken when using direct values

Hunam6 opened this issue · comments

OS: macos, macOS, 12.4, 21F79
Processor: 8 cpus, 64bit, little endian, Apple M1
CC version: Apple clang version 13.1.6 (clang-1316.0.21.2.5)

getwd: /Users/hunam/Documents/dev/go2v
vmodules: /Users/hunam/.vmodules
vroot: /Applications/v
vexe: /Applications/v/v
vexe mtime: 2022-06-20 19:00:57
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 473d26c

Git version: git version 2.32.1 (Apple Git-133)
Git vroot status: weekly.2022.24-43-g473d26ce
.git/config present: true
thirdparty/tcc status: thirdparty-macos-arm64 173c526e

What did you do?

import strconv

fn main() {
	x := 'hey'
	println(strconv.v_sprintf('%s', x)) // does work
	println(strconv.v_sprintf('%s', 'string')) // doesn't work
}

What did you see instead?

test.v:6:34: error: expression cannot be passed as `voidptr`
    4 |     x := 'hey'
    5 |     println(strconv.v_sprintf('%s', x))
    6 |     println(strconv.v_sprintf('%s', 'string'))
      |                                     ~~~~~~~~
    7 | }

I agree that if it is there, this should probably work, but... why use it? IMO, regular string interpolation is shorter and easier to understand.

Yeah I actually think these functions should be made private.

@penguindark what do you think?

printf-like functions are used a lot in Go, this is really handy for Go2V

It should be simple to change the printf style to interpolated. More "V-like" that way.

It should be simple to change the printf style to interpolated. More "V-like" that way.

Yes, I agree. At least for trivial stuff.

I don't think it will be simple, I would have to write a whole parser. Look at https://yourbasic.org/golang/fmt-printf-reference-cheat-sheet.

the go printf is another world,
anyway I was thinking to deprecate printf now that we have a good string interpolation.
It brings a lot of old and awful code in V, better to remove it.
Remember that there is always the big problem of the variadic parameters in V -_-

Also, when do we finally change string interpolation to only one consistent:
$var or ${var} -> {var}

You're welcome to work on it :)

ezoic increase your site revenue