Search code examples
clojure

Clojure : access declared defrecord in another namespace


I am trying to access a "defrecord" from another ns and I get an error. I am able to access a declared "def" and an declared constructor but not the "defredord". This is the code:

(ns myapp.model)

(defrecord Person [fname lname])

(defn make-person [fname lname]
  (->Person fname lname))

(def p1 (make-person "John" "Doe"))

(ns ibercode.core

(:require [myapp.model :as model]))

;;OK
(def p2 (model/make-person "John" "Doe"))

;;OK
(prn model/p1)

;;clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: No 
;;such namespace: ->model, compiling:
(def p3 (->model/Person "John" "Doe"))

Thanks R.


Solution

  • You misunderstood ->. It is not syntax, but simply a naming convention.

    The name of the constructor function is ->Person, so qualified, it is model/->Person.