zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-users@zsh.org
Subject: Re: return up two levels?
Date: Mon, 10 Mar 2014 19:42:39 +0000	[thread overview]
Message-ID: <20140310194239.0a3bde92@pws-pc.ntlworld.com> (raw)
In-Reply-To: <531E0393.6060106@eastlink.ca>

On Mon, 10 Mar 2014 11:25:23 -0700
Ray Andrews <rayandrews@eastlink.ca> 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


  reply	other threads:[~2014-03-10 19:48 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-10 11:51 zdotdir Yuri D'Elia
2014-03-10 12:01 ` zdotdir Aaron Kaufman
2014-03-10 13:03   ` zdotdir Yuri D'Elia
2014-03-10 15:32 ` zdotdir Bart Schaefer
2014-03-10 17:28   ` zdotdir Yuri D'Elia
2014-03-10 18:25     ` return up two levels? Ray Andrews
2014-03-10 19:42       ` Peter Stephenson [this message]
2014-03-11  3:00         ` Ray Andrews
2014-03-11  3:33           ` Kurtis Rader
2014-03-11 14:54             ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140310194239.0a3bde92@pws-pc.ntlworld.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).