all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Fwd: condition-case
       [not found] <33e7a222-992c-4fc2-bbd2-d987a0d4d9b1@j32g2000prh.googlegroups.com>
@ 2010-11-28 23:44 ` Fren Zeee
  2010-11-29  1:25   ` Glenn Morris
       [not found] ` <877hfxokvh.fsf@lola.goethe.zz>
  1 sibling, 1 reply; 9+ messages in thread
From: Fren Zeee @ 2010-11-28 23:44 UTC (permalink / raw)
  To: Emacs Dev [emacs-devel]

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

For your expert comments for newbies

---------- Forwarded message ----------
From: Fren Zeee <frenzeee@gmail.com>
Date: Sat, Nov 27, 2010 at 12:41 PM
Subject: condition-case
To: frenzeee@gmail.com


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.

Franz Xe

[-- Attachment #2: Type: text/html, Size: 667 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Fwd: condition-case
  2010-11-28 23:44 ` Fwd: condition-case Fren Zeee
@ 2010-11-29  1:25   ` Glenn Morris
  0 siblings, 0 replies; 9+ messages in thread
From: Glenn Morris @ 2010-11-29  1:25 UTC (permalink / raw)
  To: Fren Zeee; +Cc: Emacs Dev [emacs-devel]


> I am looking for some theory and small hello world type examples to
> teach to newbies the usage of
>
> condition-case

The Emacs Lisp Introduction covers condition-case.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
       [not found]                       ` <jwvbp4v9enz.fsf-monnier+gnu.emacs.help@gnu.org>
@ 2010-12-10 18:40                         ` Ted Zlatanov
  2010-12-10 21:43                           ` condition-case Stefan Monnier
  2010-12-13 17:10                           ` condition-case Ted Zlatanov
  0 siblings, 2 replies; 9+ messages in thread
From: Ted Zlatanov @ 2010-12-10 18:40 UTC (permalink / raw)
  To: help-gnu-emacs

On Thu, 09 Dec 2010 10:04:12 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> Here's what Pascal posted originally.
SM> The code looks fine (tho it needs a reindent to follow Elisp
SM> convention).  The docstring needs a completely rewrite, OTOH, to follow
SM> Elisp convention: first line should succintly describe the macro, and
SM> the rest should give details about what it does and what each
SM> param means.  I.e. someone not familiar with Common-Lisp should be able
SM> to understand how to use it.

Yes, that's not hard.  I was worried about the code's behavior.

>> (subst  var (car clausvar) body)))))

SM> Oh wait, I just noticed this one: `subst' is wrong here.  I know CL
SM> already uses it for similar purposes elsewhere, but it's simply wrong
SM> because `subst' doesn't know about Elisp binding rules.
SM> So (subst 'b 'a '(lambda () '(a b c))) will happily return
SM> (lambda () '(b b c)).  Better simply use `let', even if it has
SM> a performance cost.

I didn't catch that.  I don't know enough about ELisp vs. CL scoping and
binding rules to write this properly, unfortunately.  Can you show how
`let' could be used?  I'll take the code and provide the doc string and
reindent it, then propose the revised version in emacs-devel.

On Thu, 09 Dec 2010 05:34:02 +0100 "Pascal J. Bourguignon" <pjb@informatimago.com> wrote: 

PJB> Ted Zlatanov <tzz@lifelogs.com> writes:

>> Here's what Pascal posted originally.  I tested it a little and it seems
>> to work OK; it's basically syntactic sugar but pretty pleasant.  We
>> should also consider `handler-bind' which is like `handler-case' but
>> executes handlers directly.  Pascal, do you have an implementation of
>> that as well?

PJB> There's no condition-bind to wrap over.

PJB> I'm not sure it would be possible to implement handler-bind without
PJB> patching the virtual machine.

Stefan, WDYT?  Is `condition-bind' possible in today's GNU Emacs?  I
mean does the VM have any constraints that would block it?

Ted


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-10 18:40                         ` condition-case Ted Zlatanov
@ 2010-12-10 21:43                           ` Stefan Monnier
  2010-12-13 17:12                             ` condition-case Ted Zlatanov
  2010-12-13 17:10                           ` condition-case Ted Zlatanov
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2010-12-10 21:43 UTC (permalink / raw)
  To: help-gnu-emacs

PJB> There's no condition-bind to wrap over.
PJB> I'm not sure it would be possible to implement handler-bind without
PJB> patching the virtual machine.
> Stefan, WDYT?  Is `condition-bind' possible in today's GNU Emacs?  I
> mean does the VM have any constraints that would block it?

There used to be some allowance made in the C code for such a feature,
but since it was never used it bit-rotted and has "recently" been more
actively removed.  So adding a condition-bind or something like that
would require a fair bit of work, I think.  There is still some support
for part of it since errors can jump into the debugger, but currently
the debugger cannot return to the source of the error, it can only jump
back up the stack like condition-case does.


        Stefan


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-10 18:40                         ` condition-case Ted Zlatanov
  2010-12-10 21:43                           ` condition-case Stefan Monnier
@ 2010-12-13 17:10                           ` Ted Zlatanov
  2010-12-15  4:55                             ` condition-case Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2010-12-13 17:10 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 10 Dec 2010 12:40:06 -0600 Ted Zlatanov <tzz@lifelogs.com> wrote: 

TZ> On Thu, 09 Dec 2010 10:04:12 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>>> (subst  var (car clausvar) body)))))

SM> Oh wait, I just noticed this one: `subst' is wrong here.  I know CL
SM> already uses it for similar purposes elsewhere, but it's simply wrong
SM> because `subst' doesn't know about Elisp binding rules.
SM> So (subst 'b 'a '(lambda () '(a b c))) will happily return
SM> (lambda () '(b b c)).  Better simply use `let', even if it has
SM> a performance cost.

TZ> I didn't catch that.  I don't know enough about ELisp vs. CL scoping and
TZ> binding rules to write this properly, unfortunately.  Can you show how
TZ> `let' could be used?  I'll take the code and provide the doc string and
TZ> reindent it, then propose the revised version in emacs-devel.

...in other words, in the example you showed, is it just

(let ((b a))
  (lambda () '(b b c)))

or is it more complicated?

Ted


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-10 21:43                           ` condition-case Stefan Monnier
@ 2010-12-13 17:12                             ` Ted Zlatanov
  0 siblings, 0 replies; 9+ messages in thread
From: Ted Zlatanov @ 2010-12-13 17:12 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 10 Dec 2010 16:43:46 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

PJB> There's no condition-bind to wrap over.
PJB> I'm not sure it would be possible to implement handler-bind without
PJB> patching the virtual machine.
>> Stefan, WDYT?  Is `condition-bind' possible in today's GNU Emacs?  I
>> mean does the VM have any constraints that would block it?

SM> There used to be some allowance made in the C code for such a feature,
SM> but since it was never used it bit-rotted and has "recently" been more
SM> actively removed.  So adding a condition-bind or something like that
SM> would require a fair bit of work, I think.  There is still some support
SM> for part of it since errors can jump into the debugger, but currently
SM> the debugger cannot return to the source of the error, it can only jump
SM> back up the stack like condition-case does.

I also notice no one has complained in the last few years that
`condition-case' is insufficient.  So maybe `condition-bind' is simply
not necessary.

Ted


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-13 17:10                           ` condition-case Ted Zlatanov
@ 2010-12-15  4:55                             ` Stefan Monnier
  2010-12-15 16:50                               ` condition-case Ted Zlatanov
  0 siblings, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2010-12-15  4:55 UTC (permalink / raw)
  To: help-gnu-emacs

> ...in other words, in the example you showed, is it just

> (let ((b a))
>   (lambda () '(b b c)))

Yes.  I.e. let the interpreter perform the substitution, at run-time.


        Stefan


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-15  4:55                             ` condition-case Stefan Monnier
@ 2010-12-15 16:50                               ` Ted Zlatanov
  2010-12-16 22:03                                 ` condition-case Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Ted Zlatanov @ 2010-12-15 16:50 UTC (permalink / raw)
  To: help-gnu-emacs

On Tue, 14 Dec 2010 23:55:45 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

>> ...in other words, in the example you showed, is it just
>> (let ((b a))
>> (lambda () '(b b c)))

SM> Yes.  I.e. let the interpreter perform the substitution, at run-time.

OK, so would it work as:

(defmacro handler-case (expression &rest clauses)
  "Evaluate expression with `condition-case' and catch errors with CLAUSES.

Longer explanation here..."
  (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
                                       (let ((var (car clausvar)))
                                         body)))))
                           (remove neclause clauses))))
    (if neclause
        `(condition-case ,var
             (multiple-value-bind ,nell ,expression ,@nebody)
           ,@handlers)
      `(condition-case ,var
           ,expression
         ,@handlers))))

Does that new `let' that pops the clause need to evaluated?  And should
it maybe be a `lexical-let'?

Ted


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: condition-case
  2010-12-15 16:50                               ` condition-case Ted Zlatanov
@ 2010-12-16 22:03                                 ` Stefan Monnier
  0 siblings, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2010-12-16 22:03 UTC (permalink / raw)
  To: help-gnu-emacs

> OK, so would it work as:

> (defmacro handler-case (expression &rest clauses)
>   "Evaluate expression with `condition-case' and catch errors with CLAUSES.

> Longer explanation here..."
>   (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
>                                        (let ((var (car clausvar)))
>                                          body)))))

You need backquotes around the let.

> Does that new `let' that pops the clause need to evaluated?  And should
> it maybe be a `lexical-let'?

Whether it should be lexical or not is up to you.


        Stefan


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-12-16 22:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <33e7a222-992c-4fc2-bbd2-d987a0d4d9b1@j32g2000prh.googlegroups.com>
2010-11-28 23:44 ` Fwd: condition-case Fren Zeee
2010-11-29  1:25   ` Glenn Morris
     [not found] ` <877hfxokvh.fsf@lola.goethe.zz>
     [not found]   ` <4d4ecf83-ffd8-43d9-8c27-4123856273e9@21g2000prv.googlegroups.com>
     [not found]     ` <0b6e72ef-a605-4ac1-bc71-f3e180f162fb@j18g2000prn.googlegroups.com>
     [not found]       ` <87r5e3zxyw.fsf@kuiper.lan.informatimago.com>
     [not found]         ` <878w06lqcf.fsf@lifelogs.com>
     [not found]           ` <8762vaodaw.fsf@kuiper.lan.informatimago.com>
     [not found]             ` <8762v6ho6q.fsf@lifelogs.com>
     [not found]               ` <jwv62v6ljkb.fsf-monnier+gnu.emacs.help@gnu.org>
     [not found]                 ` <87hbepd50p.fsf@lifelogs.com>
     [not found]                   ` <jwvmxohh8yt.fsf-monnier+gnu.emacs.help@gnu.org>
     [not found]                     ` <87pqtc9sd5.fsf@lifelogs.com>
     [not found]                       ` <jwvbp4v9enz.fsf-monnier+gnu.emacs.help@gnu.org>
2010-12-10 18:40                         ` condition-case Ted Zlatanov
2010-12-10 21:43                           ` condition-case Stefan Monnier
2010-12-13 17:12                             ` condition-case Ted Zlatanov
2010-12-13 17:10                           ` condition-case Ted Zlatanov
2010-12-15  4:55                             ` condition-case Stefan Monnier
2010-12-15 16:50                               ` condition-case Ted Zlatanov
2010-12-16 22:03                                 ` condition-case Stefan Monnier

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.