Skip to content

Instantly share code, notes, and snippets.

@franks42
Created December 9, 2025 22:18
Show Gist options
  • Select an option

  • Save franks42/345be2b3baebc1bb0848ce2ffa7e16cf to your computer and use it in GitHub Desktop.

Select an option

Save franks42/345be2b3baebc1bb0848ce2ffa7e16cf to your computer and use it in GitHub Desktop.
Testing availability of function abs and constant cljs.core/Cons in nbb after adding entries to core.cljs' clojure.core namespace map
;; Test file to verify cljs.core/Cons and abs availability in nbb
;; Run with: nbb test-cons-abs.cljs
;;
;; Expected output WITHOUT fix:
;; Test 1 (abs): ERROR - Could not resolve symbol
;; Test 2 (Cons): ERROR - Could not resolve symbol
;;
;; Expected output WITH fix:
;; Test 1 (abs): 42
;; Test 2 (Cons): shows constructor function
;; Test 3 (instance?): true
(println "=== Testing cljs.core/Cons and abs in nbb ===")
(println)
;; 1. Test abs - use resolve to check at runtime
(println "1. Test abs:")
(if-let [abs-fn (resolve 'abs)]
(println " (abs -42) =" (@abs-fn -42))
(println " ERROR: Could not resolve symbol: abs"))
(println)
;; 2. Test cljs.core/Cons directly - use resolve
(println "2. Test cljs.core/Cons directly:")
(if-let [cons-var (resolve 'cljs.core/Cons)]
(let [cons-type (if (var? cons-var) @cons-var cons-var)]
(println " cljs.core/Cons =" cons-type))
(println " ERROR: Could not resolve symbol: cljs.core/Cons"))
(println)
;; 3. Test instance? with cljs.core/Cons
(println "3. Test (instance? cljs.core/Cons (cons 1 [])):")
(if-let [cons-var (resolve 'cljs.core/Cons)]
(let [cons-type (if (var? cons-var) @cons-var cons-var)]
(println " Result:" (instance? cons-type (cons 1 []))))
(println " ERROR: Cannot test - cljs.core/Cons not resolved"))
(println)
;; 4. Workaround that should work
(println "4. Workaround (type (cons 1 [])):")
(println " (instance? (type (cons 1 [])) (cons 2 [])):"
(instance? (type (cons 1 [])) (cons 2 [])))
(println)
(println "=== Done ===")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment