What do you think about using the template?
template defSayText(text: string): untyped =
proc sayText() =
echo text
sayText
template defSetText(text: string): untyped =
proc setText(newText: string) =
text = newText
setText
let (sayText, setText) = block:
var text = "Hello Nim!"
(
defSayText(text),
defSetText(text)
)
sayText() # prints "Hello Nim!"
setText("Hello world!")
sayText() # prints "Hello world!"
Run
- Idiomatic way of creating named closures slonik_az
- Idiomatic way of creating named closures Clonk
- Idiomatic way of creating named closures slonik_az
- Idiomatic way of creating named closures doongjohn
- Idiomatic way of creating named closures shirleyquirk
