Defining aliases to standard Common Lisp functions?

后端 未结 3 954
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-12 18:27

Lisp is said to enable redefinitions of its core functions. I want to define an alias to the function cl:documentation function, such that

(doc         


        
3条回答
  •  再見小時候
    2021-01-12 18:58

    Creating an Alias

    You are not trying to redefine (i.e., change the definition of) the system function documentation, you want to define your own function with a shorter name which would do the same thing as the system function.

    This can be done using fdefinition:

     (setf (fdefinition 'doc) #'documentation)
    

    How to make your change "permanent" in common lisp

    There is no standard way, different implementation may do it differently, but, generally speaking, there are two common ways.

    Add code to an init file - for beginners and casual users

    • SBCL
    • CLISP
    • Clozure
    • ECL

    The code in question will be evaluated anew every time lisp starts.

    Pro:

    • Easy to modify (just edit file)
    • Takes little disk space
    • Normal lisp invocation captures the change

    Con:

    • Evaluated every time you start lisp (so, slows start up time if the code is slow)

    Save image - for heavy-weight professionals

    • SBCL
    • CLISP
    • Clozure
    • ECL - not supported

    The modified lisp world is saved to disk.

    Pro:

    • Start uptime is unaffected

    Con:

    • Requires re-dumping the world on each change
    • Lisp image is usually a large file (>10MB)
    • Must specify the image at invocation time

提交回复
热议问题