Arc Forumnew | comments | leaders | submitlogin
Suggested more general isa function...
2 points by Xichekolas 6175 days ago | 2 comments
In your tutorial you defined the isa function as such:

  (def isa (x y) 
    (is (type x) y))
I was thinking in the case of checking a lot of parameters for type (like form post vars or something), and it would be nice if I could do this all in one line. So I am proposing an alternate definition:

  (def isa (x . ys) 
    (all [is x (type _)] ys))
And you would call it like:

  (isa string "this will be" "and this" "this too" 'notthis)
At least I think that would work. Honestly haven't tried it, as I am on my lunch break, but I think it would work. It does change the ordering of parameters so the type is first and the values to check are the rest, but I think this reads more like english when you call it.

(As an aside: It a measure of what you have created that I can look at the tutorial once on my lunch break and already feel like I can use the idioms. I look forward to hacking on this tonight.)



1 point by jpt 6175 days ago | link

Why not just call it 'are-a'.

(are-a 'string "This" "is" "a" "test") t

-----

2 points by Xichekolas 6174 days ago | link

Because you could still test one thing with it.

  (isa 'string "somestring")

-----