-
Notifications
You must be signed in to change notification settings - Fork 25
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
defn spec macro? #12
Comments
You're quite right, @didibus. Thanks for the reminder. Currently, we're using the below form for an alternative ; Example usage
(defn-spec str->kw keyword?
[s ::spec.util/non-blank]
(keyword s))
; Multiple arities are also supported
(defn-spec inc' number?
([a number?]
(inc' a 1))
([a number?, n number?]
(+ a n))) Others I've seen have gone for a We're currently using this, to great effect, but I haven't yet brought it into Orchestra. As for a timeline on this, I'll get it merged in tonight, with some tests and docs over the weekend. I'm not sure about a solution for |
I prefer that syntax to using :- as mentioned. I think if you don't want to spec everything, normal defn can do. And any? is always an option as you said. Is there a place in the syntax for the fn spec? Like maybe after the arg list? I guess I mentioned def without also really thinking about it. I guess something like this could maybe be useful: (def-spec symbol-name value) My thinking is that on the def-spec evaluation, it could use set-validator! to set the spec as the validator for the var, and also validate the initial value. If the value is another reference type, it could also set-validator! the spec on it and validate initial value. It would also now allow you to defn-spec a method and say it took [a ::symbol-name] as an argument. Not sure about the def-spec idea though. Especially the smart part with reference types, could get confusing as to what you are speccing. |
Clojure has built-in support for the meta map for functions, so Destructuring works, doc strings, meta maps. It should support everything |
@didibus I have added docs and released |
@jeaye Now that this has been released for a while, do you have any experience getting Cursive to play nice with recognizing the syntax? |
@sooheon Nope, sorry! I work in Vim and the rest of my team is in Emacs. In Vim, for example, any form starting with |
Thanks, I think this is just a matter of internal support in Cursive. |
On the Clojure mailing list, it was suggested that Orchestra was potentially working on adding a macro to replace def and defn, which would allow to define inline specs as the function/var is defined. Is this still on the roadmap?
The text was updated successfully, but these errors were encountered: