What is fdoc?

fdoc, short for "Function Documentation", is a tool and convention used primarily within the Lisp programming language family (especially Common Lisp and Emacs Lisp) for accessing and displaying documentation associated with functions, variables, and other program elements. It serves as an interactive way to get help and understand how to use different parts of a Lisp system.

Here's a breakdown of important aspects of fdoc:

  • Purpose: Its main function is to retrieve and present human-readable documentation strings directly from within the Lisp environment. This helps programmers avoid constantly consulting external manuals.

  • Access Method: Typically, you invoke fdoc by calling a function like describe or by using a command within an editor (like Emacs). You then pass the symbol you want to examine (e.g., a function name, variable name) as an argument.

  • Documentation Strings: The "documentation" is usually a string that the programmer has embedded within the definition of the function or variable using a special syntax (e.g., using a docstring in Common Lisp or using a doc property in Emacs Lisp). This makes the documentation tightly bound to the code itself.

  • Content: A good documentation string provides several crucial pieces of information:

  • Interactive Help: fdoc integrates seamlessly with the Lisp environment, providing on-demand help as you are programming. This is particularly useful for exploring unfamiliar libraries or understanding complex functions.

  • Example (Common Lisp):

    (defun my-function (arg1 arg2)
      "This is my function.  It takes two arguments, ARG1 and ARG2,
       and returns their sum.  ARG1 and ARG2 should be numbers.
    
       Example: (my-function 2 3) => 5"
      (+ arg1 arg2))
    
    ;; Using describe in a Common Lisp environment:
    ;; (describe 'my-function)  ; This will display the docstring.
    
  • Example (Emacs Lisp):

    (defun my-emacs-function (arg1 arg2)
      "This is my Emacs function. It takes two arguments, ARG1 and ARG2, and returns their sum."
      (+ arg1 arg2))
    
    ;; Using describe in Emacs:
    ;; M-x describe-function RET my-emacs-function RET ; Displays the docstring
    

In summary, fdoc is an essential tool for Lisp programmers, promoting code understanding and maintainability through readily available, embedded documentation.