Reputation: 4925
...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 not to useful later in code. But the name like Fn-15
or the first letters abbreviation is not useful too.
Is it possible either to have an alias like for packages or to access the documentation string while trying to recall the function's name?
In other words, is it possible for functions to mix somehow self-documenting and short names?
Upvotes: 19
Views: 6133
Reputation: 91
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)
Upvotes: 5
Reputation: 7042
You could use setf
to assign the function to the function cell of another, for example:
(defmacro alias (new-name prev-name)
`(setf (symbol-function ,new-name) (symbol-function ,prev-name)))
Upvotes: 5
Reputation: 5120
You want defalias
. (defalias 'newname 'oldname)
will preserve documentation and even show "newname is an alias for `oldname'" when its documentation is requested.
Upvotes: 48
Reputation: 70967
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.
Upvotes: 4
Reputation: 117350
I dont know Emacs, but wouldn't (define shortname longnamefunctionblahblah) work?
Upvotes: 0
Reputation: 49886
You could simply have a function that just calls another function.
Upvotes: -1
Reputation: 15235
If your problem is that you can't remember a very long function name, but you remember PART of the name, that's what "apropos" is for. In my Emacs, I have "C-h a" bound to "hyper-apropos". You enter a substring of the symbol you're looking for, and it lists all the matches.
Upvotes: 0