Define new defn, lein uberjar succeeds to compile but lein run fails

108 views
Skip to first unread message

mattias w

unread,
Nov 13, 2015, 7:46:56 AM11/13/15
to Clojure

I defined my own defn in the namespace mwm.


My new code looks like this


(mwm/defn foo [x] ...)


Everything was fine as long as it was called defn2, but after renaming it to defn and refering to the original defn using clojure.core/defn, only "lein uberjar" works.

When I run "lein run", the compilation fails as


c:\data3\clojure\cdn77-purge>lein run
WARNING: defn already refers to: #'clojure.core/defn in namespace: mw.mwm, being
 replaced by: #'mw.mwm/defn
Exception in thread "main" java.lang.ClassNotFoundException: mw.mw1, compiling:(
mw/mw1.clj:40:1)
        at clojure.lang.Compiler.analyze(Compiler.java:6543)
        at clojure.lang.Compiler.analyze(Compiler.java:6485)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:3791)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:6725)


The code can be found at https://github.com/mattiasw2/cdn77-purge/tree/renamed_to_defn



mattias w

unread,
Nov 25, 2015, 3:29:43 AM11/25/15
to Clojure
I moved my own definition of defn to a separate project, and then it works. It seems you cannot redefine defn within the same project it is used.

Benjamin R. Haskell

unread,
Nov 25, 2015, 11:50:57 PM11/25/15
to clo...@googlegroups.com
It sounds like you're looking for refer-clojure: https://clojuredocs.org/clojure.core/refer-clojure

E.g., for your project:

(ns mw.mwm
  (:require
   [clojure.pprint :as pp]
   [clojure.walk :as walk])
  (:refer-clojure :exclude [defn])
  (:gen-class))


Defining your own `defn` is a fairly unorthodox thing to do.  (Usually it's less Clojure-centric names that cause problems, like `time` from the example, or `filter`, `min`, or `max`.)  Based on your comment, it seems easier to just write a different version of `get` that handles nils the way you want, instead of complicated macro behavior.  E.g.:

(defn get!   ;; "!" seems better than "?" to indicate the "dangerous" assert
  "Get a value out of a map, asserting it is non-nil"
  [from key]
  (let [val (get from key)]
    (assert (some? val) (str key " is nil"))
    val))

Seems much more straightforward than a macro that translates (:key? map) to something roughly equivalent to (get! map :key).

Best,
Ben

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+u...@googlegroups.com
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 unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages