;; @module defkey.lsp ;; @description An attempt to add keyword arguments to functions ;; @example ;; (defkey (f a (b 20) c) (list a b c)) ;; (f 10 :c 30) => (10 20 30) (define-macro (defkey header) (let (_makedef (fn (_x) (if (symbol? _x) (list _x nil) (list (_x 0) (eval (_x 1)))))) (letex ((Name (header 0)) (Default (map _makedef (1 header))) (Body (cons 'begin (args)))) (define-macro (Name) (letn ((_default 'Default) (_arglist (args)) (_offset-nil (find ': _arglist)) (_offset-len (or _offset-nil (length _arglist))) (_pos-default (0 _offset-len _default)) (_pos-arglist (0 _offset-len _arglist)) (_key-arglist (_offset-len _arglist))) (map set (map first _default) (map last _default)) (map set (map first _pos-default) (map eval _pos-arglist)) (if (!= (% (length _key-arglist) 3) 0) (throw 'error)) (dolist (_triple (explode _key-arglist 3)) (local (_tag _key _val) (map set '(_tag _key _val) _triple) (if (!= _tag ':) (throw error)) (set _key (eval _val)))) Body)))))