Question

EDIT : SOLVED My issue was coming from two things -- I had a syntax error in the defmacro somewhere. I deleted it and wrote a small function that I could then access (only after restarting the repl). The big second-issue was that I was ignorant to the fact repl needed to be restarted to recognize any changes I had made. Would never have figured this out without the concrete answer given below =).

I have been working through the pedestal tutorial on github, and it recommends testing some things via repl - my problem is that I can't find the namespace/ macros or functions I am interested in working with.

user=> (require '(junkyard-client.html-templates))
nil
user=> (def t (junkyard-client-templates))

user=> CompilerException java.lang.RuntimeException: Unable to resolve symbol: 
  junkyard-client-templates in this context, compiling:
  (C:\Users\Ben\AppData\Local\Temp\form-init3290053673397861360.clj:1:8)

I have tried other things syntactically, such as (require 'junkyard-client.html-templates). This is at v2.0.10 in the pedestal tutorial:https://github.com/pedestal/app-tutorial/wiki/Slicing-Templates

EDIT: this is what I am trying to get to

(ns junkyard-client.html-templates
  (:use [io.pedestal.app.templates :only [tfn dtfn tnodes]]))

(defmacro junkyard-client-templates
  []
  {:junkyard-client-page (dtfn (tnodes "junkyard-client.html" "hello") #{:id})
   :other-counter (dtfn (tnodes "tutorial-client.html" "other-counter") #{:id}
  })

problem stage https://github.com/Sammons/clojure-projects/tree/d9e0b4f6063006359bf34a419deb31a879c7a211/pedestal-app-tutorial/junkyard-client

solved stage

Was it helpful?

Solution

require makes the namespace available within your current namespace, but does not make the symbols directly available. You still need to namespace qualify the symbols, unless you use :refer or use.

(require '[junkyard-client.html-templates])

(def t (junkyard-client.html-templates/junkyard-client-templates))

It might be preferable to alias the namespace or refer the specific symbol you are using, for convenience.

Alias:

(require '[junkyard-client.html-templates :as templates])

(def t (templates/junkyard-client-templates))

Refer:

(require '[junkyard-client.html-templates :refer [junkyard-client-templates]])

(def t (junkyard-client-templates))

Note: require and :refer is generally preferred over use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top