I have a proc which I want to directly include in my code, that's why I decided
templates is the way to go.
For example, in my caller proc I have:
case someVar
of 0: result = doSth()
...
Run
(obviously doSth() also returns a value)
Now, to make this work I converted my doSth() in this template:
template Core_Print_Templ*(xl: ExpressionList): Value =
let v = xl.evaluate(forceArray=true).a
echo v[0].stringify(quoted=false)
v[0]
Run
So, basically result (in my caller proc) gets the value of v[0] from the
template.
Now, the question is: how could I solve this, while keeping the
Core_Print_Templ as a template, if this function has more than one exit points
- meaning: if i returns a result from different locations?
For example, the following code (currently a proc), how could I turn this into
a template?
proc Core_Not*[F,X,V](f: F, xl: X): V {.inline.} =
let v0 = f.validateOne(xl.list[0],[BV,IV])
case v0.kind
of BV:
if v0.b: result = TRUE
else: result = FALSE
of IV:
result = valueFromInteger(bitnot(v0.i))
else: discard
Run
(I know templates is about code being substituted ed directly in the caller
code, but I still do not fully understand how it works - so any ideas are more
than welcome)