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

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

Re: condition-case


From: Pascal J. Bourguignon
Subject: Re: condition-case
Date: Mon, 29 Nov 2010 21:17:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux)

Fren Zeee <frenzeee@gmail.com> writes:

> On Nov 29, 11:52 am, Fren Zeee <frenz...@gmail.com> wrote:
>> On Nov 28, 1:30 am, David Kastrup <d...@gnu.org> wrote:
>>
>> > Fren Zeee <frenz...@gmail.com> writes:
>> > > I am looking for some theory and small hello world type examples to
>> > > teach to newbies the usage of
>>
>> > > condition-case
>>
>> > > and other such special forms. The emacs lisp manual is not the
>> > > clearest doc in existence on emacs lisp.
>>
>> > Why don't you consult the clearest doc in existence then?
>>
>> > --
>> > David Kastrup
>>
>> maybe an experienced programmer or computer scientist who can give a
>> good heuristic and conceptual explanation ...
>
> David, I forgot to indicate that I am not just looking for crude usage
> info but also the nuanced conceptual idea which motivates the concept.
> These are works of art and only a sensitive soul can do justice to
> explanation for newbies. Even a statement in C such as the for loop
> took a while to evolve. In lisp, we take special pleasure at its
> syntactical structure and how it manages to carry rich semantics.

First, you should forget about condition-case, and use instead
handler-case.  

(defmacro handler-case (expression &rest clauses)
  "Common-Lisp
IMPLEMENTATION: The clause variable symbols are substituted by one single
                condition-case variable symbol.  This may cause problems
                if the same symbol is used as data or if it's a dynamic 
                variable.
"
  (let* ((var (gensym))
         (neclause (assoc :NO-ERROR clauses))
         (nell     (cadr neclause))
         (nebody   (cddr neclause))
         (handlers (mapcar (lambda (clause)
                             (let ((typespec (car clause))
                                   (clausvar (cadr clause))
                                   (body     (cddr clause)))
                               (cons (if (and (consp typespec)
                                              (eq 'or (car typespec)))
                                         (cdr typespec) 
                                         typespec)
                                     (if (null clausvar)
                                         body
                                         (subst  var (car clausvar) body)))))
                           (remove neclause clauses))))
    (if neclause
        `(condition-case ,var
             (multiple-value-bind ,nell ,expression ,@nebody)
           ,@handlers)
        `(condition-case ,var
             ,expression
           ,@handlers))))


Condition-case is elisp specific.  Better use a more common operator,
such as handler-case.



Then you could read the excelent Kent Pitman's paper:

http://www.nhplace.com/kent/Papers/Condition-Handling-2001.html                 
Condition Handling in the Lisp Language Family      


-- 
__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]