Subject: Re: bug#16353: 24.3.50; cl-position fails in 23.4.1

From: Helmut Eller <[email-masked]>
Date: Tue, 07 Jan 2014 11:03:30 +0100

On Tue, Jan 07 2014, João Távora wrote:

> Can it be done without including the full definitions, e.g. via some
> bytecode-changing trick? I'm asking because I could include this
> workaround

Here's an idea for a solution: unintern the existing symbol, say
cl-postion, then intern "cl-position" again to create a second symbol.
defalias the second symbol.  Code loaded before the unintern dance, will
call the function of the uninterned symbols and code loaded afterwards
calls the function of the second symbol.  To make this work it's
important to load all code that must call uninterned symbols into
memory.  In practice that seems to be cl-seq.elc.

--- cl-lib-0.3.el.orig	2014-01-07 10:47:47.508299389 +0100
+++ cl-lib-0.3.el	2014-01-07 10:48:57.436296376 +0100
@@ -299,9 +299,20 @@
                dolist
                dotimes
                ))
-  (let ((new (if (consp fun) (prog1 (cdr fun) (setq fun (car fun)))
-               (intern (format "cl-%s" fun)))))
-    (unless (fboundp new) (defalias new fun))))
+  (let* ((old (cond ((consp fun) (car fun))
+		    (t fun)))
+	 (new (cond ((consp fun) (cdr fun))
+		    (t (intern (format "cl-%s" fun)))))
+	 (f (symbol-function old))
+	 (autoload (and (consp f) (eq (car f) 'autoload))))
+    (when autoload
+      (load (cadr f)))
+    (let ((new2 (cond ((fboundp new)
+		       (message "Conflict: %s" new)
+		       (unintern new)
+		       (intern (symbol-name new)))
+		      (t new))))
+      (defalias new2 old))))
 
 ;; `cl-labels' is not 100% compatible with `labels' when using dynamic scoping
 ;; (mostly because it does not turn lambdas that refer to those functions into