Re: Warning STklos feature: function redefination

From: Ken Anderson <kanderso_at_bbn.com>
Date: Fri, 21 Jul 1995 08:43:34 +0100

  To: stk_at_kaolin.unice.fr
  cc: jzinky_at_atom-ant.bbn.com, kanderson_at_atom-ant.bbn.com
  Subject: Warning STklos feature: function redefination
  Date: Fri, 21 Jul 1995 08:14:37 -0400
  From: "John A. Zinky" <jzinky_at_BBN.COM>
  
  The problem is when klos generic redefines a previously defined fuction.
  
  The first time was when I declared a generic function "update"
  
  The second time was when I declared a slot/accessor "text"
  
  In both cases the new generic function wipes out the old function.
  Now any code that depends on the old functions is broke, which is
  especially true of TK libraries which make extensive use of regular
  functions.
          
Here's an extension to stklos.stk that warns about the potential of this:

(define (redefinition-warning symbol old-value text)
  (format
   #t
   "~%;;; Warning: Redefining ~A with old-value ~A to ~A.~%"
   symbol old-value text))

(define-macro (define-generic name)
  `(begin
     ;; KRA 20JUL95: Warn about redefinition.
     (when (and (symbol-bound? ',name)
                (not (is-a? ,name <generic>)))
       (redefinition-warning ',name ,name "be <generic>"))
     (define ,name (make <generic> :name ',name))))


  The only saving grace is that the graphical debugger breaks and if I
  was paying attention I could have seen the culprit in the stack dump.
  
  Is there a package mechanism for STk?

No, but what is typically done is to prefix the variables you define with a
package like prefix (though any prefix will do):

(define (fern:update ...) ...)

safe, but ugly.
Received on Fri Jul 21 1995 - 14:45:31 CEST

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST