mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-05 03:17:50 +08:00
Support defining recursive functions with fn.
This commit is contained in:
parent
64c9bf842d
commit
c19a48ea8a
|
@ -199,8 +199,12 @@ func compileFn(cp *compiler, fn *parse.Form) Op {
|
|||
op := cp.lambda(pn)
|
||||
|
||||
return func(ec *EvalCtx) {
|
||||
// Initialize the function variable with the builtin nop
|
||||
// function. This step allows the definition of recursive
|
||||
// functions; the actual function will never be called.
|
||||
ec.local[varName] = NewPtrVariable(&BuiltinFn{"<shouldn't be called>", nop})
|
||||
closure := op(ec)[0].(*Closure)
|
||||
closure.Op = makeFnOp(closure.Op)
|
||||
ec.local[varName] = NewPtrVariable(closure)
|
||||
ec.local[varName].Set(closure)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user