small medium large xlarge

05 Apr 2012, 10:21
Umesh Telang (1 post)

Apologies if this is too detailed a question to be asking, but I’ve been getting all the code examples to work until this point (section 6.6 reify).

When I load the src/examples/midi.clj into a repl (I’m using Emacs) and then attempt to load src/examples/generator.clj, I get the error at the bottom of this post. I can see key-number declared in the MidiNote protocol definition in midi.clj, and the equivalent “reification” in generator.cj seems to match in name and argument signature (if that’s relevant…).

If someone can point in the general direction as to where I’m going wrong… or how to look for a resolution, that would be much appreciated!

Thanks, Umesh


Unable to resolve symbol: key-number in this context [Thrown class java.lang.RuntimeException]

Restarts: 0: [QUIT] Quit to the SLIME top level

Backtrace: 0: clojure.lang.Util.runtimeException 1: clojure.lang.Compiler.resolveIn 2: clojure.lang.Compiler.resolve 3: clojure.lang.Compiler.analyzeSymbol 4: clojure.lang.Compiler.analyze 5: clojure.lang.Compiler.analyze 6: clojure.lang.Compiler$InvokeExpr.parse 7: clojure.lang.Compiler.analyzeSeq 8: clojure.lang.Compiler.analyze 9: clojure.lang.Compiler.analyze –more–

08 Jun 2013, 08:23
Suresh Iyer (6 posts)

I got the same error message, and since Google search for the error message had only this page, decided to spend some time understanding the error message. Since it said “cannot resolve symbol”, I thought that perhaps inside a reify, if we want to access any other method, we need to use the dot operator (“object.method” in C based languages). So made the following changes and it worked!.

  (.noteOn midi-channel (.key-number this) velocity) ; 1
  (Thread/sleep (.to-msec this tempo)))))]           ; 2
  (examples.midi/perform (repeat 15 rand-note)))     ; 3

1 - key-number to “.key-number” 2 - to-msec to “.to-msec” 3 - perform to “examples.midi/perform” (namespace scoped call)

Now I am not sure why you need the dot notation inside reify when the same is not required in extend-record calls in the previous section(s). Hope someone else can explain that.

Hope this helps. Thanks.