Sorry for the late response, here is a starting point for a macro you might 
want 
    
    
    import std/macros
    macro defVal(defVal: typed, p: untyped): untyped =
      result = p
      result[^1].add quote do:
        return `defVal`
      echo result.repr # Shows the code at compile time this macro emits
    
    proc a(i: int): int {.defVal: 100} =
      if i > 0:
        return 300
    
    
    assert a(1) == 300
    assert a(0) == 100
    
    
    Run

Reply via email to