Re: Neophyte question

2009-10-22 Thread Timothy Pratley
On Oct 22, 5:55 pm, Christophe Grand wrote: > (def hexchar? (set "0123456789ABCDEFabcdef")) That's really nice! Here is my perverse entry for fun: (def hexchar? (set (map char (mapcat range [48 65 97] [58 71 103] --~--~-~--~~~---~--~~ You received this me

Re: Neophyte question

2009-10-21 Thread Christophe Grand
On Wed, Oct 21, 2009 at 5:50 PM, Lauri Pesonen wrote: > > 2009/10/21 John Harrop : > > > Like this? > > (def hexchar? #{\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \a \B \b \C \c \D \d \E > \e > > \F \f}) > > Yep, that's what I had in mind as well, but I got tired of typing ;-) > (def hexchar? (set "01234

Re: Neophyte question

2009-10-21 Thread Mark Nutter
Thanks, all, that's enlightening. So if I understand correctly, I designed hexchar? to accept a string argument, which means it needed a CharSequence, right? But instead it was getting a Char, which is not the same thing as a one-character string, and thus was not a CharSequence. Yahrgh, I've bee

Re: Neophyte question

2009-10-21 Thread Lauri Pesonen
2009/10/21 John Harrop : > Like this? > (def hexchar? #{\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \a \B \b \C \c \D \d \E \e > \F \f}) Yep, that's what I had in mind as well, but I got tired of typing ;-) -- ! Lauri --~--~-~--~~~---~--~~ You received this message beca

Re: Neophyte question

2009-10-21 Thread John Harrop
On Wed, Oct 21, 2009 at 10:51 AM, Lauri Pesonen wrote: > One way to fix this would be to produce a string out of c: > > (defn hexchar? [c] (re-find #"[0-9A-Fa-f]" (str c))) > > but you should really change hexchar? into something more elegant. Like this? (def hexchar? #{\0 \1 \2 \3 \4 \5 \6 \7

Re: Neophyte question

2009-10-21 Thread Lauri Pesonen
Hi Mark, 2009/10/21 Mark Nutter : > > (defn blank? [s] (every? #(Character/isWhitespace %) s)) > user=> (defn hexchar? [c] (re-find #"[0-9A-Fa-f]" c)) > user=> (defn hex? [s] (every? #(hexchar? %) s)) > #'user/hex? > nil > user=> (hex? "a") > # cannot be cast to java.lang.CharSequence (NO_S

Re: Neophyte question

2009-10-21 Thread Fogus
The problem is that hexchar? expects a CharSequence, but by using every? you're actually passing a Character into it. The quick fix is to change hex? to (defn hex? [s] (every? #(hexchar? (str %)) s)). However, the better solution is probably to change hexchar? to accept Characters instead -- a la

Neophyte question

2009-10-21 Thread Mark Nutter
Hi all, newcomer to clojure/lisp/fp here. I'm working my way through the Programming Clojure book (very excellent, well worth the money), and doing some dabbling in the REPL, and I'm seeing something that puzzles me. In the book there's an example of a clojure blank? function that looks like this: