Contents (package MULK.OBJECTIVE-CL)



Retrieve a method selector by name, or create it if it does not exist.


intern-selector selector-name

Arguments and Values:

selector-name --- a string, a symbol, or a list of symbols.

Returns: selector --- a selector object.


If selector-name is a string, the selector named by that string is returned. If no selector with the given name exists, such a selector is created and registered with the Objective-C runtime, after which it is returned.

If selector-name is a symbol, it is treated the same as a list whose only element is the symbol.

If selector-name is a list of symbols, all symbols are first split into parts separated by hyphens and each part converted into a string according to the following rules:

  1. 1. If the keywords' symbol names do contain lowercase characters, their case is left intact.

2. If the keywords' symbol names do not contain any lowercase characters, the following steps are taken in order to adjust their case.

  1. The first part is fully converted to <em>[lowercase](</em>.  
  2. Any additional parts are also fully converted to <em>[lowercase](</em>  
     except for their first letters, which are left intact. 
  • If the symbol is a keyword, the resulting string is suffixed by a colon (`:').
  • After that, all parts are concatenated in order to form a single selector name component. The selector name components are in turn concatenated in order to form the string that identifies the selector, which is used as if given directly as an argument to a call to intern-selector.

    Note that the conversion rules for selector names are identical to those by which invoke converts its arguments into a message name.


    (intern-selector "self")       ;=> #<SELECTOR `self'>  
    (intern-selector '(self))      ;=> #<SELECTOR `self'>  
    (intern-selector 'self)        ;=> #<SELECTOR `self'>  
    (intern-selector "stringWithCString:encoding:")  
      ;=> #<SELECTOR `stringWithCString:encoding:'>  
    (intern-selector '(:string-with-c-string :encoding))  
      ;=> #<SELECTOR `stringWithCString:encoding:'>  
    #.(setq *readtable* (copy-readtable))  
    #.(setf (readtable-case *readtable*) :invert)  
    (intern-selector '(:stringWithCString :encoding))  
      ;=> #<SELECTOR `stringWithCString:encoding:'>  


    Setting the readtable case of the current readtable to :INVERT is a good way of making the Lisp system behave as traditionally as possible while making Objective-C method names case-sensitive.

    On the other hand, writing all method names in lower case while separating parts by hyphens works nicely in all of the :INVERT, :UPCASE, :DOWNCASE, and :PRESERVE modes as well as Allegro CL's modern mode.

    See also:

    find-selector, selector