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

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
jamis
The following is cross-posted from the original Ray Tracer Challenge forum, from a post by garfieldnate. I’m cross-posting it so that the...
New
JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
New
New
AndyDavis3416
@noelrappin Running the webpack dev server, I receive the following warning: ERROR in tsconfig.json TS18003: No inputs were found in c...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
jskubick
I’m running Android Studio “Arctic Fox” 2020.3.1 Patch 2, and I’m embarrassed to admit that I only made it to page 8 before running into ...
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
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
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New

Other popular topics Top

Devtalk
Reading something? Working on something? Planning something? Changing jobs even!? If you’re up for sharing, please let us know what you’...
1030 17300 381
New
AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
New
brentjanderson
Bought the Moonlander mechanical keyboard. Cherry Brown MX switches. Arms and wrists have been hurting enough that it’s time I did someth...
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
PragmaticBookshelf
“Finding the Boundaries” Hero’s Journey with Noel Rappin @noelrappin Even when you’re ultimately right about what the future ho...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
gagan7995
API 4 Path: /user/following/ Method: GET Description: Returns the list of all names of people whom the user follows Response [ { ...
New
foxtrottwist
A few weeks ago I started using Warp a terminal written in rust. Though in it’s current state of development there are a few caveats (tab...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
First poster: bot
The overengineered Solution to my Pigeon Problem. TL;DR: I built a wifi-equipped water gun to shoot the pigeons on my balcony, controlle...
New

Sub Categories: