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

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

Re: Problem advising nreverse.


From: Sergei Organov
Subject: Re: Problem advising nreverse.
Date: Mon, 14 Dec 2009 22:59:02 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

address@hidden (Pascal J. Bourguignon) writes:

> Sergei Organov <address@hidden> writes:
>
>> You see, I wanted automatic elisp-only solution to "fixing"
>> ewoc-collect, but only if it indeed happens to be buggy. Manual
>> reloading is not an option then. Alternate approach would be to execute
>> simple test-case to determine if ewoc-collect is indeed buggy and then
>> re-define it to the correct version if so. That's what I'm going to
>> implement now, provided there doesn't seem to be a way to do what I want
>> by means of advising ewoc-collect and nreverse.
>
> I see.  
>

[...]

> or else, if you can detect the broken version with a test:
>
>     (require 'ewoc)
>     (unless (equal 'expected-result
>                    (ewoc-collect 'test-arguments))
>        (defun ewoc-collect (...)
>          ...))
>
> (you can add a (byte-compile 'ewoc-collect) after the defun in either
> case if you need it fast).

Exactly. After realizing with your help that I'll have no luck with
defadvicing nreverse, I finally ended up with the following simple
solution:

;; Fix buggy `ewoc-collect' by reversing its result. Nothing will be
;; changed if `ewoc-collect' is fine.
(require 'ewoc)
(with-temp-buffer
  (let ((ewoc (ewoc-create (lambda (elem) ()))))
    (ewoc-enter-last ewoc 0) (ewoc-enter-last ewoc 1)
    (if (equal 1 (car (ewoc-collect ewoc (lambda (elem) t))))
      (defadvice ewoc-collect (after ewoc-collect-reverse activate compile)
        "Reverse the result to compensate for buggy implementation."
        (setq ad-return-value (nreverse ad-return-value))))))

I still wonder if it's documented somewhere in some manual when
defadvice doesn't actually work. It seems it is not there in the Elisp
manual, or did I miss it?

-- 
Sergei.





reply via email to

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