On Oct 28, 10:29 am, Stuart Sierra <[EMAIL PROTECTED]>
wrote:
> On Oct 27, 10:45 pm, "Stephen C. Gilardi" <[EMAIL PROTECTED]> wrote:
>
> > I used Stuart Sierra's 'fcase' contrib today to good effect. Nice job,
> > Stuart!
>
> Thanks!
>
> On Oct 28, 9:35 am, Rich Hickey <[EMAIL PROTECTED]> wrote:
>
> > If you'd like, I think the effort would be better spent on making a
> > version of fcase for the base library.
>
> Cool!
>
> > I'd like to save unadorned "case" for this meaning.
>
> Fine by me.
>
>
>
> > There is implicit arg ordering (pred clause-value test-value) which
> > doesn't matter for some preds (=) but does for others (instance?). For
> > the uses thus far, this order seems good - instance? and re-find work
> > well, but there will be cases where people will want (pred test-value
> > clause-value). The order of things in the macro structure might imply
> > the latter:
> ...
> > (condp (= x _)         ;doesn't matter
> > (condp (instance? _ x)
> > (condp (some #{x} _)
>
> How about just one argument, the predicate:  (condp #(= x %) ...)
> That would resolve the issue without adding syntax, no?
>

Well, condp *is* syntax, being a macro. This wouldn't add anything to
the reader syntax or anything, just an interpretation of (pred expr _)
or (pred _ expr). #(pred expr %) would cause expr to be evaluated
every clause.

> > As far as the default, providing a default value as odd last clause is
> > ok, but subtle, and could use layout help, if we do that we should do
> > the same for cond.
>
> I stole that idea from Arc's "if", which has the interesting quality
> of unifying "if" and "cond".  I often use the "else" clause to throw
> an exception:
>
> (condp #(= x %)
>   42 "The Meaning of Life"
>   13 "Unlucky"
>   1 "The loneliest number"
>   (throw (Exception. "Nothing matched."))
>
> I feel like "econdp" would be less clear, since you don't know what
> kind of exception should be thrown.  Plain old Exception? Or
> RuntimeError?

The kind of error is TBD, but it won't be random. It saves everyone a)
redundantly having to specify this, and b) specifying needlessly
different Exceptions and messages on no matching case. It's pretty
useful in CL.

>
> > Finally there is the name, which has to follow the form and function.
> > If we go with something like the last above, I like condp/econdp.
>
> I'm not sure about condp, only because Clojure hasn't used the CL-ish
> "-p" suffix anywhere else.  Ideas: condfn, fcond, cond-apply, cond-
> with, try-each,...

This wouldn't match the use of trailing p in CL, which has been
replaced by ? in Clojure. I like leading with cond so it sorts
together to make people aware of the option. I don't think I like any
of those better - whatever it is should be short.

Rich

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to