[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: [Warning] cl-count (And Other Options)
From: |
Drew Adams |
Subject: |
RE: [Warning] cl-count (And Other Options) |
Date: |
Fri, 30 Nov 2012 14:58:06 -0800 |
> > (let ((count-func (if (fboundp 'cl-count) #'cl-count #'count)())))
> > ...
> > (delete-char (* (cl-count ...)...
> >
> > php-mode.el:436:8:Warning: malformed let binding:
>
> The warning tries to tell you that ...
the let binding is malformed. ;-)
> 2) Replace that (cl-count ...) with (funcall count-func ...).
Yes. Calling `cl-count' just, well, calls `cl-count'. ;-)
The point was to call `cl-count' if it exists, or call `count' if not. `count'
is defined if `cl-count' is not defined. Older Emacs uses the name `count';
newer Emacs uses the name `cl-count'.
> But what Drew meant, I think, if for you the create a prefixed
> function alias, not local value binding. The former would just
> look better in code.
That's OK too.
But all I really meant was to call the function that exists, whether it is named
`cl-count' or `count'. One or the other is available, and they presumably do
the same thing.
Look first for a function with the newer name, `cl-count'. If that does not
exist then use `count', which must exist prior to the introduction of
`cl-count'.
If you have only one or a few occurrences of `cl-count' in your code, you could
just replace them with a funcall of the right function, as indicated above. If
you have a lot of them, or if you prefer (e.g. to ease maintenance), you can
create your own (non-local) function that calls the right one, and then use that
everywhere in your code.
(defun my-count (&rest args)
(if (fboundp 'cl-count)
(apply #'cl-count args)
(apply #'count args)))
Or just:
(defalias 'my-count (if (fboundp 'cl-count) #'cl-count #'count))
Then (delete-char (* (my-count ...)... etc.