1

This works fine:

(ns ns1) (defprotocol P (foo [this a])) (defrecord Foo [attr] P (foo [this a] a)) (println (foo (Foo. "test") "Works!")) 

But when I move the protocol to its own namespace like so:

(ns ns2) (defprotocol P (foo [this a])) 

Then this throws a Use of undeclared var ns1/foo

(ns ns1 (:require ns2 :refer [P])) (defrecord Foo [attr] P (foo [this a] a)) (println (foo (Foo. "test") "Undeclared var?")) 

I found this really nice write up that makes sense for Clojure and Java.

Is it possible to get my example above to work in clojurescript?

Update: I knew I was missing something super simple! For the record, as mentioned in the accepted answer: all I needed was to refer foo like so:

(ns ns1 (:require ns2 :refer [P foo])) (defrecord Foo [attr] P (foo [this a] a)) (println (foo (Foo. "test") "Works once again")) 

1 Answer 1

3

The answer is right in the blog post you linked. You have to :refer the protocol functions you wish to use (or use them more explicitly, as is the style these days, using :require :as).

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.