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

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

Re: Calling different kinds of functions, which finish the same job


From: Kevin Rodgers
Subject: Re: Calling different kinds of functions, which finish the same job
Date: Tue, 11 Apr 2006 12:36:55 -0600
User-agent: Mozilla Thunderbird 0.9 (X11/20041105)

Herbert Euler wrote:
From: Kevin Rodgers <address@hidden>
To: address@hidden
Subject: Re: Calling different kinds of functions, which finish the same job
Date: Tue, 11 Apr 2006 09:49:29 -0600

[This doesn't belong on emacs-devel]


OK.  Sorry for having sent to emacs-devel.

What are "args of f1" etc? They are apparently not the arguments to a single call to f1, since you have these variations:

(apply ,func) ; this is tried first
(apply ,func (car ,largs)) ; then this is tried, while cdr'ing down largs

If all of the functions are defined, why would any of the function call signal an error? Why do you care which function is actually called? You certainly don't return that information, you only return the result of the first non-error-signalling call.


Suppose functions f1, f2, and f3 are all for inserting one space, but
without side effect or with different side effect;  f1 requires an
integeral argument as count, f2 requires an symbolic argument specifies
how the side effect is caused, and f3 requires two arguments, one
of them is an integer, the other one is a symbol.  Now, if I want to
insert one space (either with or without side effect), I can issue one
of the following commands:

   (f1 1)
   (f2 'indent)
   (f3 1 'indent)

And I'm granteed that, if one space is inserted, one of f1, f2, f3 is
called, but I don't which one is called.  So I want I can write (with
function in my last post),

   (xgp-casi2-safe-call f '((1) (indent) (1 indent)))
>
Where f is one of f1, f2, or f3 (got from environment).

No you can't, because your macros call

(f1)
(f1 1)
(f2)
(f2 indent)
(f3)
(f3 1)
(f3 indent)

If f can be
self-insert-command as well, the first trial will be successful  (so
perhaps I should make invoking without arguments the last trial).

Any better solutions?  Thanks.

(condition-case nil
    (f1 1)
  (error (condition-case nil
             (f2 'indent)
           (error (f3 1 'indent)))))

(defmacro try (&rest forms)
  "Eval FORMS until one of them returns without signalling an error."
  `(condition-case nil
       ,(car forms)
     (error (try ,@(cdr forms)))))

(try (f1 1) (f2 'indent) (f3 1 'indent))

--
Kevin Rodgers





reply via email to

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