Index: polemy/eval.d ================================================================== --- polemy/eval.d +++ polemy/eval.d @@ -128,19 +128,19 @@ (LayeredExpression e) { if( e.lay == "@macro" ) return macroEval(e.expr, ctx, false); else - return eval(e.expr, ctx, false, e.lay); + return eval(e.expr, ctx, true, e.lay); }, (LetExpression e) { // for letrec, we need this, but should avoid overwriting???? // ctx.set(e.var, "@v", new UndefinedValue, e.pos); - Value v = eval(e.init, ctx, true, lay); if(splitCtx) ctx = new Table(ctx, Table.Kind.NotPropagateSet); + Value v = eval(e.init, ctx, true, lay); ctx.set(e.var, (e.layer.length ? e.layer : lay), v, e.pos); return eval(e.expr, ctx, false, lay); }, (FuncallExpression e) { @@ -381,6 +381,12 @@ } unittest { assert_eq( evalString(`@@t = fun(x){x+1}; @t(123)`).val, new IntValue(BigInt(124)) ); + // there was a bug that declaration in the first line of function definition + // cannot be recursive + assert_nothrow( evalString(`def foo() { + def bar(y) { if(y<1) {0} else {bar(0)} }; + bar(1) +}; foo()`) ); } ADDED sample/macro.pmy Index: sample/macro.pmy ================================================================== --- sample/macro.pmy +++ sample/macro.pmy @@ -0,0 +1,57 @@ +@macro twice(x) { x; x }; +@macro max(x,y) { + var _x = x; # no hygenic macro btw.... + var _y = y; # no hygenic macro btw.... + if(_x<_y){_y}else{_x} +}; +def maxNormal(x,y) { + if(x