Open Ryan1729 opened 3 years ago
If you change const
to let
or if you wrap the code after it in static:
then there is no error. No difference between var bool
and bool
. Is Nim supposed to support const procs at all? This compiles:
type Spell = proc (state: bool)
proc requirePlayer(): Spell =
return proc (state: bool) =
discard
const spell = requirePlayer()
var state = true
spell(state)
But a simple example like this doesn't:
proc foo() = discard
const bar = foo
bar()
In case you don't know, const
is for constants evaluated at compile time while let
is runtime. If you want to use your compile time closure value at runtime, then Nim would have to generate code for it, which seems to cause problems such as this.
Attempting to compile the following examples involving
proc
s that returnproc
s that capture variables, result ingcc
errors.Example
Current Output
Expected Output
The program compiles successfully, or an error message explaining why this cannot be done.
Example
Here's a slightly longer example that hopefully makes the motivation for wanting to do this clearer.
Current Output
Expected Output
The program compiles successfully, or an error message explaining why this cannot be done.
Additional Information
The posted output is from this version:
But the problem happens with this version as well: