Search code examples
emacselisp

emacs/elisp: What is the hash (pound, number sign, octothorp) symbol used for?


What does this do?

(add-hook 'compilation-mode-hook #'my-setup-compile-mode)

...and is it different than

(add-hook 'compilation-mode-hook 'my-setup-compile-mode)

Solution

  • There is no difference:

    (eq 'my-add #'my-add)
    

    yields t

    The # can be used in front of a lambda expression indicating to the byte-compiler that the following expression can be byte compiled, see the docs for Anonymous Functions. But there's nothing to compile in the case of a symbol.

    In general, it is used in the printed representation along with the left angle bracket (<) to indicate that the object printed is a description (but cannot be read). For example:

    #<buffer foo.txt>
    

    It is also used in constructs by the reader to represent circular structures. See the docs for Read Syntax for Circular Objects.

    And then you have its use for denoting the base for integers, e.g. #x2c -> 44.

    Plus more I'm sure.