defn with inline specs?

226 views
Skip to first unread message

Daniel Compton

unread,
Jun 19, 2017, 6:01:34 PM6/19/17
to Clojure List
Currently I don't think it's possible to include a spec inline with a function definition. If you want to spec a function, it needs to come afterwards in an s/fdef. 

Is it planned for defn to have an extension to allow inline specs, similar to how pre and postconditions are defined in defn? I think the answer is no from memory, but I'm not sure why.

As a side note, I thought that this question, and other common questions could go well in the spec guide under a new spec FAQ section.

Thanks, Daniel.

Alex Miller

unread,
Jun 19, 2017, 6:23:18 PM6/19/17
to Clojure
No, we don't plan to add that. We think there is a lot of value in having them independent.

Rather than add it to the guide, I would prefer to add a section to the FAQ page. I've been to do so, but haven't gotten around to it yet.

Daniel Compton

unread,
Jun 19, 2017, 7:06:10 PM6/19/17
to Clojure
We think there is a lot of value in having them independent.

I agree that there's value in having them independent, and I'm not suggesting that fdef is taken away, but it seems like there's also value in having the ability to make them inline? It makes the code more concise and readable, and avoids typos between the defn name and the fdef name.

On Tue, Jun 20, 2017 at 10:23 AM Alex Miller <al...@puredanger.com> wrote:
No, we don't plan to add that. We think there is a lot of value in having them independent.

Rather than add it to the guide, I would prefer to add a section to the FAQ page. I've been to do so, but haven't gotten around to it yet.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Miller

unread,
Jun 19, 2017, 10:54:47 PM6/19/17
to Clojure
A spec is a commitment about what the function accepts and returns. Over time, the function may grow (by requiring less in the args or by providing more in the return). By combining the function and spec, it sends the message that you can and should change both together, rather than thinking about how you can grow the function while retaining the spec. 

Additionally, if I think about the changes that would be needed in the defn macro to make this happen they seem pretty gross. :)

On Monday, June 19, 2017 at 6:06:10 PM UTC-5, Daniel Compton wrote:
We think there is a lot of value in having them independent.

I agree that there's value in having them independent, and I'm not suggesting that fdef is taken away, but it seems like there's also value in having the ability to make them inline? It makes the code more concise and readable, and avoids typos between the defn name and the fdef name.

On Tue, Jun 20, 2017 at 10:23 AM Alex Miller <al...@puredanger.com> wrote:
No, we don't plan to add that. We think there is a lot of value in having them independent.

Rather than add it to the guide, I would prefer to add a section to the FAQ page. I've been to do so, but haven't gotten around to it yet.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to

For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages