0
votes

First I have to say, I'm completely new to clojure, so forgive me if I'm missing something obvious. I recently installed the clojure package on the atom text editor in order to create some graphs and tried to add ubergraph, an extension that makes weighted graphs possible, since these are not supported in the standard clojure package.

I followed the quickstart guide on ubergraphs github https://github.com/Engelberg/ubergraph and managed to complete the first step (adding ubergraph to leiningen dependencies). I downloaded the git repository and don't know how to carry on from here. Running the example code

(ns example.core
  (:require [ubergraph.core :as uber]))

(def graph1
  (uber/graph [:a :b] [:a :c] [:b :d]))

on the repl as described on github ends up with the following error:

CompilerException java.lang.NullPointerException, compiling:(ubergraph/core.clj:11:1)

The line that seems to cause the error in core.clj is:

(import-vars
 [...])

I skipped over the vars since I don't think they're causing the problem. Clojure runs on the correct version (1.9.0) and java 8 is installed. Help is appreciated, thanks in advance.

1
I just installed the library, created a fresh namespace, pasted the code you have above in, and it worked. It works for both 1.9.0 and 1.10.0 for me. Try running lein clean. - Carcigenicate
Tried it out, didn't work. Still returns the same error. Could you post the code you used to create the namespace? Also, do I have to put the lib somewhere specific? I might be doing something wrong there. Thanks. - Heathcliff
I also tried running it 1.10.0, and got pretty much the same thing: (ns example.core (:require [ubergraph.core :as uber])) Unexpected error (NullPointerException) macroexpanding potemkin.namespaces/import-def at (core.clj:11:1) - Heathcliff
Running the example code on the repl - which command are you using? - nha
It's described right below, the one trying to create the namespace. - Heathcliff

1 Answers

0
votes

Based on your comment "Also, do I have to put the lib somewhere specific?", this seems to caused by a misunderstanding of how to install a library. You shouldn't be manually dealing with stuff like that; leiningen handles library installation for you.

Here's a quick guide that assumes you haven't created a project yet. If you have, skip to step 2.

  1. Run lein new app you-project-name-here. This will create a barebones project with a project.clj and basic file structure. If you use an IDE like IntelliJ+Cursive, creating a new project will do this step automatically.

  2. Go into your project.clj, and add [ubergraph "0.5.2"] to the :dependencies entry. As a minimal, reduced example, it should look something like:

    (defproject example "0.1.0-SNAPSHOT"
        :dependencies [[org.clojure/clojure "1.10.0"]
                       [ubergraph "0.5.2"]]
    
        :main example.core) ; The path to your core
    
  3. Have your core as something like:

    (ns example.core
      (:require [ubergraph.core :as uber])
      (:gen-class))
    
    (def graph1
      (uber/graph [:a :b] [:a :c] [:b :d]))
    
    (defn -main
      "I don't do a whole lot ... yet."
      [& args]
      (println "The graph:" graph1))
    
  4. Now run lein run. You should see it download the dependencies, then print something like this mess:

    The graph: {:node-map {:a #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :c #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :out-degree 2, :in-degree 2}, :b #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :b, :dest :a, :mirror? true}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "0768ef5b-1507-4bb0-b3da-fc14a84d013d", :src :a, :dest :b, :mirror? false}}, :d #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :out-degree 2, :in-degree 2}, :c #ubergraph.core.NodeInfo{:out-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :c, :dest :a, :mirror? true}}}, :in-edges {:a #{#ubergraph.core.UndirectedEdge{:id #uuid "acddd770-52cc-4b1f-aec1-762861e70ee2", :src :a, :dest :c, :mirror? false}}}, :out-degree 1, :in-degree 1}, :d #ubergraph.core.NodeInfo{:out-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :d, :dest :b, :mirror? true}}}, :in-edges {:b #{#ubergraph.core.UndirectedEdge{:id #uuid "ef931d4e-8143-4cd1-8a10-c3692c47072f", :src :b, :dest :d, :mirror? false}}}, :out-degree 1, :in-degree 1}}, :allow-parallel? false, :undirected? true, :attrs {}, :cached-hash #object[clojure.lang.Atom 0x16da1abc {:status :ready, :val -1}]}
    

I suspect the NPE was because you had installed ubergraph somehow, but didn't allow it to automatically resolve its dependencies. When it tried to run import-vals, one of the libraries it depends on wasn't found, and it threw a fit.