Last active
April 26, 2017 20:27
-
-
Save edcrypt/934cda01dc23ad4b073c0cef3b33d936 to your computer and use it in GitHub Desktop.
Helper macro for attrs lib on Hy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; -*- mode: lisp; mode: paredit -*- | |
(defmacro defattrs [klass-name | |
&optional [super-klasses []] [options []] [attrs []] | |
&rest body] | |
`(do | |
(import attr) | |
(with-decorator ~(if options `(attr.s ~@options) 'attr.s) | |
(defclass ~klass-name ~super-klasses | |
~(list (interleave | |
(list-comp (if (coll? a) (first a) a) [a attrs]) | |
(list-comp `(attr.ib ~@(if (coll? a) | |
(list (rest a)) [])) | |
[a attrs]))) | |
~@body)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For even less boilerplate.
https://attrs.readthedocs.io/en/stable/
https://hylang.org
Similar to
(defclass)
, but generates__init__(...)
methods for you. Use it like this:TODO attr.s(...) options.