It's not pattern matching, but would replacing the apply with a reduce
achieve the same result?

I'm not in a position to test this right now, but I believe (reduce f init
()) returns init without invoking f, and (conj x a b c) is equivalent to
(reduce conj x [a b c]), so replacing apply with reduce should let you get
rid of the if.

On Tuesday, 9 February 2016, Stuart Sierra <the.stuart.sie...@gmail.com
<javascript:_e(%7B%7D,'cvml','the.stuart.sie...@gmail.com');>> wrote:

> Clojure's destructuring is not the same thing as the "pattern matching"
> found in some other functional languages. Pattern matching can do various
> conditional checks, destructuring cannot. Clojure's "defn" supports
> destructuring in the argument list.
>
> Full pattern matching is available in Clojure via libraries such as
> core.match:
> https://github.com/clojure/core.match
>
> –S
>
>
>
> On Monday, February 8, 2016 at 2:41:44 PM UTC-5, Laws wrote:
>>
>> Sean Johnson has a great video about pattern matching, where he suggests
>> that any function that starts with a conditional should have the
>> conditional removed and the conditional logic implemented as
>> pattern-matching and restructuring in the signature of the function. But
>> after some experimentation, I have failed to figure out a way to do this
>> here:
>>
>> (defn add-parties-to-customer-queue [parties]
>>   (if (seq parties)
>>     (swap! customer-queue
>>            (fn [previous-customer-queue]
>>              (apply conj previous-customer-queue parties)))))
>>
>> "parties" sometimes has a vector of vectors, but sometimes it is simply:
>> ()
>>
>> Is there any way I can match against that pattern in the function
>> signature?
>>
>>
>>
>>
>>
>> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@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+unsubscr...@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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@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+unsubscr...@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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to