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

Re: problem with MACL reader macros for traps used in macros.



> Date: Wed, 11 Sep 91 14:01:55 PDT
> From: cdj@tc.pw.com (Cris Johnson)
> To: info-macl@cambridge.apple.com
> Subject: problem with MACL reader macros for traps used in macros.
> 
> I'm having a problem with MACL trap reader macros in MACL2b2.
> They work great in executable code I compile.  But when I try to
> use (#_symbol . . .) forms in a macro, I get a macroexpander function
> that produces expressions of the form (traps::symbol . . .) and the
> appropriate traps::symbol gets bound to the appropriate definition AT
> THE TIME I evaluate the macro definition.  When I come back later in
> a different session of LISP and try to use the previously defined macro,
> I have problems because traps::symbol is no longer bound.
> 
> I've had no luck trying to get the (traps::symbol . . .) forms
> macroexpanded into their more primitive (register-trap . . .)
> equivalents at macro definition evaluation time.
> 
> I can explicitly call 'require-interface' on every traps file related
> to my macro, but this rather undoes the whole purpose of MACL's traps
> reader macro.  Has anyone had some better insight than I in using
> trap reader macros?
> 
> Cris Johnson 
> Price Waterhouse Technology Centre 
> 68 Willow Road, Menlo Park, CA 94025 
> (415) 322-0606
> 

There is a macro designed for just that problem.  If you precede the trap
name by REQUIRE-TRAP, all will work well:

(defmacro with-pen-saved (&body body)
  "executes body and restores state of window pen"
  (let ((old-pen-state (gensym)))
    `(rlet ((,old-pen-state :penstate))
       (unwind-protect
         (progn
           (require-trap #_GetPenState ,old-pen-state)
           ,@body)
         (require-trap #_SetPenState ,old-pen-state)))))

For #$ constants, use REQUIRE-TRAP-CONSTANT or #.

(defmacro window-manager-port ()
  (%get-ptr (%int-to-ptr #.#$WmgrPort)))

or

(defmacro window-manager-port ()
  (%get-ptr (%int-to-ptr (require-trap-constant #$WmgrPort))))