[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
				   (prin1-to-string s)))
				 (#/numberWithInt: ns:ns-number n)
				   (inspector::symbol-type-line s)))

More information about the Openmcl-devel mailing list