[Openmcl-devel] Variadic initializers

R. Matthew Emerson rme at clozure.com
Tue Feb 26 08:25:26 PST 2008


On Feb 26, 2008, at 9:39 AM, Didier Verna wrote:

> I would like to perform the equivalent of the following in CCL:
>
> [NSMutableDictionary
> dictionaryWithObjectsAndKeys: obj1, @"obj1", obj2, @"obj2", ..., nil];
>
> As you can see, this is a variadic call. The openmcl manual has a
> paragraph about a rather heavy syntax for sending variadic messages,  
> but
> I was wondering if something more practical exists now. I would have
> thought something like:
>
> (make-instance 'ns:ns-mutable-dictionary
>  :with-objects-and-keys obj1 #@"obj1" ...) ;; no nil at the end ;-)

You can use the Objective-C style idiom for creating objects.

Here's an excerpt from ccl:cocoa-ide;apropos-window.lisp:

(#/dictionaryWithObjectsAndKeys: ns:ns-dictionary
				 (#/autorelease
				  (%make-nsstring
				   (prin1-to-string s)))
				 #@"symbol"
				 (#/numberWithInt: ns:ns-number n)
				 #@"index"
				 (#/autorelease
				  (%make-nsstring
				   (inspector::symbol-type-line s)))
				 #@"kind"
				 +null-ptr+)







More information about the Openmcl-devel mailing list