Contents (package MULK.OBJECTIVE-CL)


Function INTERN-SELECTOR

Purpose:

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

Syntax:

intern-selector selector-name

Arguments and Values:

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

Returns: selector --- a selector object.

Description:

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](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#lowercase)</em>.  
  
  2. Any additional parts are also fully converted to <em>[lowercase](http://www.lispworks.com/documentation/HyperSpec/Body/26_glo_l.htm#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.

    Examples:

    (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:'>  
     
    

    Note:

    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