dash.el
dash.el copied to clipboard
Add `-defun'
-defun
is like -lambda
, but with destructuring. To implement it, abstract
the arglist and form generation code of -lambda
into separate functions.
Additional benefits of the refactoring are:
-
-lambda
(and by extension,-defun
) can now accept empty argument lists -
-lambda
(and-defun
) no longer rebinds symbols (fixing the TODO)
Various declaration forms should be handled properly in -defun
.
Motivation: when this is merged, lsp-defun' can be made an alias for
-defun`.
-
Please note the use of
intern
instead ofmake-symbol
. Using the latter instead caused test-failures. -
What
git-commit-major-mode
do you prefer? I assumed and usedgit-commit-elisp-text-mode
here -
[x] add examples
I haven't noticed yyoncho's PR... This is going to be awkward.
I believe my PR to be better: it has no code duplication, and it doesn't rebind symbols, so things like (-lamba (foo)) are the same as (lambda (foo)). Is signing a copyright disclaimer enough, and if so, how would I go about doing that?
I'll add support for &optional.
Is signing a copyright disclaimer enough
Yes.
and if so, how would I go about doing that?
Just email the completed form at https://git.savannah.gnu.org/cgit/gnulib.git/tree/doc/Copyright/request-assign.future to [email protected]; they'll give you further instructions. It's generally a matter of scanning and emailing a scanned document, or in some countries digitally signing a document. See (info "(emacs) Copyright Assignment")
for more.
Thanks.
Now we also support &rest and &optional.
TODO: add &key, making -defun
a 100% drop-in replacement for cl-defun
.
Now we have -defmacro, and correct function signatures :).
Also, do you think I should implicitly add a signature doc to -lambda, if a docstring is provided? What we have currently:
(-lambda (a b)) = (lambda (a b))
(-lambda (a b) "Some docstring...") = (lambda (a b) "Some docstring...") ; no destructuring and signature comment necessary, as we only use symbols in the arglist
(-lambda ((a b)) "") = (-lambda ((a b)) "\n\n(fn ((a b)))") ; Note the auto-generated signature docstring fragment
(-lambda ((a b))) = (-lambda ((a b))) ; no signature docstring, as the user probably doesn't care if they didn't bother to provide a docstring
What I could do instead is to never touch -lambda
docstrings at all. What do you think?
Other than &key (which may or may not be needed), this PR is ready.
I couldn't write a proper edebug-form-spec for -defun, -lambda, -defmacro's lambda-lists, because I still don't understand them.
Now I added:
-
(-lambda [sym &as &DocumentSymbol :kind])
=(-lambda ((sym &as &DocumentSymbol :kind)))
-
(-lambda ((sym &as &DocumentSymbol :kind))
=(lambda (sym) (-let (((&DocumentSymbol :kind) sym)))
(&as is destructured directly, without going trough inputX)
My changes seem to not have broken anything: I am using my modified dash.el with lsp-mode, a heavy user of -lambda
, without any issues. I have recompiled the former a few times already.
Thanks, I'll have a closer look in the coming days. Let us know how the copyright assignment process goes.
I have sent the E-Mail for the copyright assignment.