-
-
Notifications
You must be signed in to change notification settings - Fork 19
Adds support for :decorators in anon fns, defasync #1189
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -338,8 +338,11 @@ | |
| After the name, an optional mapping of meta attributes may be provided. | ||
| Any metadata values given will be attached to the metadata of the | ||
| interned Var. A few special meta keys change how ``defn`` emits the | ||
| final Var and function: | ||
| interned Var, overriding any existing metadata associated with the | ||
| ``name``. | ||
| A few special meta keys change how ``defn`` emits the final Var and | ||
| function. The processing is handled by :lpy:fn:`fn`: | ||
| - ``:decorators`` is an optional vector of functions which will wrap | ||
| the final function emitted by ``defn``. Like standard Python | ||
|
|
@@ -411,15 +414,7 @@ | |
| {:found (first body)}))) | ||
| (rest body))) | ||
|
|
||
| decorators (:decorators fmeta) | ||
| fn-body (if decorators | ||
| (loop [wrappers (seq (python/reversed decorators)) | ||
| final `(fn ~fname ~@body)] | ||
| (if (seq wrappers) | ||
| (recur (rest wrappers) | ||
| `(~(first wrappers) ~final)) | ||
| final)) | ||
| `(fn ~fname ~@body))] | ||
| fn-body `(fn ~fname ~@body)] | ||
| `(def ~fname ~fn-body)))) | ||
|
|
||
| (defn nth | ||
|
|
@@ -6002,6 +5997,13 @@ | |
| (defmacro ^:no-warn-on-redef fn | ||
| "Return an anonymous (but possibly named) function. | ||
| A few special metadata keys change how ``fn`` emits the final function: | ||
| - ``:decorators`` is an optional vector of functions which will wrap | ||
| the final function emitted by ``fn``. Like standard Python | ||
| decorators and the ``comp`` function, decorators are applied to the | ||
| generated function from right to left. | ||
| Function argument vectors support sequential and associative :ref:`destructuring` . | ||
| See :lpy:form:`fn` for more details." | ||
|
|
@@ -6017,12 +6019,23 @@ | |
| (apply list (map fn-arity-with-destructuring body)) | ||
|
|
||
| :else | ||
| body)] | ||
| (as-> arities $ | ||
| (cond->> $ name (cons name)) | ||
| (cons 'fn* $) | ||
| (cond-> $ | ||
| (meta &form) (with-meta (meta &form)))))) | ||
| body) | ||
| fn-decl (as-> arities $ | ||
| (cond->> $ name (cons name)) | ||
| (cons 'fn* $) | ||
| (cond-> $ | ||
| (meta &form) (with-meta (meta &form)))) | ||
|
|
||
| fmeta (merge (meta fn-decl) (meta name)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this the correct order for how it is done in Clojure? I am indifferent towards the order, but I'd rather not have another ticket later just because it's wrong. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a very interesting point I did not consider. To clarify, I believe you are asking about the merging order: should the fn From a quick survey:
Thus based on the above, there’s no defined precedence in Clojure between fn For the
Since Conceptually to me, decorators are linked to the function, so I think support for the key in the If both are supported, my view is:
Supporting I prefer supporting both What is your view? Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I agree that we should support |
||
| decorators (:decorators fmeta)] | ||
| (if decorators | ||
| (loop [wrappers (seq (python/reversed decorators)) | ||
| final fn-decl] | ||
| (if (seq wrappers) | ||
| (recur (rest wrappers) | ||
| `(~(first wrappers) ~final)) | ||
| final)) | ||
| fn-decl))) | ||
|
|
||
| (defn destructure | ||
| "Take a ``[binding expr]`` pair (as from a ``let`` block) and produce all of the | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.