java - Clojure doto macro -


i going call .touppercase method within doto macro follows doto returns small letters:

(doto (java.lang.string. "clojure")        (.touppercase)) 

returns "clojure". macroexpansion , return value object created: (clojure.core/let [g__7359 (java.lang.string. "cojure")] (.touppercase g__7359) g__7359) , why don't uppercased answer?

doto part of clojure's java interop features. designed make possible write java out soooo darn many parens. so

foo foo = new foo; foo.setx().sety().makefactory().applyphaseofmoon(); 

which has 8 parens becomes:

(doto foo .sety .makefactory .applyphaseofmoon) 

which has total of two.

in case if dig expanstion of example:

user> (doto "hi" .touppercase) "hi" 

expands to:

user> (macroexpand-1 '(doto "hi" .touppercase)) (clojure.core/let [g__110453 "hi"]    (.touppercase g__110453)     g__110453) 

where second line this:

user> (.touppercase "hi") "hi" 

and throws answer away , returns saved value form start. never see doto used in practice outside of places people translating java clojure inorder call api.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -