Replies: 7 comments 22 replies
-
V doesn't allow local fn declarations, but in this case it would be better for the parser than fn local(n int) {
if n>1 {
local(n-1)
}
println('hello world')
} |
Beta Was this translation helpful? Give feedback.
-
@ntrel but I remember local fn declaration examples like this worked... fn func() {
local := fn() {
println('hello world')
}
local()
} |
Beta Was this translation helpful? Give feedback.
-
That works (I meant you can't have named function declarations inside a function). In the body of the anonymous function above, you can't use the name |
Beta Was this translation helpful? Give feedback.
-
@ntrel yes that makes sense. I think we could simply use |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Update: A preliminary decision is to accept this. Syntax suggestions are wanted and welcome! |
Beta Was this translation helpful? Give feedback.
-
Having calls like And what happens if you have functions within functions and need to call the outermost My suggestion would be an optional means of declaring a symbol, e.g.:
The symbol
It also looks ambiguous to a person. Recursive functions in other langs typically need a name, e.g. in JavaScript - so this wouldn't be surprising to most people. This seems more consistent with function syntax/semantics (in V) in general. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Update: A preliminary decision is to accept this. Syntax suggestions are wanted and welcome!
Local functions are very useful. Thanks to the recently implemented anonymous function, we can now write, e.g.,
However, sometimes local functions need to be recursive, so please consider implementing recursive anonymous function. Here's a possible syntax.
A more real example:
Beta Was this translation helpful? Give feedback.
All reactions