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])

Popular Prag Prog topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
Razor54672
The answer to 3rd Problem of Chapter 5 (Making Choices) of “Practical Programming, Third Edition” seems incorrect in the given answer ke...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
sdmoralesma
Title: Web Development with Clojure, Third Edition - migrations/create not working: p159 When I execute the command: user=> (create-...
New
Mmm
Hi, build fails on: bracket-lib = “~0.8.1” when running on Mac Mini M1 Rust version 1.5.0: Compiling winit v0.22.2 error[E0308]: mi...
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New
jskubick
I found an issue in Chapter 7 regarding android:backgroundTint vs app:backgroundTint. How to replicate: load chapter-7 from zipfile i...
New
brunogirin
When running tox for the first time, I got the following error: ERROR: InterpreterNotFound: python3.10 I realised that I was running ...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New

Other popular topics Top

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
PragmaticBookshelf
“A Mystical Experience” Hero’s Journey with Paolo Perrotta @nusco Ever wonder how authoring books compares to writing articles?...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
Maartz
Hi folks, I don’t know if I saw this here but, here’s a new programming language, called Roc Reminds me a bit of Elm and thus Haskell. ...
New
First poster: joeb
The File System Access API with Origin Private File System. WebKit supports new API that makes it possible for web apps to create, open,...
New
AstonJ
Was just curious to see if any were around, found this one: I got 51/100: Not sure if it was meant to buy I am sure at times the b...
New
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
New

Latest in PragProg

View all threads ❯