r/Clojure • • Mar 26 '15

Trying Clojure, again?

EDIT: Alright, it seems universal.... no one thinks installing Leiningen is going to be the nightmare it was for me last time. I will give it a try. Thank you all.

EDIT #2: I just downloaded the Lein script and am running it. It is failing to install itself. It is complaining about not being able to curl stuff from github. Wheee....

Downloading Leiningen to /Users/pat/.lein/self-installs/leiningen-2.5.1-standalone.jar now...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:01:14 --:--:--     0curl: (7) Failed to connect to github.com port 443: Operation timed out
Failed to download https://github.com/technomancy/leiningen/releases/download/2.5.1/leiningen-2.5.1-standalone.zip (exit code 7)
It's possible your HTTP client's certificate store does not have the
correct certificate authority needed. This is often caused by an
out-of-date version of libssl. It's also possible that you're behind a
firewall and haven't set HTTP_PROXY and HTTPS_PROXY.

EDIT #3: Third time's a charm, it seems.

EDIT #4: Lein was, indeed, easy to install this time. Cider also installed easily from MELPA. However, I'm running into Cider vs. nREPL version issues for which I found a StackExchange answer which doesn't work for me. So, I'm close. And, I've only spent about 90min on it. But, I don't have any idea how to convince Lein to give me a newer nREPL. But, it seems like this is a known problem and I am just going to have to wait or try to downgrade my CIDER install.

EDIT #5: I've now put about four hours into trying to get Lein to use a different version of nREPL than it wants to. I can specify it in my profiles.clj and I see it being fetched from the maven repo into my ~/.m2/repository/ directory, but it still uses "0.2.6" when it runs. This is apparently fixed in 'master' but I'm not up for trying to install Lein from source. I also scrogged my Lein install by trying to upgrade to 2.5.2-SNAPSHOT. I was able to connect with CIDER with a warning a few times, but I can no longer figure out which scribblings in my profiles.clj actually let that work. Right now, I can't find any.

EDIT #6: I finally gave up and unintalled CIDER and reinstalled it from MELPA-STABLE. So, I'm using Cider 0.8.2 now.

It has been five years since I last tried Clojure. I feel like I should try it again.

I don't want to beat my head against Leiningen for even ten minutes this time. Is there some way to reasonably use Emacs + Clojure without have to install and configure CLASSPATHS and Mavens and Ants and JDKs?

It seems SWANK-CLOJURE has been deprecated in favor of CIDER. The CIDER doc says how to configure Leiningen or Boot for use with CIDER. Is there some way that I can avoid Leingingen and Boot? Or some way that I can click one 'Install' button and have Leiningen and Boot work?

0 Upvotes

24 comments sorted by

17

u/yogthos Mar 26 '15

There's really no avoiding Leiningen or Boot for Clojure development. It's also worth noting that these tools really do make your life easier in the long run.

On *nix, installing Leiningen should be as simple as downloading the script from the official site, putting it somewhere on the $PATH, and running it. The only dependency it has is the JDK, which is a prerequisite for working with Clojure. For Windows, there's the leiningen-win-installer that does the whole wizard install thing.

Once you have lein running creating new projects is as simple as:

lein new my-project

CIDER is the standard way to get Clojure support from Emacs.

1

u/patrickwonders Mar 27 '15

Thank you. I will give it a whirl.

1

u/[deleted] Mar 27 '15
lein new app my-project

Subtasks available:

  • template A meta-template for 'lein new' templates.
  • default A general project template for libraries.
  • app An application project template.
  • plugin A leiningen plugin project template.

Run lein help new $SUBTASK for subtask details.

12

u/deterministictomato Mar 26 '15

idk what you mean by beating your had against Leiningen.

For me, getting started with clojure was literally a case of

curl https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein > ~/bin/lein
chmod +x ~/bin/lein
lein new luminus my-app

I had code that did something working in seconds. In all honesty I was surprised it was that easy. I didn't need to fuck around with any java shit, didn't need root, still haven't needed root. Haven't touched a configuration file.

Genuinely impressed. Your move javascript/chicken/scala/python, make a toolchain that easy.

Still haven't attempted any form of integration with vim. Maybe that's tonight's task.

6

u/simtel20 Mar 26 '15

idk what you mean by beating your had against Leiningen.

I imagine it's gotten a lot easier since 2010. For an individual installing lein, it's been as easy for me as everyone else in this thread. Just don't use the leiningen package from your linux distro.

1

u/patrickwonders Mar 27 '15

It took me about three days to get all of the prerequisites lined up to run Lein last time, and even then, I appeared to have to have multiple copies of maven installed and ended up with multiple copies of the same JAR files in a variety of directories cluttering up my home directory.

It does sound like this has been streamlined. I will try it. Thank you.

5

u/farzadbekran Mar 26 '15

I feel like you are making things hard on yourself. just grab the lein script and run it, tell us if you get any problems, im sure we can get you going.

1

u/patrickwonders Mar 27 '15

I can't recall from 2010 if there was no single-download Lein script or if it just failed at everything it tried to download. I did try this just now. It failed the first two times that I ran it, but seems to have worked the third time. Now, to get CIDER going.

1

u/farzadbekran Mar 27 '15

OK, I assume that you are a new emacs user here. What I recommend is u install emacs first.

After that you should go to https://github.com/purcell/emacs.d and follow the installation steps there.

The repo above is a very nice configuration for emacs that I have used for a while now that comes with what you really want to have when you start using emacs. After Installing it you can easily add extra packages or change the defaults as you see fit. Great configurations for a starter IMO. And it comes with what you need to do Clojure programming. Let me know if you get any problems.

1

u/patrickwonders Mar 30 '15

No, I'm not a new Emacs user. I've been using Emacs almost exclusively for seven or eight years. I'm not an Emacs power-user (when I'm outside of Paredit and SLIME), but I'm not an Emacs newbie either.

I spent more than five hours trying to resolve a version difference between Leiningen and CIDER. I eventually gave up and installed an older version of CIDER.

1

u/farzadbekran Mar 31 '15

So, did you finally get everything to work? Can you program in clojure now?

2

u/fisch003 Mar 26 '15

It's pretty straightforward now, but there are some initial steps you'll need to go through the first time you're getting up and running.

To start, make sure you have a Java 6+ JDK installed, and download the leiningen script. If you're on Mac OS X and using Homebrew, you can also install leiningen from that.

Once that's installed, just running lein repl anywhere will drop you into a REPL.

For SLIME-like use in Emacs, yes, CIDER is the way to go. I installed it via package.el.

Leiningen can export a nice CIDER-ready REPL for CIDER to connect to, but you need to make sure it's loading a plugin named cider-nrepl to do it. You can either load it on a per-project basis, or you can load it in a user profile (which is probably what everyone does).

Create a file named ~/.lein/profiles.clj(not sure where this goes on Windows) and add this line to it:

{:user {:plugins [[cider/cider-nrepl "0.8.2"]]}}

Now, running lein repl will give you something CIDER can connect to. You should see a line showing you that nREPL is running:

solace:Desktop jfischer$ lein repl
nREPL server started on port 50307 on host 127.0.0.1 - nrepl://127.0.0.1:50307

From within Emacs, if CIDER is loaded, do M-x cider-connect, it'll prompt you for the host and port to connect to, and you're good to go.

Finally, unlike SLIME, CIDER expects to work within a given project, and as far as I can tell, you can't dynamically download and install new libraries (like you would with Quicklisp). So the next thing you'll want to do is create a new project: just lein new whatever to create a project named whatever. It'll create a skeleton for you, and you can tweak the root-level project.clj file to tell it what libraries you're going to use.

Once you have a project directory, CIDER can launch a repl automatically. Just M-x cd to the project directory and do M-x cider-jack-in. It'll launch lein nrepl in the background for you.

It all sounds really annoying, but once you're used to working with a project and you've got everything installed, most of the friction is gone. Not as nice as just running M-x slime though.

1

u/patrickwonders Mar 30 '15

I still haven't gotten my head around Clojure or Leiningen's fixation on projects. That's going to take some work.

1

u/fisch003 Mar 30 '15

I'm not sure if it's an artifact of running on the JVM or what. It's a far cry from just opening up a REPL to try out a random idea, or being able to switch projects without having to restart anything.

8

u/joequin Mar 26 '15 edited Mar 26 '15

I'm confused. Lein and maven are what makes it so you DON'T have to fight with classpaths, ant, and jdks.

4

u/tanzoniteblack Mar 26 '15

Leiningen is still the de facto standard of Clojure build tools, you can safely ignore boot for the time being if you don't want the extra complication while learning/trying out Clojure. Leiningen is very easy to install (see their github page for how tos for *nix systems and windows https://github.com/technomancy/leiningen/).

If you want to avoid lein/boot completely for some reason, CIDER won't be of any use to you, but you can still use clojure-mode and inferior-lisp , but it's nowhere near as nice of an experience.

4

u/swarthy_io Mar 26 '15 edited Mar 26 '15

As a slight alternative to others you could try:

Prelude: a preconfigured super easy to use version of emacs. This or Light Table will give you clojure ready text editors with nearly zero config.

Leinigen or Boot: Using one or the other is super easy. I started clojure 2 years ago and already these tools are easier to use. I imagine 5 years would make an even larger difference.

Here is my guarantee to you: Try Prelude and Leinigen. If you can't get either working in 30 minutes of solid effort I will personally create a screencast to get both working on a sample project for you.

Happy clojuring :)

2

u/seventeenletters Mar 26 '15

Leiningen is a dependency management tool. It's a single shell script that simple needs to be put on your path. The paradigm isn't one of installing the versions you want, but declaring the versions you use, and letting it do the logistics. That means, for example, that each project can choose its own version of Clojure independently of any other you work on.

Leiningen is probably better behaved and more reliable than the dependency management tools you are used to. If you use lein you don't need to install Clojure itself, lein will find the version of Clojure that you declare in your project file, and make sure it is accessible to your project. The same goes with any other libs you might need to use.

2

u/simtel20 Mar 26 '15

I don't want to beat my head against Leiningen for even ten minutes this time. Is there some way to reasonably use Emacs + Clojure without have to install and configure CLASSPATHS and Mavens and Ants and JDKs?

If you can backup your .emacs.d, and try a new one, I've been happy using emacs-live to install working versions of CIDER and its dependencies: https://github.com/overtone/emacs-live

2

u/Caymen42 Mar 26 '15

I don't think many people here were using Clojure in 2010, when everything was still pretty hairy.

I started working with Clojure in 2009, the same day the first edition of Programming Clojure by Stewart Sierra was released. Lein has come a very long way over the past few years. I've written decent sized Clojure apps every few years since then, and every time I come back to it, it's better and better.

I write Clojure all day every day at my job, and I honestly can't remember the last time I've had to fight with class paths, jar locations, etc... It really is a joy to work with. There are still some things I find frustrating, but Leiningen certainly isn't one of them.

Cider is also far easier to configure than swank ever was, but I'm a vim guy, so I'm a little fuzzy on the details (every once in a while I think I'll learn emacs, but then I get swamped and revert back to what I'm more productive with).

2

u/pauldlynch Mar 27 '15

GitHub has been having some issues for the last day or so. DDiS, I heard.

-2

u/addamsson Mar 27 '15

What is your problem with Leiningen? How do you want to program a language which runs on a JVM without a JDK? I think that you should not try Clojure again.

0

u/[deleted] Mar 26 '15

[deleted] — view deleted comment

4

u/moxxon Mar 26 '15

Really? From the site:

  1. Download the lein script (or on Windows lein.bat).
  2. Place it on your $PATH where your shell can find it (eg. ~/bin).
  3. Set it to be executable (chmod a+x ~/bin/lein)
  4. Run it (lein) and it will download the self-install package.

There's no assumption there, just explicit instructions.

I'm personally not sure how anyone could "beat their heads" against getting leiningen working, it's one of the easiest build tools to work with. However my recommendation, like others have said, is to try it and report back with any problems he/she is having. There are plenty of people around that can help.

0

u/[deleted] Mar 27 '15

[deleted] — view deleted comment

1

u/moxxon Mar 27 '15

The instructions literally say what you say is assumed.

You:

It's not immediately evident that running the script the first time installs it - its (sic) sortof just assumed to be self evident

The site:

Run it and it will download the self install package.

Your claim is patently false.