Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: return up two levels?
On Mon, 10 Mar 2014 11:25:23 -0700
Ray Andrews <rayandrews@xxxxxxxxxxx> wrote:
> Didn't I read somewhere that one can return from a function 'up two
> levels'? i.e. that if function1 calls function2, that function2 can
> return both itself and function1?
function1() { function2; print Doesn\'t get called; }
function2() { trap 'return' EXIT; print Does get called; }
% function1
Does get called
Of course you can return at the point you set the trap, I'm just
illustrating that the forced return of the parent function isn't tied to
the child function returning immediately.
And regardless of options EXIT traps are only associated with the
immediate parent, so...
function0() { function1; print Does get called, too; }
% function0
Does get called
Does get called, too
So forcing a whole hierarchy to return immediately is harder work. You can set an exit trap inside an exit trap, if you want (I haven't tried but I have a vague memory of debugging this years ago), but it gets messy.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author