help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About `catch' and `throw'


From: Pascal J. Bourguignon
Subject: Re: About `catch' and `throw'
Date: Fri, 21 Dec 2012 20:08:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux)

Xue Fuqiao <xfq.free@gmail.com> writes:

> I'm reading the Emacs Lisp Reference Manual, and I met a problem.  In the 
> node 
> 10.5.1(http://www.gnu.org/software/emacs/manual/html_node/elisp/Catch-and-Throw.html#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?

The point is that catch/throw is a dynamic mechanism, not a lexical one.
So it is bad to say "outside", since this has a spacial conotation.

throw can be used WHEN catch is executing, or WHEN it is not.

If you call (throw 'something result) WHEN there's a (catch 'something …)
executing, then the control will pass from the throw expression to the
catch expression, and the catch expression will return the result
passed to throw.

It's only a question of time, of WHEN catch is being evaluated and WHEN
throw is evaluated.




I could talk you about block and return-from which are a lexical
mechanism, with which what matters is WHERE the return-from is relative
to the lexical scope defined by block, but the current implementation
(even in emacs-24) is full of bugs.  If you want, ask again on
news:comp.lang.lisp and we'll tell you about catch/throw and
block/return-from in Common Lisp.

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]