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

后端 未结 8 1414
梦毁少年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: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)
    

提交回复
热议问题