diff options
| author | Andrey Orst <andreyorst@gmail.com> | 2020-11-02 22:33:25 +0300 |
|---|---|---|
| committer | Andrey Orst <andreyorst@gmail.com> | 2020-11-02 22:33:25 +0300 |
| commit | 34ae8addc83267960d0b2daede2bcc91ea24d809 (patch) | |
| tree | 68251c66d3a0a71252b090cfe13d2fbf4c2bc67a /macros/core.fnl | |
| parent | d7ebb3e607da6444d8215b1ee273c4247489f862 (diff) | |
feature(macros): support attribute table in def and defonce
Diffstat (limited to 'macros/core.fnl')
| -rw-r--r-- | macros/core.fnl | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/macros/core.fnl b/macros/core.fnl index f300dbd..31ac1ae 100644 --- a/macros/core.fnl +++ b/macros/core.fnl @@ -184,16 +184,28 @@ multifn#)) (fn* core.def - [name expr] - (let [(s m) (multisym->sym name)] - (if m - `(local ,s (do (local ,s ,expr) (set ,name ,s) ,s)) - `(local ,name ,expr)))) + ([name expr] (def {} name expr)) + ([attr-map name expr] + (if (not (or (table? attr-map) + (string? attr-map))) + (error "def: expected keyword or literal table as first argument" 2)) + (let [(s multi) (multisym->sym name) + f (if (if (table? attr-map) + (. attr-map :dynamic) + (if (= attr-map :dynamic) + true + (error (.. "unsupported attribute keyword: :" attr-map) 2))) + 'var 'local)] + (if multi + `(,f ,s (do (,f ,s ,expr) (set ,name ,s) ,s)) + `(,f ,name ,expr))))) (fn* core.defonce - [name expr] - (if (in-scope? name) - nil - (def name expr))) + ([name expr] + (defonce {} name expr)) + ([attr-map name expr] + (if (in-scope? (if (table? attr-map) name attr-map)) + nil + (def attr-map name expr)))) core |