For instance, I have a small dsl like: 
    
    
    dsl:
      algo1:
        evaluate:
          echo "Evaluation is " & $value
      algo2:
        evaluate:
          echo "Evaluation is " & $value
    
    
    Run

The role of `evaluate` is to retrieve the result of calculation using `algo1` 
or `algo2` that use different data structures in an external API. So when 
`evaluate` is called in the context of `algo1`, it must call a different API 
than when used in the context of `algo2`.

The simplest solution would be to use different names for `evaluate` in context 
1 vs 2, like `evaluate1` and `evaluate2`.

Another solution, in `evaluate`, would be being able to detect when walking up 
the AST if it contains NimNode calls with "algo1" or "algo2". But I don't think 
that you can walk up the AST to the root like you can do down to the children 
with 
[findChild](https://nim-lang.org/docs/macros.html#findChild.t%2CNimNode%2Cuntyped)
 for instance.

Another idea is for `algo1` and `algo2` to set the algorithm used in a variable 
and let `evaluate` retrieve the value of that variable before calling the API. 
But if the macro `evaluate` is executed in an `untyped` context from `algo1` / 
`algo2`, it can't access that variable content because that context hasn't been 
semantically checked yet, if I understand correctly.

What would be an approach to solve that problem? Please note that I've 
simplified my problem and that in the real DSL, there could be multiple layers 
of block calls between `algoX` and `evaluate`.

Reply via email to