Skip to content

Instantly share code, notes, and snippets.

@myguidingstar
Last active July 29, 2021 10:29
Show Gist options
  • Save myguidingstar/77340c5b145e1e657ca693dbe2e997fa to your computer and use it in GitHub Desktop.
Save myguidingstar/77340c5b145e1e657ca693dbe2e997fa to your computer and use it in GitHub Desktop.
(ns helloworld.core)
;; two identical code blocks
;; first one is at top level
(let [{:keys [a-b a_b]} {:a-b 0 :a_b 1}] [a-b a_b])
;; second one nested inside a function call
(println (let [{:keys [a-b a_b]} {:a-b 0 :a_b 1}] [a-b a_b]))
// Compiled by ClojureScript 1.10.866 {:optimizations :none}
goog.provide('helloworld.core');
goog.require('cljs.core');
var map__528_529 = new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"a-b","a-b",-1660985764),(0),new cljs.core.Keyword(null,"a_b","a_b",-1795286609),(1)], null);
var map__528_530__$1 = cljs.core.__destructure_map.call(null,map__528_529);
var a_b_531 = cljs.core.get.call(null,map__528_530__$1,new cljs.core.Keyword(null,"a-b","a-b",-1660985764));
var a_b_532 = cljs.core.get.call(null,map__528_530__$1,new cljs.core.Keyword(null,"a_b","a_b",-1795286609));
new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a_b_531,a_b_532], null);
cljs.core.println.call(null,(function (){var map__533 = new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"a-b","a-b",-1660985764),(0),new cljs.core.Keyword(null,"a_b","a_b",-1795286609),(1)], null);
var map__533__$1 = cljs.core.__destructure_map.call(null,map__533);
var a_b = cljs.core.get.call(null,map__533__$1,new cljs.core.Keyword(null,"a-b","a-b",-1660985764));
var a_b = cljs.core.get.call(null,map__533__$1,new cljs.core.Keyword(null,"a_b","a_b",-1795286609));
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a_b,a_b], null);
})());
//# sourceMappingURL=core.js.map
{:deps {org.clojure/clojurescript {:mvn/version "1.10.866"}}}
@myguidingstar
Copy link
Author

myguidingstar commented Jul 29, 2021

  • the a-b and a_b symbols in first block ended up as var a_b_531 and var a_b_532.
  • in the second block they both ended up as var a_b, therefore their values collided.

@myguidingstar
Copy link
Author

the setup is similar to the clojurescript official guide https://clojurescript.org/guides/quick-start
Compiled with clj -M --main cljs.main --compile helloworld.core

@myguidingstar
Copy link
Author

The same result with macroexpanded version using let*, so we can eliminate the case that something is wrong with cljs.core/let macro:

(let* [m {:a-b 0, :a_b 1}
       a-b
       (cljs.core/get m :a-b)
       a_b
       (cljs.core/get m :a_b)]
  [a-b a_b])

(println 
 (let* [m {:a-b 0, :a_b 1}
        a-b
        (cljs.core/get m :a-b)
        a_b
        (cljs.core/get m :a_b)]
   [a-b a_b]))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment