clojure 2026-01-19

can somebody help me understand the following error and why it occurs?

user=> (map .toUpperCase ["a" "b"])
Syntax error compiling at (REPL:1:1).
Unable to resolve symbol: .toUpperCase in this context
I managed to figure out a way to do what I want to do with an anonymous function, but I'm wondering how .toUpperCase is parsed, vs having it in an anonymous function with #(.toUpperCase %) (which works)

user=> (macroexpand '(.foo 1))
(. 1 foo)
user=>

(.f x) is sugar for (. x f), which is a special form: https://clojure.org/reference/java_interop#_the_dot_special_form It basically resolves f in the context of x and calls it. With (map .f [x]), Clojure first has to parse the form, then evaluate all arguments to map, then finally call map with those values. .f there is a plain symbol which cannot be resolved. So you either need that lambda to create the dot form, or you can use the syntax that's new in 1.12 and use String/.toUpperCase.

.toUpperCase is syntax sugar implemented in the compiler that gets expanded into the older . special form

the "expansion" just happens to happen after macro expansion in the compiler, so macroexpand is a useful way to demo it, it is not a macro

🙏 1

thanks, guys. I'm a bit lost in the details... but I guess the key idea is the order in which things are evaluated/expanded?

(side note: I'm not specifically using .toUpperCase (but thank you!); this was just an easy one to demo in lieu of my actual code)

It isn't the order in which things are evaluated, it is the fact (.foo bar) is special syntax, but outside of that context .foo is just a random symbol that isn't bound to any value

👍 1

ahh, ok. Thank you for that clarification!