[Openmcl-devel] Snow Leopard snafu
R. Matthew Emerson
rme at clozure.com
Tue Sep 1 10:20:17 PDT 2009
On Sep 1, 2009, at 12:20 PM, Ron Garret wrote:
> OK, I get that I'm being a moron and I'm missing something obvious.
> But my house nearly burned down three days ago so I'm not really
> firing on all cylinders at the moment and would appreciate it if you
> could cut me a little slack here. What is «the "with" component»?
As you know, an Objective-C instance is allocated and initialized with
code like:
id something = [[MyObject alloc] init];
Often, a class typically has a number of initializers. For example,
from NSString.h we see something like:
- (id)init;
- (id)initWithCharacters:(const unichar *)characters length:
(NSUInteger)length;
- (id)initWithUTF8String:(const char *)nullTerminatedCString;
- (id)initWithString:(NSString *)aString;
etc.
So we'd say
id something = [[NString alloc] initWithString:@"foo"];
To make this message sending look more lispy, we basically turn
messages into generic functions. Thus, the above would be:
(defvar *something* (#/initWithString: (#/alloc ns:ns-string) #@"foo"))
Fine. Now, we try to make Objective-C more CLOS-like. You can say:
(make-instance 'ns:ns-string :init-with-string #@"foo")
The #/alloc message is implicit (you still have to manually release
the object). As another convenience, the "init-" part of the keyword
argument can optionally be omitted:
(make-instance 'ns:ns-string :with-string #@"foo")
This may be a little too cute for its own good, but there it is.
(It's also potentially confusing, because Cocoa programmers are told
something like "you own an object if you got it via calling some
method that has "init" or "copy" in the name." This abbreviated
initarg convention conceals that.)
Anyway, after writing all this, I noticed the following change:
http://trac.clozure.com/openmcl/changeset/12652
This removes the unadorned ":string" initarg (among other changes), so
you were right after all: your code used to work, but this change
broke it.
>> On Tue, 1 Sep 2009, Ron Garret wrote:
>>
>>> I upgraded to Snow Leopard, and now this happens:
>>>
>>> ? (make-instance gui::ns-lisp-string :string (coerce "foo" 'simple-
>>> base-string))
>>>> Error: Unknown ObjC init message: "initString:"
More information about the Openmcl-devel
mailing list