[Openmcl-devel] dfsl/foreign function oddities

Gary Byers gb at clozure.com
Sat May 14 22:28:27 UTC 2005



On Sat, 14 May 2005, Chris Curtis wrote:

> On May 13, 2005, at 8:04 PM, Gary Byers wrote:
>
>> I can't think of a clean solution to the problem when #_ is involved.
>
> With a little more thought and some testing.... is it clean enough to just 
> wrap a defmacro that uses the reader macros in (eval-when :compile-toplevel 
> :load-toplevel ...)?
>
> --chris
>

I don't think so; regardless of what EVAL-WHEN situtations are involved,
the reader will only read the form (and call the #_ reader macro) once.


You could do something like:

;;; file containing macro definitions
(eval-when (:compile-toplevel :load-toplevel :execute)
   ;; Ensure that #_/#$ reader macros are in effect, so
   ;; that the OS-package symbols involved have correct
   ;; definitions and so #_/#$ can be used in macroexpansions.
   (read-from-string "#_foo")
   (read-from-string "#$bar"))

(defmacro ...)

(defmacro ...)
;;;; eof

About the only way that I can think of to make it a little less
ugly is to expose some of the stuff that the reader macros use,
e.g.:


(eval-when (:compile-toplevel :load-toplevel :execute)
   ;; Ensure that #_/#$ reader macros are in effect, so
   ;; that the OS-package symbols involved have correct
   ;; definitions and so #_/#$ can be used in macroexpansions.
   (ensure-foreign-function-definition-from-interface-db "foo")
   (ensure-foreign-constant-definition-from-interface-db "bar"))

assuming that those ENSURE-FOREIGN-...-DEFINITION-... functions
existed.  (They obviously sort of do - under different names -
but they're probably a little too tied to the reader macros
implementations )

The user would -still- need to be aware of this issue - "in order to
reliably use #_/#$/#? in macroexpansions, one has to ensure that the
foreign constant/function/variable definitions are in effect at
macroexpand time."  The proposed ENSURE-FOREIGN-* functions are
arguably a less obscure way of doing that than calling READ-FROM-STRING.

Yet another approach:

(defmacro ensure-foreign-constant-definition-from-interface-db (string)
   `(eval-when (:compile-toplevel :load-toplevel :execute)
      (read-from-string ,(concatenate 'string "#$" string))))






More information about the Openmcl-devel mailing list