2

People, I decided to rewrite this post entirely to show it in a clear way.

First of all, thanks for all the support. I appreciate that.

This is the exercise in "The Clojure Workshop - Packt" where i've got stuck:

(My IDE is IntelliJ and i'm using Windows).

Exercise 4.10: Importing Data from a CSV File

1. Create a folder somewhere convenient on your computer.

I decided to create an entirely new project.

Is there any difference here while choosing between Leiningen or Deps? I most of the time use Leiningen, but should i use Deps because i am gonna use a deps.edn file?

2. Download the match_scores_1991-2016_UNINDEXED.csv file to the folder you created. (here on github)

But where should i download this file? Into the src file inside the project file or any file works? Is there any difference?

I decided to save inside de src.

3. In your editor, in the same folder, create a deps.edn file with the following contents:

{:deps
 {org.clojure/data.csv {:mvn/version "0.1.4"}
  semantic-csv {:mvn/version "0.2.1-alpha1"}}}

So, i created a deps.edn file.

4. Verify that everything is working by evaluating the following expression in your REPL:

user> (require '[clojure.data.csv :as csv])
nil
user> (require '[clojure.java.io :as io])
nil
user> (with-open [r (io/reader "match_scores_1991-2016_unindexed_csv.csv")]
         (first (csv/read-csv r)))

Created a new local Clojure REPL for this project.

But when i am gonna evaluate the testing expressions, it shows an error while evaluating the second one and third one.

As you can see here.

The error while evaluating the "clojure.data.csv :as csv" is this one:

Execution error (FileNotFoundException) at csv-example.core/eval1549 (form-init2604783929697477049.clj:1).
Could not locate clojure/data/csv__init.class, clojure/data/csv.clj or clojure/data/csv.cljc on classpath.

What am i missing? Have been trying for days to solve this but i didn't found any answer.

Thank you!

  • 1
    It's hard to tell what you're having problems with. Step 3 could be done with any editor. deps.edn is a text file. Can you explain what you've tried and what doesn't seem to work? – Sean Corfield Jan 02 '21 at 21:27
  • Sean, I cant understand those things: "In your editor" (Inside INTELIJ? In the REPL?) "In the same folder" (But the folder is in the desktop, should i transfer it to src folder inside the IJ?) "create a deps.edn file" (again, where? what is he referring by "editor"? IJ, Windows PowerShell, or a txt file? Sorry for the noob question @sean. I'am beggining with clojure and programming. – Claudio Ferreira Jan 02 '21 at 21:55
  • Have you created an IntelliJ project? If so you can go to the project view, right-click on the top-level folder and goto `New -> File` and create a `deps.edn` file. `deps.edn` should be at the top level of the project folder. – Lee Jan 02 '21 at 22:26
  • 2
    The book you are following may assume more of a programming background, such that other obstacles may follow after this one; a difficult and dispiriting path overall. A csv file as a first exercise is a very steep start! Would you consider another guide to get started with? As an example of a great, readable, interesting intro, I would nominate "Think Python: how to think like a computer scientist". Of course, if you find one for Clojure, so much the better; but my favorite, "Clojure for the brave and true", assumes familiarity with the matter of editors, files, folders. – Biped Phill Jan 02 '21 at 23:23
  • Just to be clear here: the instructions want you to create a new folder (anywhere). E.g. create `ex410`. Then add a new `deps.edn` file in there (if in doubt add it using your regular editor and not intellij, since it wants to open project roots and is not a great general purpose editor) with the content from the instructions. Then open the directory from intellij. It should detect a clojure project, IF you have a plugin installed (e.g. cursive). – cfrick Jan 02 '21 at 23:36
  • As Biped Phil indicates, if you're not familiar with that level of terminology around files, folders, and editors, you're going to really struggle trying to learn Clojure as all of the material really assumes you have some background in programming. Finding a really basic introduction to Python instead might be a better place to start. – Sean Corfield Jan 03 '21 at 19:36
  • Thanks for all the support @SeanCorfield, i really appreciate that. I decided to rewrite the intire post to show it in a clear way. If anyone could give any light i would be very thankful. Again, thanks all. – Claudio Ferreira Jan 04 '21 at 20:10

2 Answers2

2

I'll try to answer all the questions here and get you to the next stage:

  1. Leiningen uses a project.clj file. The Clojure CLI uses a deps.edn file. Since the book is asking you to create a deps.edn file, you'll need to use the Clojure CLI, not Leiningen, to start a REPL and/or run the code. More on this below.

  2. The book expects you to download the .csv file to whichever folder you created in step 1. The folder that contains your deps.edn file. Looking at your screenshots, it looks like you asked Cursive/IntelliJ to create a Leiningen-based project. If you start again and ask Cursive/IntelliJ to create a Deps-based project, you'll have a deps.edn file at the top of the project, which you can edit to look like what the book wants, and you'll end up with:

  • deps.edn
  • match_scores_1991-2016_unindexed.csv
  • src

(and maybe some other files that Cursive/IJ might create)

  1. Per my comments in 2. above, you'll have a deps.edn file -- created by Cursive/IJ -- that you can edit, in the top of the project.

  2. The error you got was because you created a Leiningen project, and then started a Leiningen REPL -- and it doesn't know about deps.edn so it won't see what you added there (even if you'd put it in the top of the project, next to project.clj). So Leiningen didn't know you wanted the CSV library and therefore it wasn't available in the REPL when you tried to require it -- and because the require failed, you didn't get the csv alias and so the call to csv/read-csv failed to compile.

Two points about the Clojure CLI:

a. It's substantially simpler to use than Leiningen and requires much less structure in a project. You could create a Deps-based project manually at the command line. Open a Command Prompt (cmd.exe) and you can do the following:

C:\Users\seanc>mkdir myproject

C:\Users\seanc>cd myproject

C:\Users\seanc\myproject>notepad deps.edn

C:\Users\seanc\myproject>dir
 Volume in drive C is Local Disk
 Volume Serial Number is 4459-1FFE

 Directory of C:\Users\seanc\myproject

01/05/2021  02:24 PM    <DIR>          .
01/05/2021  02:24 PM    <DIR>          ..
01/05/2021  02:25 PM               101 deps.edn
               1 File(s)            101 bytes
               2 Dir(s)  158,998,511,616 bytes free

(then you could download the .csv file into myproject and then start the REPL the way the book probably shows you -- I expect it suggests you run the clj command in that folder)

b. And here's where you run into a problem: Windows is not very well-supported by a lot of tools and libraries in the Clojure world -- nearly all Clojure developers either use Macs or Linux. Even those who use Windows generally use WSL2 (on Windows 10) and a Linux flavor such as Ubuntu. Because that's easier than trying to work with the tools on Windows.

There is a prerelease version of the Clojure CLI available for Powershell on Windows: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows

As noted at the bottom of that page, it's easier to install Scoop and then use that to install the Clojure CLI. And then use Powershell instead of the Command Prompt.

I don't know how you feel about WSL2/Linux or Powershell -- since you're new to programming, I suspect that's all going to seem somewhat complex and rather daunting. What you might consider is abandoning "The Clojure Workshop" (Packt books are generally not very good anyway) and find either another book or an online tutorial that takes you through using Leiningen (preferably on Windows -- but that might be hard to find, since so few Clojurians use Windows) and to try to work through that material with Cursive/IJ.

Sean Corfield
  • 6,297
  • 22
  • 31
  • 1
    And you might also consider joining the Clojurians Slack where you can chat with other beginners and get advice in real-time, which will probably help you get going quicker: http://clojurians.net to self-signup, https://clojurians.slack.com to chat. – Sean Corfield Jan 05 '21 at 22:38
  • Thank you @SeanCorfield, I really do appreciate your effort on trying to help me! – Claudio Ferreira Jan 07 '21 at 10:45
2

You can solve the problem by doing what Sean Corfield commented on the post if you choose to use deps.edn.

Or, if you prefer leiningen you can solve that just by adding


[org.clojure/data.csv   "1.0.0"]
[semantic-csv           "0.2.1-alpha1"]

at the :dependencies key inside the project.clj file.

inside the project.clj file.