Thanks @Vindaar and @jyapayne... I can't keep up! 🙂
I was still mapping @Vindaars suggestion into a more general **Lazy** template
and @jyapayne anticipated my desire to reduce the redundant boilerplate even
further!
I will try to add his latest refinements to what I currently have.
You can also go crazy and get rid of even more boiler plate (I've added types
as well):
# env.nim
import macros, tables
import std/envvars, std/options
export envvars, options
type
EnvVarInfo = tuple[envType: string, envBody: NimNode]
# Store all o
I think this is exactly what you want, minus the `do:`
import macros
import std/envvars, std/options
type
EnvType = object
m_user: Option[string]
m_icloud_dir: Option[string]
var Env*: EnvType
macro defineEnv*(fieldName, body: untyp
I'm not 100% sure if I understand you correctly. This is what seems closest to
what I understand you have in mind. Note the comments I added:
import std/envvars, std/options
type
EnvType = object
m_user: Option[string]
m_icloud_dir: Option[string]
I've wasted more time than I'd like to admit trying to:
Fabricate a simple macro or template to reduce the tedious boilerplate code
required to setup up lazy ( deferred i.e. only define on first access) object
fields.
My stumbling block is extrapolating untype parameter data into valid Nim
acc