Clojure compile error - Unable to resolve symbol: this in this context - clojure

Just when I thought I had seen it all in Clojure errors I get one that is baffling. When compiling my .clj file using lein compile I'm getting this exception:
java.lang.RuntimeException: Unable to resolve symbol: this in this context, compiling:(medical_notes/read_notes.clj:135:26)
the line in the read_notes.clj file that it is pointing to (135) is simply
{:type :compute}
that's it. The word "this" does not appear anywhere in the file. That line is inside this function:
(defn m-compute
"Message sent to master to start the computation"
[]
{:type :compute})
Anyone have any idea what is confusing it?
UPDATE: after troubleshooting and trying different things I can at least say now that the line number reported with the error is totally wrong for sure. It always reports exactly the same line number (135:26) no matter what. Right now line 135 in the file is a blank line and it's still calling out that line as the problem.

Related

Trouble with sum.ml from Real World Ocaml

I'm currently working my way through Real World Ocaml and I got stuck running the OCaml "corebuild" compiled version of sum.ml:
$ ./sum.native
1
2
3
Uncaught exception:
(Invalid_argument "Float.of_string ")
Raised at file "pervasives.ml", line 31, characters 25-45
Called from file "sum.ml", line 7, characters 44-61
Called from file "sum.ml", line 10, characters 24-46
What am I doing wrong?
Thank you!
When I try to recreate your reported error, I don't see it. Things work fine and I get the answer of 6.0. Possibly I'm using a different version of Core.
Update
The problem occurs if you type an extra newline after the last number. Float.of_string fails when the input string is empty. I think that's what you're seeing because there is an empty line between the last number and the error report. If you type ^D to terminate the input, there's no empty line.

Python - Unexpected EOF while parsing

I am using REPL.it to run Python for my homework. When typing in and running this line of code:
# print "This will not run"
I get an unexpected EOF error:
Traceback (most recent call last):
File "python", line 1
# print "This will not run"
^
SyntaxError: unexpected EOF while parsing
This is an issue with REPL.it, not with Python. I am not sure what the internals of that interpreter are, but it appears that REPL.it will not allow a comment as the first line of code if there is no other code. To illustrate, try the following:
foo = 1
# print "This will not run"
The interpreter should spit out None instead of raising an error. It seems that it also works to have a comment on the first line and an empty line (or a line with code) as the second line, but running a file in this app that consists of only a single comment line does not seem to work.
If you have access to Python on your computer (which you do by default if you are on Mac OSX or Linux), then I would suggest trying your examples in a real Python interpreter. Otherwise, you might see some unexpected results, as I assume that repl.it is not a full-featured interpreter (as indicated by the syntax error).
It means Python is surprised that that the code ended without being finished. For your example, you didn't write any code, just a comment, without a blank line on the bottom?
Try print "This will not run" if that's the ONLY line of code in your file.
The python-interpreter is looking for code it shall execute but finds none, as the line you try to run is uncommented (by the # in the beginning).
Because it found no code to evaluate it makes some noise.
Remove the # and it will work...

Tensorflow sess.run() returns nothing

I've been running a program located here:
https://github.com/dennybritz/cnn-text-classification-tf
and the base code works fine with the posted example. But, I tried to split new data into a train/test split and then it gives me errors. The program trains on the train data I give it, but come evaluation time I get this error:
Traceback (most recent call last):
File "./eval.py", line 81, in correct_predictions = float(sum(all_predictions == y_test))
TypeError: 'bool' object is not iterable`
From the eval.py code I located where the problem is in this loop:
for x_test_batch in batches:
batch_predictions = sess.run(predictions, {input_x: x_test_batch, dropout_keep_prob: 1.0})
all_predictions = np.concatenate([all_predictions, batch_predictions])
Wherein sess.run returns nothing and batch_predictions becomes an empty array, leading to a value error later on. Also of note:
batch_predictions is always empty.
x_test_batch is non-empty for every batch.
all_predictions is also always empty.
I brought up the issue with the github owner but he recommended I trace through execution. This is my first time using Tensorflow and I am unable to access their website. If anyone can
Tell me what my issue is
or
Tell me how to trace through the graph execution to find it
I would be endlessly appreciative. Thank you to anyone who reads this!
you say sess.run does not return anything, perhaps you could print x_test_batch before running sess.run and look whats inside, perhaps its empty, which is not your intention i think

Clojure (load-file) gives an error

Whenever I try to use (load-file) on my home computer (OSX) it throws the following error:
IllegalArgumentException Parameter declaration comp should be a vector clojure.core/assert-valid-fdecl (core.clj:6732)
When I load the same file on my Windows box at work it works. What is the difference between (load-file "C:\clojure\pc-3.clj") and (load-file "/Users/myname/clojure/pc-3.clj") that is throwing the error. Other than the path structure with the slashes is different but I don't understand why this is not working on my both systems.
BTW: Other than OS both systems are running JRE 1.7_025 with clojure-1.5.1.
UPDATE:
I was asked for a stack trace and I'm not sure how to do this just started working with Clojure. But emacs nrepl-error buffer listed this out for me:
java.lang.ClassCastException: clojure.lang.PersistentVector cannot be cast to java.lang.String
RT.java:318 clojure.lang.RT$3.invoke
NO_SOURCE_FILE:1 user/eval278
Compiler.java:6619 clojure.lang.Compiler.eval
Compiler.java:6582 clojure.lang.Compiler.eval
core.clj:2852 clojure.core/eval
main.clj:259 clojure.main/repl[fn]
main.clj:259 clojure.main/repl[fn]
main.clj:277 clojure.main/repl[fn]
main.clj:277 clojure.main/repl
RestFn.java:1096 clojure.lang.RestFn.invoke
interruptible_eval.clj:56 clojure.tools.nrepl.middleware.interruptible-eval/evaluate[fn]
AFn.java:159 clojure.lang.AFn.applyToHelper
AFn.java:151 clojure.lang.AFn.applyTo
core.clj:617 clojure.core/apply
core.clj:1788 clojure.core/with-bindings*
RestFn.java:425 clojure.lang.RestFn.invoke
interruptible_eval.clj:41 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj:171 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval[fn]
core.clj:2330 clojure.core/comp[fn]
interruptible_eval.clj:138 clojure.tools.nrepl.middleware.interruptible-eval/run-next[fn]
AFn.java:24 clojure.lang.AFn.run
ThreadPoolExecutor.java:1145 java.util.concurrent.ThreadPoolExecutor.runWorker
ThreadPoolExecutor.java:615 java.util.concurrent.ThreadPoolExecutor$Worker.run
Thread.java:724 java.lang.Thread.run
UPDATE: Found out what the problem was today. I was having the exact same problem with my Windows box turns out that the original answer was correct but my assumption that it had to do with (load-file) was incorrect. The file I was loading had a function that was not using a vector [] as part of the function itself. Clojure was doing the correct thing (but I totally forgot about this) when loading the file checking the syntax to make sure that everything was complete in the file. My function wasn't so it wouldn't load the file. I forget that LISPs do this and that it's a feature not a bug (reason why I like LISPs).
I'm new to clojure but not to LISPs and I should have realized this. The file is my study file. All the examples I retype from the REPL why studying and the reload the file with the newest to make sure I typed it in correct. It appears that when I added the newest function to file I retyped it incorrect and didn't reload the file to check it. When I went away and closed down the REPL and then came back after dinner and tried to reload the file it wouldn't load.
So sorry for being a waste of time. But thanks for the help, and quickly too. The original answer was correct I just forgot to recheck all the functions in the file.
That error indicates that the compiler was processing something like
(defn function-name comp (do-stuff ...))
or perhaps
(defn [arg1] comp (do-stuff ...))
instead of
(defn function-name [comp] (do-stuff ...))
load-file takes a string not a vector (load-file "path/to/file.clj)
Could it be that the code is not the same on the two systems?
Could there be a difference in path interpretation / vs \ causing something else to get loaded?

Opening SML file - use fail

I opened a file in "SML of New Jersey" with the following command: use "c:\\work.sml", and it gives me the next problem:
[openning c:\\work5.sml]
[use failed: Io: openln failed on "c:\\work.sml", Win32TextPrimIO:openRd: failed]
uncaught Exception error
raised at:../complier/TopLevel/interact.sml:24.14-24.28
In work.sml, I have just this one line:
- datatype ’a seq = Nil | Cons of ’a * (unit -> ’a seq);
Your file contains two errors:
The - at the beginning of the line needs to be removed.
The ’s should be 's.
However these should cause a syntax error and a bunch of "illegal token" errors respectively, not an IO error.
The only reason I can think of that you get the error you do is that you mistyped the file name.
I suddenly started experiencing this problem as well after I pinned the shortcut to SML New Jersey to my task bar. If I ran SML from this shortcut and tried to "use" a .sml file it would give this error.
So basically make sure your SML.exe is in the same folder as your .sml programs and this should work fine again.