[Openmcl-devel] More confusion about cocoa constants

R. Matthew Emerson rme at clozure.com
Fri Jul 10 10:15:55 PDT 2009


On Jul 10, 2009, at 12:47 PM, Neil Baylis wrote:

> In addition to the problem I previously mentioned re #
> $kCAGravityCenter at compile time, I'm running into other difficulties
> with constants. Is there something more I need to do other than
> loading the framework?
>
> This is a session from the IDE listener window:
>
> Welcome to Clozure Common Lisp Version 1.4-dev-r12363M-trunk
> (DarwinX8664)!
> CL-USER> (objc:load-framework "QuartzCore" :quartzcore)
> NIL
> CL-USER> #$kCAGravityCenter
>> Error: Constant not found: X86-DARWIN64::|kCAGravityCenter|
>> While executing: CCL::LOAD-OS-CONSTANT, in process Listener(6).
>> Type cmd-. to abort, cmd-\ for a list of available restarts.
>> Type :? for other options.
> CL-USER> #&kCAGravityCenter
> #<NS-MUTABLE-STRING "center" (#x7FFF704F3AC0)>
> CL-USER> #$kCAConstraintMidx
>> Error: Constant not found: X86-DARWIN64::|kCAConstraintMidx|
>> While executing: CCL::LOAD-OS-CONSTANT, in process Listener(6).
>> Type cmd-. to abort, cmd-\ for a list of available restarts.
>> Type :? for other options.
> CL-USER> #&kCAConstraintMidx
>> Error: Foreign variable "kCAConstraintMidx" not found
>> While executing: CCL::%LOAD-VAR, in process Listener(6).
>> Type cmd-. to abort, cmd-\ for a list of available restarts.
>> Type :? for other options.
> CL-USER>  #$NSBackingStoreBuffered
> 2
> CL-USER>
>
> It's very confusing trying to find the correct syntax for init forms.
> How do I know beforehand whether to use the #$ or #& prefix for a
> constant? It seems very unintuitive.

Unfortunately, you just have to look it up in the documentation or  
header files.  Sometimes the "constants" are real numeric constants,  
and sometimes they're NSString instances.

http://trac.clozure.com/openmcl/wiki/FrequentlyAskedQuestions#Objective-CBridge


> Why is kCAGravityCenter defined,
> but kCAConstraintMidx is not, when they are both from the same
> framework? (They are defined in different header files).

You used a lower-case "x" in kCAConstraintMidX.

Welcome to Clozure Common Lisp Version 1.4-dev-r12394M-trunk   
(DarwinX8664)!
? (objc:load-framework "Quartz" :quartz)
NIL
? #$kCAConstraintMidX
1

As for compiling your file, you want an eval-when in there instead of  
a bare top-level form:

(eval-when (:compile-toplevel :load-toplevel :execute)
   (objc:load-framework "QuartzCore" :quartzcore))





More information about the Openmcl-devel mailing list