Characters allowed in symbols
The Clojure documentation, under "Reader", gives a list of characters allowed in a symbol name. The characters, <, >, and = are not included in this list. How is it then that <, <=, >, >=, =, etc. are symbols? (I assume they are symbols because I can write (< 3 4), etc.) --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Using method names in macros
I'm in the process of learning Clojure, and I ran across something that other newbies like me may find useful. The question I had was this: how does one get a method name into a macro? Consider the following code: (defmacro foo [x] `(. Character (isWhitespace ~x))) Yes, I know that this would be better defined as a function, but it's a simple example to illustrate the problem. If I evaluate (macroexpand '(foo \a)) I get (. java.lang.Character (user/isWhitespace \a)) which is not what I want -- the expansion of Character to java.lang.Character is fine, but I want the symbol isWhitespace to remain as is. Trying to evaluate (foo \a) gives a "no such var" exception, as user/isWhitespace is not found. The solution I found was to keep the symbol isWhitespace out of the scope of the backquote operator: (defmacro foo [x] `(. Character (~'isWhitespace ~x))) Then (foo \a) expands to (. java.lang.Character (isWhitespace \a)) as desired. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Bug report -- macros within let [Re: Bizarre behavior (bug?) for unchecked-add]
I have more information on this now, and it is definitely a bug in Clojure -- defmacro within a let doesn't work correctly. Consider the following file: --- BEGIN foo1a.coj --- (ns com.ksvanhorn.foo1a) (let [dummy 0] (defmacro add [& args] `(unchecked-add ~...@args)) (defmacro mul [& args] `(unchecked-multiply ~...@args)) (let [magic 1812433253 x 5489 v (add 1 (mul magic x))] (println (str "v: " v --- END --- If I type "(use 'com.ksvanhorn.foo1a)" at the REPL, I get v: (clojure.core/unchecked-add 1 (clojure.core/unchecked-multiply 1812433253 5489)) printed out and nil returned, but if I just type (uncheck-add 1 (unchecked-multiply 1812433253 5489)) I get 1301868182. Although in this case the defmacro doesn't need to be inside the let, I actually have a real need for doing defmacro inside a let -- I have a computed constant that I want to use in several places, and one of those places is in the macro definition. --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---
Re: Bit-Shift without Sign-Extend?
Here's how I implemented the ">>>" operator for ints: (let [intmask (dec (bit-shift-left 1 32))] (defmacro ushr [x n] `(int (bit-shift-right (bit-and ~intmask ~x) ~n The (bit-and intmask x) expression effectively gives you the unsigned equivalent of x. For bytes, use 255 instead of intmask. On May 21, 7:39 pm, CuppoJava wrote: > Hi everyone, > I'm just wondering where the equivalent of the ">>>" operator is for > Clojure. I need it to do a divide-by-power-of-2 on unsigned bytes. > -Patrick --~--~-~--~~~---~--~~ 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 clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~--~~~~--~~--~--~---