Thanks for digging.
The mapping of "-" to "_" comes indeed from clojure.lang.Compile/munge which is
called by cljsh.compiler/munge:
--------------------
user=> (#'cljs.compiler/munge "-")
"_"
user => (clojure.lang.Compiler/munge "-")
"_"
user => (clojure.lang.Compiler/munge "_")
"_"
user =>
--------------------
Looking at the java-source, the reason can be found in the CHAR_MAP mapping
table in Compiler.java:
--------------------
static final public IPersistentMap CHAR_MAP =
PersistentHashMap.create('-', "_",
// '.', "_DOT_",
':', "_COLON_",
'+', "_PLUS_",
'>', "_GT_",
'<', "_LT_",
'=', "_EQ_",
'~', "_TILDE_",
'!', "_BANG_",
'@', "_CIRCA_",
'#', "_SHARP_",
'\'', "_SINGLEQUOTE_",
'"', "_DOUBLEQUOTE_",
'%', "_PERCENT_",
'^', "_CARET_",
'&', "_AMPERSAND_",
'*', "_STAR_",
'|', "_BAR_",
'{', "_LBRACE_",
'}', "_RBRACE_",
'[', "_LBRACK_",
']', "_RBRACK_",
'/', "_SLASH_",
'\\', "_BSLASH_",
'?', "_QMARK_");
static public String munge(String name){
StringBuilder sb = new StringBuilder();
for(char c : name.toCharArray())
{
String sub = (String) CHAR_MAP.valAt(c);
if(sub != null)
sb.append(sub);
else
sb.append(c);
}
return sb.toString();
}
--------------------
Note that it's in the first entry of CHAR_MAP - a little obscured by the
(original) formatting.
What's puzzling is that all mappings use a convention to map the char to a
_WORD_ , except the "-" which gets mapped to "_" directly.
What's further puzzling is that in the clj-repl this mapping deosn't seemed to
be used:
--------------------
user=> (def my-var "YES")
#'user/my-var
user => (def my_var "NO")
#'user/my_var
user => my-var
"YES"
swimtimer=>
--------------------
Guess the AOT compiler uses it but the REPL-one doesn't (???).
Confused - FrankS.
On Sep 24, 2012, at 6:53 AM, Herwig Hochleitner <[email protected]> wrote:
>
> Not sure if this has been reported before - I searched JIRA and the mailing
> list, but couldn't find anything, but it's difficult to search for "_"…
>
> Bug?
> Mapping limitation?
>
> This behavior comes from cljs.compiler/munge, I'd say it's a mapping
> limitation that should be considered a bug.
> A possible fix would be to replace _ with _UNDERSCORE_ in munge.
>
> Notice that clojure.core/munge has the same limitation and should probably
> fixed aswell:
>
> (defn foo-bar []
> "DASH")
>
> (defn foo_bar []
> "UNDERSCORE")
>
> (defn -main []
> (println "Dash version: " (foo-bar))
> (println "Underscore version: " (foo_bar)))
>
>
> When AOT compiling this example and running it, it prints:
>
> Dash version: UNDERSCORE
> Underscore version: UNDERSCORE
>
> as opposed to the expected
>
> Dash version: DASH
> Underscore version: UNDERSCORE
>
> when running from source.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en