[Openmcl-devel] A few quick ObjectiveC Bridge questions
gb at clozure.com
Wed May 17 01:11:04 UTC 2006
On Fri, 12 May 2006, Gary King wrote:
> Thanks for the bridge. It is really quite wonderful.
> 1. Is %null-ptr-p the "right" way to test for an object being null?
> For example, is this enumerator code canonical?
>> (let ((enumerator (ccl::send people 'object-enumerator)))
>> (loop for person = (ccl::send enumerator 'next-object)
>> until (%null-ptr-p person) collect
> 2. Why aren't things like #'send, #'lisp-string-from-nsstring, and so
> on exported? It seems to me that they should be.
> 3. Is #'%make-nsstring the "right" way to make nsstrings?
There are several different kinds of NSStrings (and related things):
1) an NSConstantString is statically allocated and read-only.
2) the result of allocating and initializing an NSString (perhaps using
an 8-bit, NUL-terminated C string) is likely to be an instance of
some concrete subclass of NSString. (In Cocoa, it's likely to
be an NSCFString, which can be treated as a Core Foundation
CFString object.) These objects are immutable but can be freed.
3) an instance of some subclass of NSMutableString
4) an instance of some subclass of NSAttributedString
5) NSSimpleCString, NSMutableAttribtedString, ...
The #@ reader macro does (1).
%MAKE-NSSTRING does (2).
There aren't any functions in the examples directory that automate
or simplify the creation of other types of string objects, though
none of this is exactly rocket science.
Both of these things use a C string to initialize the result. In
the case of (IIRC) everything but (1), there are lots of other
ways of initializing the string's data (actually, a few other ways
but support for several string encoding schemes.)
I sort of look at this answer to your 3rd question as a partial
answer to your 2nd question and to ask a few related rhetorical ones:
is %MAKE-NSSTRING particularly well-named ? (I don't think so) is it
a particularly good interface to NSString creation ? (it's not
necessarily bad, but ...) Is it just a random, somewhat useful
function ? (yes, both random and somewhat useful).
Should %MAKE-NSSTRING be exported, simply because it does something
somewhat useful and because there's nothing else written that does
(at least) the same thing ?
I tend to think that exporting things carves them in stone. That's
not entirely true, but there's certainly some truth there. The status
quo (not exporting much of anything ObjC-related) isn't entirely
desirable either, since it likely discourages use to some degree and
in some cases. If I could think of a shorter package name, I think
that I might advocate something like "exporting a dozen or so symbols
from an OBJC-BRIDGE-1 package", with the understanding that that
package might go away in a future release.
> Gary Warren King
> (413) 210 7511
> gwking on #lisp (occasionally)
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
More information about the Openmcl-devel