The "->" & "." nested usage
Following a blog post on building large object graphs I was suggested with the following solution: (def nested-object (-> GrandFather. Father. GrandSon.)) this indeed seems to be correct however fails in even in a simple example: user=> (-> String. String.) java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) expanding the macros involved seems to reveal the issue: user=> (macroexpand-1 `(-> String. String.)) (java.lang.String. java.lang.String.) the "." macro isn't expanded. Is there a way of applying nested macros? (iv searched for "applying nested macros" with no results). --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
you need to pass something in. example: => (-> "foo" String. String.) "foo" => (macroexpand '(-> String. String.)) (new String String.) => (macroexpand '(-> "foo" String. String.)) (new String (clojure.core/-> "foo" String.)) => (macroexpand '(-> "foo" String.)) (new String "foo") String. is only treated as new String ... when it is placed in the function position (String. ...) in (-> String. String.) the first String. is never put in the function position, so effectively you get (String. String.) On Mon, Jun 8, 2009 at 12:38 PM, ronen wrote: > > Following a blog post on building large object graphs I was suggested > with the following solution: > (def nested-object (-> GrandFather. Father. GrandSon.)) > > this indeed seems to be correct however fails in even in a simple > example: > > user=> (-> String. String.) > java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) > > expanding the macros involved seems to reveal the issue: > > user=> (macroexpand-1 `(-> String. String.)) > (java.lang.String. java.lang.String.) > > the "." macro isn't expanded. > > Is there a way of applying nested macros? > (iv searched for "applying nested macros" with no results). > > > > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
On Jun 8, 2009, at 12:38 PM, ronen wrote: user=> (-> String. String.) java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) expanding the macros involved seems to reveal the issue: user=> (macroexpand-1 `(-> String. String.)) (java.lang.String. java.lang.String.) the "." macro isn't expanded. The trailing dot syntax is used for creating an object given a class name: (String.) creates a String object. Nested macros work fine. What were you hoping the above expressions would expand to? Here's an example of -> in action: (-> (System/getProperties) (.get "java.class.path") .toUpperCase (nth 3) int (* 2)) --Steve smime.p7s Description: S/MIME cryptographic signature
Re: The "->" & "." nested usage
I see, using "->" with "." will not create a chain of "new" invocations, the best solution that iv found is: user=> (String. (String.)) "" user=> (macroexpand (String. (String.))) "" user=> (macroexpand `(String. (String.))) (new java.lang.String (java.lang.String.)) Nesting is a must :) Thank you both for your helpful reply On Jun 8, 10:51 pm, Kevin Downey wrote: > you need to pass something in. > example: > > => (-> "foo" String. String.) > "foo" > > => (macroexpand '(-> String. String.)) > (new String String.) > > => (macroexpand '(-> "foo" String. String.)) > (new String (clojure.core/-> "foo" String.)) > => (macroexpand '(-> "foo" String.)) > (new String "foo") > > String. is only treated as new String ... when it is placed in the > function position (String. ...) > in (-> String. String.) the first String. is never put in the > function position, so effectively you get > (String. String.) > > > > On Mon, Jun 8, 2009 at 12:38 PM, ronen wrote: > > > Following a blog post on building large object graphs I was suggested > > with the following solution: > > (def nested-object (-> GrandFather. Father. GrandSon.)) > > > this indeed seems to be correct however fails in even in a simple > > example: > > > user=> (-> String. String.) > > java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) > > > expanding the macros involved seems to reveal the issue: > > > user=> (macroexpand-1 `(-> String. String.)) > > (java.lang.String. java.lang.String.) > > > the "." macro isn't expanded. > > > Is there a way of applying nested macros? > > (iv searched for "applying nested macros" with no results). > > -- > And what is good, Phaedrus, > And what is not good— > Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
Just to be clear, is (String.) a macro? I thought it was just a special form. On Mon, Jun 8, 2009 at 3:47 PM, Stephen C. Gilardi wrote: > > On Jun 8, 2009, at 12:38 PM, ronen wrote: > > user=> (-> String. String.) > java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) > > expanding the macros involved seems to reveal the issue: > > user=> (macroexpand-1 `(-> String. String.)) > (java.lang.String. java.lang.String.) > > the "." macro isn't expanded. > > > The trailing dot syntax is used for creating an object given a class name: > > (String.) > > creates a String object. > > Nested macros work fine. What were you hoping the above expressions would > expand to? > > Here's an example of -> in action: > > (-> (System/getProperties) (.get "java.class.path") .toUpperCase (nth 3) > int (* 2)) > > --Steve > > --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
sure it can, you just need to pass in an initial value. (-> (String.) String. String.) ; works (-> x String. String.) ;works for any x where string has a constructor that takes something of type x for example (-> "file.txt" File. FileReader. BufferedReader.) will return a buffered reader on file.txt (assuming you import those classes from java.io) On Mon, Jun 8, 2009 at 12:59 PM, ronen wrote: > > I see, using "->" with "." will not create a chain of "new" > invocations, the best solution that iv found is: > user=> (String. (String.)) > "" > user=> (macroexpand (String. (String.))) > "" > user=> (macroexpand `(String. (String.))) > (new java.lang.String (java.lang.String.)) > > Nesting is a must :) > Thank you both for your helpful reply > > On Jun 8, 10:51 pm, Kevin Downey wrote: >> you need to pass something in. >> example: >> >> => (-> "foo" String. String.) >> "foo" >> >> => (macroexpand '(-> String. String.)) >> (new String String.) >> >> => (macroexpand '(-> "foo" String. String.)) >> (new String (clojure.core/-> "foo" String.)) >> => (macroexpand '(-> "foo" String.)) >> (new String "foo") >> >> String. is only treated as new String ... when it is placed in the >> function position (String. ...) >> in (-> String. String.) the first String. is never put in the >> function position, so effectively you get >> (String. String.) >> >> >> >> On Mon, Jun 8, 2009 at 12:38 PM, ronen wrote: >> >> > Following a blog post on building large object graphs I was suggested >> > with the following solution: >> > (def nested-object (-> GrandFather. Father. GrandSon.)) >> >> > this indeed seems to be correct however fails in even in a simple >> > example: >> >> > user=> (-> String. String.) >> > java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) >> >> > expanding the macros involved seems to reveal the issue: >> >> > user=> (macroexpand-1 `(-> String. String.)) >> > (java.lang.String. java.lang.String.) >> >> > the "." macro isn't expanded. >> >> > Is there a way of applying nested macros? >> > (iv searched for "applying nested macros" with no results). >> >> -- >> And what is good, Phaedrus, >> And what is not good— >> Need we ask anyone to tell us these things? > > > -- And what is good, Phaedrus, And what is not good— Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
Great! that was the missing bit i was looking for. thanks for clearing it out (& it seems that String. is indeed a macro) On Jun 8, 11:05 pm, Kevin Downey wrote: > sure it can, you just need to pass in an initial value. > > (-> (String.) String. String.) ; works > (-> x String. String.) ;works for any x where string has a constructor > that takes something of type x > > for example > > (-> "file.txt" File. FileReader. BufferedReader.) > > will return a buffered reader on file.txt (assuming you import those > classes from java.io) > > > > On Mon, Jun 8, 2009 at 12:59 PM, ronen wrote: > > > I see, using "->" with "." will not create a chain of "new" > > invocations, the best solution that iv found is: > > user=> (String. (String.)) > > "" > > user=> (macroexpand (String. (String.))) > > "" > > user=> (macroexpand `(String. (String.))) > > (new java.lang.String (java.lang.String.)) > > > Nesting is a must :) > > Thank you both for your helpful reply > > > On Jun 8, 10:51 pm, Kevin Downey wrote: > >> you need to pass something in. > >> example: > > >> => (-> "foo" String. String.) > >> "foo" > > >> => (macroexpand '(-> String. String.)) > >> (new String String.) > > >> => (macroexpand '(-> "foo" String. String.)) > >> (new String (clojure.core/-> "foo" String.)) > >> => (macroexpand '(-> "foo" String.)) > >> (new String "foo") > > >> String. is only treated as new String ... when it is placed in the > >> function position (String. ...) > >> in (-> String. String.) the first String. is never put in the > >> function position, so effectively you get > >> (String. String.) > > >> On Mon, Jun 8, 2009 at 12:38 PM, ronen wrote: > > >> > Following a blog post on building large object graphs I was suggested > >> > with the following solution: > >> > (def nested-object (-> GrandFather. Father. GrandSon.)) > > >> > this indeed seems to be correct however fails in even in a simple > >> > example: > > >> > user=> (-> String. String.) > >> > java.lang.ClassNotFoundException: String. (NO_SOURCE_FILE:7) > > >> > expanding the macros involved seems to reveal the issue: > > >> > user=> (macroexpand-1 `(-> String. String.)) > >> > (java.lang.String. java.lang.String.) > > >> > the "." macro isn't expanded. > > >> > Is there a way of applying nested macros? > >> > (iv searched for "applying nested macros" with no results). > > >> -- > >> And what is good, Phaedrus, > >> And what is not good— > >> Need we ask anyone to tell us these things? > > -- > And what is good, Phaedrus, > And what is not good— > Need we ask anyone to tell us these things? --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
On 08.06.2009, at 21:59, Andrew Wagner wrote: > Just to be clear, is (String.) a macro? I thought it was just a > special form. Let's ask Clojure: (macroexpand-1 '(String.)) -> (new String) So it's a macro. The only difference between a macro and a special form is that a macro expands into something, whereas a special form is handled directly by the compiler. This also means that the distinction is implementation-dependent: Clojure 1.1 could very well implement (String.) as a special form, or implement new as a macro. Konrad. --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
So there's a different macro analogous to "String." for a bunch of different classes, and it doesn't work for arbitrary classes? On Tue, Jun 9, 2009 at 2:55 AM, Konrad Hinsen wrote: > > On 08.06.2009, at 21:59, Andrew Wagner wrote: > > > Just to be clear, is (String.) a macro? I thought it was just a > > special form. > > Let's ask Clojure: > >(macroexpand-1 '(String.)) > -> (new String) > > So it's a macro. The only difference between a macro and a special > form is that a macro expands into something, whereas a special form > is handled directly by the compiler. This also means that the > distinction is implementation-dependent: Clojure 1.1 could very well > implement (String.) as a special form, or implement new as a macro. > > Konrad. > > > > > --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
Andrew Wagner a écrit : > So there's a different macro analogous to "String." for a bunch of > different classes, and it doesn't work for arbitrary classes? It works for arbitrary classes. Any symbol that ends with a dot macroexpands to a 'new form. => (macroexpand '(AndrewWagner.)) (new AndrewWagner) In this sense, String. is a macro (since it macroexpands) but there's no defmacro statement, it's a special case of macroexpansion -- just like .method, see: => (macroexpand '(.bar foo)) (. foo bar) In both case it's not a special form (because special-symbol? returns false) nor a readermacro (if you try quoting them at the repl, they won't expand). hth Christophe > On Tue, Jun 9, 2009 at 2:55 AM, Konrad Hinsen > mailto:konrad.hin...@laposte.net>> wrote: > > > On 08.06.2009, at 21:59, Andrew Wagner wrote: > > > Just to be clear, is (String.) a macro? I thought it was just a > > special form. > > Let's ask Clojure: > >(macroexpand-1 '(String.)) > -> (new String) > > So it's a macro. The only difference between a macro and a special > form is that a macro expands into something, whereas a special form > is handled directly by the compiler. This also means that the > distinction is implementation-dependent: Clojure 1.1 could very well > implement (String.) as a special form, or implement new as a macro. > > Konrad. > > > > > > > -- Professional: http://cgrand.net/ (fr) On Clojure: http://clj-me.blogspot.com/ (en) --~--~-~--~~~---~--~~ 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 Note that posts from new members are moderated - please be patient with your first post. 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: The "->" & "." nested usage
Hi, Am 09.06.2009 um 12:57 schrieb Andrew Wagner: So there's a different macro analogous to "String." for a bunch of different classes, and it doesn't work for arbitrary classes? Any Symbol ending in a dot is treated as macro expanding into (new TheSymbol). Similar Symbols starting in a dot are handled specially as macros expanding into (. thing theSymbol). So this works for arbitrary classes/methods. Sincerely Meikel smime.p7s Description: S/MIME cryptographic signature