[Openmcl-devel] dfsl/foreign function oddities

Gary Byers gb at clozure.com
Fri May 13 17:04:45 PDT 2005



On Fri, 13 May 2005, Chris Curtis wrote:

>
> The next one on my hit list is #$noErr. The easiest workaround, it seems, is 
> to do *something* that calls #$noErr before the prebuilt fasls get loaded, 
> but that seems ugly to me. The alternative is in the original source to do 
> something like (defconstant +noErr+ #$noErr), but that seems like a bit of a 
> hack too.
>
> Stylistically, what's the best solution here? Is it always a Bad Idea to use 
> the #$ and #_ forms in macros?

I think that in the relatively recent past, someone suggested that #$foo
look up and return the value of the foreign constant "foo", rather than
doing something like:

(progn
   (defconstant os::|foo| 1) ; or whatever
   'os::foo)

That would mean that a macro FOO-P could be defined as:

(defmacro foo-p (form)
   `(eql #$foo ,form))

and that would be entirely equivalent to:

(defmacro foo-p (form)
   `(eql 1 ,form))

The only reason that I can think of for not doing that is the (presumably)
small possibility that there's code somewhere that somehow depends on
#$foo returing a symbol.  There probably isn't much such code, if any,
and it's probably worth making this change.

The only example of this in the OpenMCL sources that I can think of is
the macro WITH-EAGAIN, which uses READ-FROM-STRING:

(defmacro with-eagain (fd direction &body body)
   (let* ((res (gensym))
 	 (eagain (symbol-value (read-from-string "#$EAGAIN"))))
    `(loop
       (let ((,res (progn , at body)))
 	(if (eql ,res (- ,eagain))
 	  (,(ecase direction
 	     (:input 'process-input-wait)
 	     (:output 'process-output-wait))
 	   ,fd)
 	  (return ,res))))))

Yes, that's ugly, and since (IIRC) I wrote it (at least the READ-FROM-STRING
part), I should probably be disqualified from making any judgements about
style.  Ever.

I can't think of a clean solution to the problem when #_ is involved.

>
> --chris
>
>
>



More information about the Openmcl-devel mailing list