Thanks, that was helpful, for anyone interested here how my macro looks like:
    
    
    macro act(body: untyped): untyped =
       result = nnkObjConstr.newTree(ident"ActivationFunction")
       let flType = ident"NeuralFloat"
       expectLen(body, 2)
       for fn in body:
          expectKind(fn, nnkCall)
          let fnParam = fn[1]
          let fnName = fn[0]
          let fnBody = fn[2]
          let fnType = [flType, newIdentDefs(fnParam, flType)]
          let p = newProc(newEmptyNode(), fnType, fnBody, nnkLambda)
          let field = nnkExprColonExpr.newTree(fnName, p)
          result.add field
    
    let sigmoid* = act:
       fn(x): 1 / (1 + exp(-x))
       deriv(fx): fx * (1 - fx)
    
    
    
    Run

Reply via email to