Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `-defun' #347

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f3f29e3
Add `-defun'
nbfalcon Nov 6, 2020
6add372
`-defun': add declare with doc-string and indent
nbfalcon Nov 6, 2020
3a63e45
Add examples for `-defun'
nbfalcon Nov 6, 2020
727df5c
`-defun', `-lambda': support &optional and &rest
nbfalcon Nov 6, 2020
379e48c
Fix `-defun' &rest example
nbfalcon Nov 6, 2020
24850aa
`-lambda': support declare-forms; add `-defmacro'
nbfalcon Nov 6, 2020
2e989aa
Improve docstrings
nbfalcon Nov 6, 2020
03186e0
Fix edebug specs
nbfalcon Nov 6, 2020
6a87bae
Optimize &as bindings
nbfalcon Nov 6, 2020
95462fc
`-defun', ...: allow vectors as MATCH-FORMs
nbfalcon Nov 6, 2020
c4ffe96
`-defun', ...: optimize &as bindings in vectors
nbfalcon Nov 6, 2020
6f2626f
`-lambda', ...: improve debug specs
nbfalcon Nov 8, 2020
bcfd26a
Fix byte-compile error(s)
nbfalcon Nov 13, 2020
fd53121
`-defmacro': add example
nbfalcon Nov 13, 2020
92e623f
`dash--destructure-body': optimize: use `-let*'
nbfalcon Nov 26, 2020
23749b3
`dash--destructure-arglist': docstring generation
nbfalcon Nov 26, 2020
6afe446
Fix edebug specs: debugging `-defun'
nbfalcon Nov 26, 2020
376acdb
`-defun', ...: improve error handling
nbfalcon Nov 26, 2020
34d618b
`dash--arg-list-keywords': improve docstring
nbfalcon Nov 26, 2020
79a71d6
`-lambda': don't interpret `declare'
nbfalcon Dec 30, 2020
30a0de5
`dash-lamba-list': remove TODO
nbfalcon Dec 30, 2020
e0fb5d5
`-defun', ...: use `make-symbol'
nbfalcon Jan 6, 2021
2f9fc8c
`dash--as-matcher?': destructure directly
nbfalcon Jan 6, 2021
148a833
`dash--as-matcher?': [x &as] is not an as-matcher
nbfalcon Jan 6, 2021
83a3c12
`dash--match': refactor: use `dash--as-matcher?'
nbfalcon Jan 6, 2021
bcc9763
`dash--destructure-body': DOC -> ARGLIST
nbfalcon Jan 7, 2021
caf7445
`dash--decompose-defun-body': drop DECLARE?
nbfalcon Jan 7, 2021
7895a2b
`-defun', .... reduce code duplication
nbfalcon Jan 7, 2021
9ac1487
Drop `dash--docstring-add-signature'
nbfalcon Jan 7, 2021
d8cab22
`dash--decompose-defun-body': behave like `defun'
nbfalcon Mar 22, 2021
8ac91de
Fix square-bracket arguments
nbfalcon Mar 22, 2021
66f513e
Improve examples
nbfalcon Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 18 additions & 7 deletions dash.el
Expand Up @@ -2209,6 +2209,11 @@ docstring if none is provided."
`((-let ,let-bindings ,@body))
body))))

(defun dash--normalize-arglist (arglist)
"Make ARGLIST have the form (MATCHERS...).
If it is a vector, convert it to a single-matcher arglist."
(if (vectorp arglist) (list (append arglist nil)) arglist))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I use cl-coerce here? append nil seems fragile.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(append x ()) is the canonical way to convert an array x into a list, so I wouldn't worry about it. Also, dash.el tries to avoid relying on cl-lib.


;; TODO: a proper `dash-lambda-list'
(def-edebug-spec dash-lambda-list sexp)

Expand All @@ -2227,8 +2232,9 @@ additional destructuring, this function behaves exactly like
[&optional ("declare" &rest sexp)]
[&optional ("interactive" interactive)]
def-body)))
`(defun ,name ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body)))
(let ((match-form (dash--normalize-arglist match-form)))
`(defun ,name ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body))))

(defmacro -defmacro (name match-form &rest body)
"Like `-defun', but define macro called NAME instead.
Expand All @@ -2240,8 +2246,9 @@ MATCH-FORM and BODY are the same.
[&optional stringp]
[&optional ("interactive" interactive)]
def-body)))
`(defmacro ,name ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body)))
(let ((match-form (dash--normalize-arglist match-form)))
`(defmacro ,name ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body))))

(defmacro -lambda (match-form &rest body)
"Return a lambda which destructures its input as MATCH-FORM and executes BODY.
Expand All @@ -2254,7 +2261,10 @@ such that:

has the usual semantics of `lambda'. Furthermore, these get
translated into a normal `lambda', so there is no performance
penalty.
penalty. MATCH-FORM may also be a vector, in which case the
entire vector destructures a single argument:

(-lambda [a b]) = (-lambda ((a b)))

See `-let' for the description of destructuring mechanism.

Expand All @@ -2263,8 +2273,9 @@ See `-let' for the description of destructuring mechanism.
(debug (&define dash-lambda-list lambda-doc
[&optional ("interactive" interactive)]
def-body)))
`(lambda ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body t)))
(let ((match-form (dash--normalize-arglist match-form)))
`(lambda ,(dash--make-arglist match-form)
,@(dash--destructure-body match-form body t))))

(defmacro -setq (&rest forms)
"Bind each MATCH-FORM to the value of its VAL.
Expand Down