Is it possible to have an alias for the function name in Lisp?

后端 未结 8 1408
梦毁少年i
梦毁少年i 2021-02-05 20:37

...just like packages do.

I use Emacs (maybe, it can offer some kind of solution).

For example (defun the-very-very-long-but-good-name () ...) is no

相关标签:
8条回答
  • 2021-02-05 21:22

    If it's all the typing which makes continual use of long names undesirable, then yes, emacs can help. Check out abbrev-mode. Also well thought-of in this context is hippie-expand.

    If it's a question of readability, that's harder.

    0 讨论(0)
  • 2021-02-05 21:30

    from 《On Lisp》?Here is the code:

    (defmacro alias (new-name prev-name)
      `(defmacro ,new-name (&rest args)
         `(,',prev-name ,@args)))
    
    ; use: (alias df defun)
    
    
    (defun group (source n)
      (if (zerop n) (error "zero length"))
      (labels ((rec (source acc)
                 (let ((rest (nthcdr n source)))
                   (if (consp rest)
                       (rec rest (cons (subseq source 0 n) acc))
                       (nreverse (cons source acc))))))
        (if source (rec source nil) nil)))
    
    (defmacro aliasx (&rest names)
      `(alias
         ,@(mapcar #'(lambda (pair)
                       `(alias ,@pair))
                   (group names 2))))
    
    ; use: (aliasx df1 defun 
    ;              df2 defun 
    ;              df3 defun)
    
    0 讨论(0)
提交回复
热议问题