all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Drew Adams" <drew.adams@oracle.com>
To: "'Xue Fuqiao'" <xfq.free@gmail.com>, <help-gnu-emacs@gnu.org>
Subject: RE: About `catch' and `throw'
Date: Fri, 21 Dec 2012 09:03:19 -0800	[thread overview]
Message-ID: <6EB1418B063C4F8CAFA179007459A7A5@us.oracle.com> (raw)
In-Reply-To: <20121221200001.891d30e881f25580089bbc5b@gmail.com>

> I'm reading the Emacs Lisp Reference Manual, and I met a 
> problem.  In the node `Catch and Throw', it says:
> 
> throw is used inside a catch, and jumps back to that catch. 
> For example:
>      (defun foo-outer ()
>        (catch 'foo
>          (foo-inner)))
>      (defun foo-inner ()
>        ...
>        (if x
>            (throw 'foo t))
>        ...)
> 
> but the `throw' is used outside the `catch', I'm confused.  
> Can anybody help?

It's about dynamic extent (scope, if you like) vs lexical scope.  It should
perhaps not say "inside", as that is a bit ambiguous.  It really means that the
`throw' is evaluated during the evaluation of the sexp inside the `catch'.  The
`throw' need not be lexically inside the `catch'.

During the evaluation of code that is lexically inside the `catch', a `throw'
that is evaluated throws back to that `catch'.  And if there is more than one
`catch' with the same label then it throws to the one that is lexically nearest
(i.e., innermost, outside the `throw'), which is also the most recent.

This part of the text should make it clear:

 "The `throw' need not appear lexically within the `catch' that
 it jumps to.  It can equally well be called from another function
 called within the `catch'.  As long as the `throw' takes place
 chronologically after entry to the `catch', and chronologically
 before exit from it, it has access to that `catch'."

That last sentence says it better than I have said it here.  It's really about
dynamic extent ("chronologically"), not lexical scope.




  reply	other threads:[~2012-12-21 17:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-21 12:00 About `catch' and `throw' Xue Fuqiao
2012-12-21 17:03 ` Drew Adams [this message]
2012-12-22 17:50   ` Stefan Monnier
     [not found]   ` <mailman.15933.1356198906.855.help-gnu-emacs@gnu.org>
2012-12-22 20:33     ` Pascal J. Bourguignon
2012-12-21 19:08 ` Pascal J. Bourguignon
     [not found] ` <mailman.15880.1356116940.855.help-gnu-emacs@gnu.org>
2013-01-05  0:57   ` David Combs
2013-01-08 16:08     ` Stefan Monnier
     [not found]     ` <mailman.16939.1357661400.855.help-gnu-emacs@gnu.org>
2013-02-13  1:08       ` David Combs

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=6EB1418B063C4F8CAFA179007459A7A5@us.oracle.com \
    --to=drew.adams@oracle.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=xfq.free@gmail.com \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.