Thanks James gonna try it out now
On Thursday, 18 May 2017 17:46:02 UTC+1, James Reeves wrote:
>
> I'd first factor out all the parts you can into a function. So for
> instance:
>
> (defn html-spec [html-tag]
> (s/or :map (st-ds/spec html-tag {:tag (tag html-tag)})
> :vector (s/cat :tag (tag html-tag))))
>
> This will allow you to write:
>
> (s/def ::a (html-spec ::a))
>
> I'd be inclined to leave it there, but if you really want to use a macro,
> we could write:
>
> (defmacro def-html-spec [html-tag]
> `(s/def ~html-tag (html-spec ~html-tag)))
>
> Notice that the macro starts with "def". This is a good indicator for
> anyone using it that this is a macro that defines something.
>
> On 18 May 2017 at 17:23, david swift <[email protected] <javascript:>>
> wrote:
>
>> I forgot to mention I am using the following library
>> https://github.com/metosin/spec-tools; where you see (st-ds/spec) calls
>> is the use of that library.
>>
>>
>> On Thursday, 18 May 2017 17:21:45 UTC+1, david swift wrote:
>>>
>>> Hey Guys,
>>>
>>> I am looking for help creating a particular function/macro, right now
>>> I've no experience using macro's and I'm under the impression it might be
>>> the right solution to my problem, that produces a spec output but a very
>>> specific spec output. My goal here is to reduce the constant repeating of
>>> the same spec over and over with only the tag portion being the part that
>>> changes.
>>>
>>> this is a little helper function I've been using to reduce repeating
>>> (defn- tag [tag] (s/and keyword? #{tag}))
>>>
>>> this is the core of what I need help with, this is currently what I have
>>> and find it not to work, even in macro form but that's most likely down to
>>> my poor knowledge of macro's.
>>> (defn html-spec-creator [html-tag]
>>> (s/def html-tag
>>> (s/or
>>> :map (st-ds/spec html-tag {:tag (tag html-tag)})
>>> :vector (s/cat :tag (tag html-tag)))))
>>>
>>>
>>> (html-spec-creator ::a)
>>>
>>> the intended output of the above is to produce the following
>>> (s/def ::a (s/or :map (st-ds/spec ::a {:tag (tag :a)}) :vector (s/cat :tag
>>> (tag :a))))
>>>
>>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to [email protected]
>> <javascript:>
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> [email protected] <javascript:>
>> 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 [email protected] <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> James Reeves
> booleanknot.com
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
For more options, visit https://groups.google.com/d/optout.