diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-08 21:13:47 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-08 21:13:47 +0300 |
| commit | 910bfcf768c2305a6885b0d1f491561d09ebd9ca (patch) | |
| tree | cd88174ffdb222df8b61ecf68796452580d9dee4 /macros/fn.fnl | |
| parent | cf18cb390b2ba9ac852b52b22beb9fda0d4ab7d2 (diff) | |
feature(macros): add metadata macros, doc, and some tests
Diffstat (limited to 'macros/fn.fnl')
| -rw-r--r-- | macros/fn.fnl | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/macros/fn.fnl b/macros/fn.fnl index 2d4a753..24f909d 100644 --- a/macros/fn.fnl +++ b/macros/fn.fnl @@ -1,14 +1,16 @@ (local unpack (or table.unpack _G.unpack)) (local insert table.insert) (local sort table.sort) +(local meta-enabled (pcall _SCOPE.specials.doc (list (sym :doc) (sym :doc)) _SCOPE _CHUNK)) (fn with-meta [val meta] - `(let [val# ,val - (res# fennel#) (pcall require :fennel)] - (if res# - (each [k# v# (pairs ,meta)] - (fennel#.metadata:set val# k# v#))) - val#)) + (if (not meta-enabled) val + `(let [val# ,val + (res# fennel#) (pcall require :fennel)] + (if res# + (each [k# v# (pairs ,meta)] + (fennel#.metadata:set val# k# v#))) + val#))) (fn gen-arglist-doc [args] (if (list? (. args 1)) @@ -252,8 +254,8 @@ namespaced functions. See `fn*' for more info." (let [docstring (if (string? doc?) doc? nil) (name-wo-namespace namespaced?) (multisym->sym name) arg-list (if (sym? name-wo-namespace) - (if (string? doc?) args doc?) - name-wo-namespace) + (if (string? doc?) args doc?) + name-wo-namespace) arglist-doc (gen-arglist-doc arg-list) body (if (sym? name) (if (string? doc?) |