From: Wayne Mesard
Subject: MACL Recover from symbol name conflicts
Date: 
Message-ID: <52375@bbn.COM>
This is too gross to keep to myself.  One of the problems with trying to
be anal about packages is that you always have package problems.  During
development, I all-too-often compile buffers in the wrong order, and
then when my code tries to execute a USE-PACKAGE, I wind up lying on my
face in the debugger.

After loading the following code, recovering from a name conflict is as
simple as typing executing USE! immediately after the error occurs.  All
the offending symbols in the receiving package will be shadowed or
uninterned.  This won't work for anything but Macintosh Allegro Common
Lisp.  (The DEFVAR at the top is about the only line of portable code.)

It's left as an exercise for the reader to decipher how I get the list
of conflicting symbols; I'm too embarrassed to talk about it.  But if
anyone starts an Obfuscated Lisp contest, I'm submitting this. ;-)

I don't pretend that this is the best implementation of the concept, but
I had fun doing it.  I'm eager to hear any comments or problems.

void Wayne_Mesard();   ······@BBN.COM   Bolt Beranek and Newman, Cambridge, MA

---snip------snip------snip------snip---
;;; USE! - Fix package problems from the MACL debugger.  
;;; Copyright 1990 Wayne Mesard.  ······@BBN.COM
;;; This file may be freely redistributed provided that this message 
;;; remains intact.
;;; 
;;; This little code has been developed for Macintosh Allegro Common 
;;; Lisp 1.3 only.  It is a kludge of the worst type.  It may not work an
;;; hour from now, never mind the next MACL release.
;;; 
;;; What do you do when USE-PACKAGE throws you into the debugger with
;;; a name conflict error?  I used to curse and scream, then UNINTERN all 
;;; the conflicting symbols in some awkward way.  Now I just type "(USE!)".  
;;; This little function finds out which symbol(s) are causing the conflict
;;; and shadow-imports them into the receiving package.  It then
;;; reexecutes the USE-PACKAGE and exits the debugger.
;;; 
;;; It was inspired by the Symbolics <Resume> handler for this error,
;;; although USE! makes no effort to warn the user when a symbol is going
;;; to be UNINTERNed (as opposed to merely shadowed).  Also, processing
;;; does not continue since--unfortunately--USE-PACKAGE calls ERROR
;;; not CERROR (Hi Apple ;-).

(require :records)

(defvar %use!)

(defun use!-1 ()
   (rset *current-event* :event.what %use!)
   (rset *current-event* :event.when (get-internal-real-time))
   (rset *current-event* :event.where 
           (add-points ·@(5 5) (ask (front-window) (window-position))))
   (rset *current-event* :event.modifiers 0)
   (if (= 3 (incf %use!))
     (setq *eventhook* nil))
   )

(defun use! (&optional quietly)
   (ccl::select-backtrace)
   (setq %use! 1
            *eventhook* #'use!-1)
   (let (conflicts import-list)
     (loop 
       (sleep .5)
       (if (setq conflicts (local 1))
         (return)))
     (setq import-list (mapcar #'cdr (third conflicts)))
     (shadowing-import import-list (second conflicts))
     (if (not quietly) (format t "Shadow-imported: ~S.~%" import-list))
     (use-package (first conflicts) (second conflicts))
     (abort-break)
     (values)))