Why is the hyphen conventional in symbol names in LISP?

后端 未结 3 1793
深忆病人
深忆病人 2021-02-14 22:54

What\'s the reason of this recommendation? Why not keeping consistent with other programming languages which use underscore instead?

3条回答
  •  后悔当初
    2021-02-14 23:04

    In written natural languages the - sign is often used as a way to make compound words. In German for example we compose german nouns just by appending them:

    Hofbräuhaus
    

    Above consist of three parts: Hof bräu haus.

    But when we write concepts in German which have foreign names as their part we write them like this:

    Mubarak-Regime
    

    In natural languages it is not common to compose words by CamelCase or Under_Score.

    The design of most Lisps was more oriented towards the linguistic tradition. The convention in some languages to use the underscore came up, because in these languages the - sign was already taken for the minus operation and the identifiers of theses were not allowed to include the - sign. The - sign is a identifier terminating character in these languages. Not in Lisp.

    Note though that one can use the underscore in Lisp identifiers, though this is rarely use in code for aesthetic reasons.

    One can also use every character in an identifier. The vertical bar encloses an arbitrary symbol:

    |this *@^! symbol is valid - why is that po_ss_ib_le?|
    
    > (defun |this *@^! symbol is valid - why is that po_ss_ib_le?| (|what? really?|)
                  (+ |what? really?| 42))
    |this *@^! symbol is valid - why is that po_ss_ib_le?|
    
    > (|this *@^! symbol is valid - why is that po_ss_ib_le?| 42)
    84
    

    Note that the backslash is an escape character in symbol names.

提交回复
热议问题