[Openmcl-devel] Defining objc classes causes the class name to be declared static

Ron Garret ron at flownet.com
Mon Oct 14 08:25:12 PDT 2013


I understand the design rationale.  Ironically, the reason I discovered this, and the reason it was a problem, is that I had my own code attempting to produce the exact same behavior, except that I was defining a symbol macro rather than using defglobal.  (You might want to consider that if you want to fix this in a backwards-compatible way.  If it's a symbol macro it's a little less obtrusive because you can still bind the symbol lexically.)

I have since decided that binding the naked class name is a Bad Idea [1], and my own code now defines a symbol macro that uses the old Dylan lexical convention of wrapping class names in <angle-brakcets>, so for me it's a moot point.

But if I may make a suggestion: in cases where a less-than-optimal design is being maintained for reasons of backward compatibility, one can make everyone happy by defining a parameter like *automatically-bind-objc-classes*.  That also makes it possible to gracefully deprecate that (mis)feature some day.

rg

----

[1] The reason it's a Bad Idea is that it masks the following error:

(def-objc-class foo ...)

(let ((foo ...)) (some-code-that-uses foo) (some-other-code-that-uses foo))

Now you decide you want to change "foo" to "baz" in the second line, but you miss an occurrence and end up with:

(let ((baz ...)) (some-code-that-uses baz) (some-other-code-that-uses foo))

Now instead of an undeclared free variable warning you get a very weird runtime error.

rg

On Oct 13, 2013, at 11:12 PM, Gary Byers wrote:

> It's intentional and it's been this way for many years.
> 
> It's similar enough to what ObjC does that you can translate
> 
> [someMessage classname]
> 
> into
> 
> (#/someMessage classname) ; instead of (#/someMessage (find-class 'classname))
> 
> If "classname" would also be a good variable/argument name (e.g., "view"),
> then declaring the symbol to be static effectively makes use of the same
> name as an argument or local variable awkward.
> 
> Whatever convenience the first point offers is obviously offset by the second.
> If I was sure that no code anywhere was taking advantage of that behavior I
> wouldn't be at all hesitant about changing it. but I'm not sure of that and
> I am hesitant.
> 
> On Sun, 13 Oct 2013, Ron Garret wrote:
> 
>> Is this a feature or a bug? My vote goes to bug, but it's a damned peculiar bug:
>> 
>> Welcome to Clozure Common Lisp Version 1.10-dev-r15900M-trunk  (DarwinX8664)!
>> ? (defclass foo2 (ns:ns-object) () (:metaclass ns:+ns-object))
>> #<OBJC:OBJC-CLASS FOO2 (#x20D42FA0)>
>> ? foo2
>> #<OBJC:OBJC-CLASS FOO2 (#x20D42FA0)>
>> 
>> rg
>> 
>> _______________________________________________
>> Openmcl-devel mailing list
>> Openmcl-devel at clozure.com
>> http://clozure.com/mailman/listinfo/openmcl-devel
>> 
>> 




More information about the Openmcl-devel mailing list