Why does (name <keyword>) return nil?

146 Views Asked by At

I'm scratching my head on this for a while. I have this hiccup snippet:

[:div.tab-pane {:id (name (:name t))} ...]

't' is a record with, among other fields, :name set to a keyword. This particular record has :name mapped to :testgroup.

If I run it like this:

[:div.tab-pane {:id (:name t)} ...]

The resulting html is not surprisingly: <div id=":testgroup" class="tab-pane" .../>

But when I run it calling (name (:name t)) i get: <div class="tab-pane" .../>

This has nothing to do with hiccup, in my tests for this function I get a nil value in the {:id } map in the original [:div ...] vector , but why?

1

There are 1 best solutions below

0
On

Silly mistake. In case others run into it:

What I omitted above is that the function is part of a protocol extended on that particular record. That means that the symbol name inside the protocol method is shadowed by the name field of the record. Calling clojure.core/name instead of name solved the problem.