You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
V full version: V 0.4.8 5c65e58.a454f06
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 10 cpus, 64bit, little endian,
getwd: C:\Users\user\Downloads
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-10-25 17:08:19
vroot: OK, value: C:\Users\user\Desktop\Code\v
VMODULES: OK, value: C:\Users\user\.vmodules
VTMP: OK, value: C:\Users\user\AppData\Local\Temp\v_0
Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.41-127-ga454f064
.git/config present: true
CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.
thirdparty/tcc status: thirdparty-windows-amd64 b425ac82
What did you do? ./v -g -o vdbg cmd/v && ./vdbg test.v
fnadd(a int, b int) int {
return a + b
}
fnmain() {
res:= (add)(2, 4)
println("2 + 4 = ${res}")
}
What did you expect to see?
2 + 4 = 6 printed to stdout or a better error message
I am against this change. I see zero utility for something that can be confusing... is (add) supposed to mean to call add, or is it a cast, or is it something else?
Yes, I do know what it is meant to do, I simply don't know why the syntax should allow it... it just adds unnecessary complexity with no discernible benefit.
As far as other languages allowing it... V is not those other languages. It doesn't have to do what they do, with the same syntax.
The conclusion above, "The following works, meaning that add can be used as an expression:" is also incorrect. add is not being used as an expression in that example, the code is simply creating a function pointer and calling add through that pointer. That has nothing to do with an expression. It may appear as though it is being used as an expression, if you assume the syntax of other languages.
ptr := add in the example case is virtually the same as doing ptr := fn(a int, b int) int { return a + b } - an anonymous function pointer.
ptr:=fn(a int, b int) int { return a + b }
res:=ptr(2, 4)
println('2 + 4 = ${res}')
V doctor:
What did you do?
./v -g -o vdbg cmd/v && ./vdbg test.v
What did you expect to see?
2 + 4 = 6
printed to stdout or a better error messageWhat did you see instead?
Additional information
The following works, meaning that
add
can be used as an expression:As for other languages, this prints
2 + 4 = 6
in Go and in Rust:Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
Huly®: V_0.6-21101
The text was updated successfully, but these errors were encountered: