-
Notifications
You must be signed in to change notification settings - Fork 42
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
condp (cond using predicate) ? #138
Comments
What I like about this construct is that you can encode "custom pattern matchers" with it, and the resulting code is nice to read. For example, a regex matcher: (condp (alexandria:rcurry #'ppcre:scan "my-string")
("^foo" :foo)
("^bar" :bar)
("^my.*" :mine)
("^mi.*" :mio)) Or a string matcher: (condp (alexandria:curry #'string= "some")
("foo" :foo)
("bar" :bar)
("some" :some)) (Now I'm thinking it could also be called What do you say @ruricolist ? Not interested? |
I think this would be nice to have. I like |
Is there a reason not to have a separate expression argument, like Clojure does? |
The reason is that I can control the order of arguments to the predicate using |
I'm not sure if Clojure has it, but a combinator like flip could be used
…On Mon, Jul 24, 2023, 7:56 PM Mariano Montone ***@***.***> wrote:
Is there a reason not to have a separate expression argument, like Clojure
does?
The reason is that I can control the order of arguments to the predicate
using curry or rcurry as in the examples.
I'm not sure how the Clojure version let's you control that.
If you know, please let me know. I'll have a closer look.
—
Reply to this email directly, view it on GitHub
<#138 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAC7AKCTXDQN7W3NF3WEN2TXR4KUNANCNFSM57HVK72A>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I thought about that, but by composing a predicate without a separate expression, I have complete control over how I can compose the predicate, and which arguments doesn't matter how many and where to pass them. And so I didn't see the point on separating predicate and expression. |
With the most extreme case of using a lambda: (condp (lambda (option) (string= option "my expression"))
("lala" :no)
("my expression" :yes)) I suppose it is a question of readability, as the predicate-only option is very flexible. |
I recently had a look at Clojure's condp: https://clojuredocs.org/clojure.core/condp
and I thought it could be handy for CL too, simplifies code.
Here is a slightly different implementation:
For example, this:
can be rewritten as:
Is there an idiom for this in CL or Serapeum already? Do you think this is worth including?
The text was updated successfully, but these errors were encountered: