Fork me on GitHub
#beginners
<
2017-08-05
>
bschrag00:08:07

Re "adding dependency to project," should there be something(s) for norsys in the :require clause?

noisesmith00:08:19

also, you can eliminate some uncertainty by just working in a normal repl without emacs until you can verify you can find the classes you expect to

bschrag00:08:40

All I have in defproject is the path thing now.

noisesmith00:08:49

no, you don’t require java classes, they are auto-loaded when referenced if found on the classpath

noisesmith00:08:07

the path thing?

bschrag00:08:36

:java-source-paths

noisesmith00:08:39

oh, it’s source, it’s not a jar you are using

noisesmith00:08:59

try running lein javac before starting a repl

bschrag00:08:02

No, it is a JAR. That's what's wrong?

noisesmith00:08:11

I forget if starting a repl fixes that automatically…

noisesmith00:08:21

source-paths is for things that are source code to compile

noisesmith00:08:35

if it’s a jar, you need to add it to the classpath directly

bschrag00:08:23

Different keyword to defproject? Or where does the classpath live?

noisesmith00:08:38

the recommended thing with jars is to have a maven coordinate, then add to :dependencies

noisesmith00:08:56

but you can also add a jar to eg. :resource-paths I guess…

bschrag00:08:37

I'll try that last (sounds easier for the moment).

noisesmith00:08:42

the advantage to using via maven is that anyone who checks out your source code can automatically get your deps

bschrag00:08:06

That sound good---so I'll have to learn about it.

noisesmith00:08:06

if that dir has a pom.xml near the jar, it should be possible to at least install it to your dep cache locally

noisesmith00:08:34

with mvn clean install at the top level probably

bschrag00:08:08

:resource-paths mod fails the same way (on REPL restart).

noisesmith00:08:39

you put the jar itself on the path

noisesmith00:08:44

not just the dir the jar is in

noisesmith00:08:38

this is a bit of a hack though, :resource-paths is meant to indicate directories for static resources used at runtim (which a jar of classes technically is, but…)

noisesmith00:08:01

lein doesn’t have a “just put this in classpath” directly, probably because they’d just say “don’t do it that way”

noisesmith00:08:08

use maven, etc. etc.

bschrag00:08:35

I will learn.

bschrag00:08:47

This looks better...

bschrag00:08:55

edit-server.core> Environ
CompilerException java.lang.RuntimeException: Unable to resolve symbol: Environ in this context, compiling:(*cider-repl edit-server*:1:7209) 
edit-server.core> norsys.netica.Environ
norsys.netica.Environ
edit-server.core> 

bschrag00:08:45

Seems like I could get that much without importing, though. Import just affects compilation, not REPL?

noisesmith00:08:16

import is a convenience

noisesmith00:08:28

it works the same way in a file as the repl: it means you don’t need to type out the full name

noisesmith00:08:09

you can call (import (norsys.netica Environ)) in the repl and it works

noisesmith00:08:18

same thing the :import clause in ns does

bschrag00:08:23

But the latter doesn't affect the REPL?

noisesmith00:08:46

:import is part of the ns syntax

noisesmith00:08:55

it’s less often that you’d redefine your ns in the repl

bschrag00:08:13

Curious why this didn't seem to have effect?

bschrag00:08:22

(ns edit-server.core
  (:require [clojure.data.json :as json]
            [clojure.java.shell :only [sh]]
            [clojure.pprint :refer :all]
            [clojure.mathyes.numeric-tower :as math]
            )
  (:import [norsys.netica.Environ]
           []
           [norsys.netica.Node]
           [norsys.neticaEx.aliases.Node])
  (:gen-class))

noisesmith00:08:42

but in general everything that works in the file works in the repl, and visa-versa

noisesmith00:08:53

it’s odd that you’ve tried to import two things called Node

noisesmith00:08:58

I’d expect an error for that

bschrag00:08:38

Their demo Java code did the same.

bschrag00:08:53

That ran fine.

bschrag00:08:39

import norsys.netica.*;
import norsys.neticaEx.aliases.Node;

bschrag00:08:48

Maybe the second one prevails?

noisesmith00:08:00

that’s what I’d expect, for any clashes, yes

bschrag00:08:21

Ok, then seems like I can drop the first.

bschrag00:08:22

Not sure CLJ has all the Java info it needs yet...

bschrag00:08:33

edit-server.core> (norsys.netica.Environ. nil)
UnsatisfiedLinkError no NeticaJ in java.library.path  java.lang.ClassLoader.loadLibrary (ClassLoader.java:1867)

noisesmith00:08:57

so there’s another jar you forgot

noisesmith00:08:03

this is the thing that maven takes care of

noisesmith00:08:37

oh, it’s a so - a binary thing you need on the library path

bschrag00:08:52

Another? I have :resource-paths ["c:/NeticaJ_Win/NeticaJ_504/bin/NeticaJ.jar"] (NeticaJ)

noisesmith00:08:16

right, but that’s not the shared object - your OS can’t load it from inside a jar even if there is an so in there

noisesmith00:08:20

it’s a native code dep

bschrag00:08:52

bin include NeticaJ.dll, NeticaJ.lib.

noisesmith00:08:56

you need to add -Djava.library.path= to your :jvm-opts

noisesmith00:08:12

with the path to the dir that has those

bschrag00:08:39

edit-server.core> (norsys.netica.Environ. nil)
UnsatisfiedLinkError C:\NeticaJ_Win\NeticaJ_504\bin\NeticaJ.dll: Can't find dependent libraries  java.lang.ClassLoader$NativeLibrary.load (ClassLoader.java:-2)

bschrag00:08:42

:jvm-opts ["-Djava.library.path=c:/NeticaJ_Win/NeticaJ_504/bin"]

bschrag00:08:56

@noisesmith Thanks for all your help! I'll dig into this more soon. So long for now.

noisesmith01:08:31

you might need to escape that :

hmaurer12:08:08

Which editor would you people recommend for Clojure these days? Emacs+CIDER? Cursive? Other?

yonatanel13:08:51

I'm on Cursive and using Intellij for other languages as well. It's really good at renaming and supporting multiple coding styles. I need to learn a lighter editor though, for my clojure-only days. Check out Atom with proto-repl: https://github.com/jasongilman/proto-repl

dominicm13:08:04

@hmaurer Whatever you already use 🙂, Clojure plugins are good & widespread.

athomasoriginal15:08:18

I agree with dominicm, but I have to say that the balance of easy of use, and plugins like proto-repl, make Atom a great first choice.

athomasoriginal15:08:29

What is the difference between boot-reload and figwheel?

noisesmith15:08:21

does boot-reload provide a cljs repl?

noisesmith15:08:54

it might be that figwheel is more prepackaged / start up and go compared to how you would do it with boot

athomasoriginal15:08:12

Good point, There is a separate boot task for the cljs-repl called boot-cljs-repl

gonewest81816:08:16

@hmaurer - if emacs seems daunting, I would suggest the braveclojure tutorial covers just the right amount to get started with clojure. https://www.braveclojure.com/basic-emacs/

gonewest81816:08:12

@tkjone the modern-cljs tutorial does a pretty good job showing how to set up a cljs repl in boot, and actually, it layers in the boot steps incrementally and explains why.

athomasoriginal16:08:32

I am going through it right now.

athomasoriginal16:08:18

It does a fantastic job providing the overall context, but I am finding that there are some gaps when you want to build out your own project structure

athomasoriginal16:08:45

For me, the issue was understanding how boot is using the .cljs.edn files

hmaurer16:08:15

@gonewest818 thank you! that’s great, I’ll read through it

hmaurer16:08:52

Speaking of, I am having an issue trying to use CIDER’s debugger. I can’t seem to be able to configure it: getting “no reader function for tag break” error

hmaurer16:08:31

Ah I just realised there is a #cider channel; I’ll ask there

bschrag18:08:08

@noisesmith How to escape ":"? Tried "\:", got clojure.lang.Compiler$CompilerException: java.lang.RuntimeException: Unsupported escape character: \:, ...

noisesmith18:08:44

to use \ in a string you need \\

noisesmith18:08:29

since there's two layers of escaping now - the string escape so lein can read it, then the env var's escape so we can differentiate foo:bar from c:\\foo

noisesmith18:08:57

and now that I say all that I realize I should probably just look up how this is properly done...

noisesmith18:08:14

oh - you do this by using ; instead of : to separate items in the cp, OK

bschrag18:08:14

"the cp" ?

noisesmith18:08:30

the classpath

noisesmith18:08:56

where what I really meant was "definition of paths" because we aren't talking about a classpath here, we are talking about the library path

bschrag18:08:52

I think I have only one path item in this defproject clause: :jvm-opts ["-Djava.library.path=c\\:/NeticaJ_Win/NeticaJ_504/bin"].

bschrag19:08:20

Above gets me UnsatisfiedLinkError no NeticaJ in java.library.path java.lang.ClassLoader.loadLibrary (ClassLoader.java:1867) (again).

noisesmith19:08:50

is having the \\ before : actually correct?

bschrag19:08:50

c:\NeticaJ_Win\NeticaJ_504\bin>dir
dir
 Volume in drive C is OS
 Volume Serial Number is 0894-B1E2

 Directory of c:\NeticaJ_Win\NeticaJ_504\bin

08/03/2017  03:54 PM    <DIR>          .
08/03/2017  03:54 PM    <DIR>          ..
07/26/2017  09:18 AM         2,675,200 Netica.dll
07/26/2017  09:18 AM           105,472 NeticaJ.dll
07/26/2017  09:18 AM            89,017 NeticaJ.jar
07/26/2017  09:18 AM            74,640 NeticaJ.lib
08/03/2017  03:54 PM    <DIR>          x32_bin
08/03/2017  03:55 PM    <DIR>          x64_bin
               4 File(s)      2,944,329 bytes
               4 Dir(s)  51,155,099,648 bytes free

c:\NeticaJ_Win\NeticaJ_504\bin>

bschrag19:08:16

I don't know. You had suggested escaping the :, right?

bschrag19:08:27

I guess I could move Netica under the project, get away from using the absolute path.

bschrag19:08:51

It's just this project I'm using it in, now.

bschrag19:08:26

However, the following defproject clause seems to be working fine---so perhaps no escaping is really necessary. :resource-paths ["c:/NeticaJ_Win/NeticaJ_504/bin/NeticaJ.jar"]

noisesmith19:08:56

fair enough - I'm not as informed about windows

bschrag19:08:23

Seems like most folks run Linux. I'd planned to start that way but was really frustrated trying to install JDK on Ubuntu. Windows "just worked," so I've gone with that.