pwalker

pwalker

Programming Clojure, Third Edition: Invalid token: ::music/id spec error (122)

Hi @alexmiller

I’ve been following along through PC 3rd, and hit a bump on page 122 - the ‘name’ format for the spec seems incorrect. I went back and it looked like adding a namespace might fix it, but that didn’t help either, I still get the ‘invalid token’ error.

Code:
(ns net.solarwinter
(:require [clojure.spec.alpha :as s]))

(s/def ::music/id uuid?)

Evaluating this produces:

  1. Unhandled clojure.lang.Compiler$CompilerException
    Error compiling spec.clj at (4:18)
    #:clojure.error{:phase :read-source,
    :line 4,
    :column 18,
    :source
    “/Users/paul/Documents/Programming/clojure/spec.clj”}
    Compiler.java: 7647 clojure.lang.Compiler/load
    REPL: 1 user/eval7690
    REPL: 1 user/eval7690
    Compiler.java: 7181 clojure.lang.Compiler/eval
    Compiler.java: 7136 clojure.lang.Compiler/eval
    core.clj: 3202 clojure.core/eval
    core.clj: 3198 clojure.core/eval
    interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn/fn
    AFn.java: 152 clojure.lang.AFn/applyToHelper
    AFn.java: 144 clojure.lang.AFn/applyTo
    core.clj: 667 clojure.core/apply
    core.clj: 1977 clojure.core/with-bindings*
    core.clj: 1977 clojure.core/with-bindings*
    RestFn.java: 425 clojure.lang.RestFn/invoke
    interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn
    main.clj: 437 clojure.main/repl/read-eval-print/fn
    main.clj: 437 clojure.main/repl/read-eval-print
    main.clj: 458 clojure.main/repl/fn
    main.clj: 458 clojure.main/repl
    main.clj: 368 clojure.main/repl
    RestFn.java: 1523 clojure.lang.RestFn/invoke
    interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
    interruptible_eval.clj: 152 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
    AFn.java: 22 clojure.lang.AFn/run
    session.clj: 218 nrepl.middleware.session/session-exec/main-loop/fn
    session.clj: 217 nrepl.middleware.session/session-exec/main-loop
    AFn.java: 22 clojure.lang.AFn/run
    Thread.java: 833 java.lang.Thread/run

  2. Caused by java.lang.RuntimeException
    Invalid token: ::music/id

I’m on Clojure 1.10.3 (java version “13.0.1” 2019-10-15, macOS Monterey, but I don’t think those should matter).

Marked As Solved

alexmiller

alexmiller

Author of Programming Clojure, Third Edition

I think this is a bug in the book in that the music alias is not defined before it’s used as a qualifier. To do so, you either need to define a namespace music that is loadable or, more commonly alias music to some longer namespace (which is also loadable):

(create-ns 'domain.music)
(alias 'music 'domain.music)

In Clojure 1.11, the new :as-alias clause in require allows you to do this without loading any namespace:

(require '[music :as-alias music])

Where Next?

Popular Pragmatic Bookshelf topics Top

jeremyhuiskamp
Title: Web Development with Clojure, Third Edition, vB17.0 (p9) The create table guestbook syntax suggested doesn’t seem to be accepted ...
New
jgchristopher
“The ProductLive.Index template calls a helper function, live_component/3, that in turn calls on the modal component. ” Excerpt From: Br...
New
brunogirin
When installing Cards as an editable package, I get the following error: ERROR: File “setup.py” not found. Directory cannot be installe...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
jwandekoken
Book: Programming Phoenix LiveView, page 142 (157/378), file lib/pento_web/live/product_live/form_component.ex, in the function below: d...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
Keton
When running the program in chapter 8, “Implementing Combat”, the printout Health before attack was never printed so I assumed something ...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New
New

Other popular topics Top

New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
DevotionGeo
I know that -t flag is used along with -i flag for getting an interactive shell. But I cannot digest what the man page for docker run com...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
New
AstonJ
We have a thread about the keyboards we have, but what about nice keyboards we come across that we want? If you have seen any that look n...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
Rainer
Not sure if following fits exactly this thread, or if we should have a hobby thread… For many years I’m designing and building model air...
New
dimitarvp
Small essay with thoughts on macOS vs. Linux: I know @Exadra37 is just waiting around the corner to scream at me “I TOLD YOU SO!!!” but I...
New
PragmaticBookshelf
Create efficient, elegant software tests in pytest, Python's most powerful testing framework. Brian Okken @brianokken Edited by Kat...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Sub Categories: