Fork me on GitHub
#beginners
<
2019-06-04
>
heath01:06:39

👋 I wanted to start playing with clojure and corda… I added

[net.corda/corda "4.0"]]
to project.clj and ran lein install from lein repl, I get this:
=> (require 'net.corda.core)
FileNotFoundException Could not locate net/ccorda/core__init.class or net/ccorda/core.clj on classpath.  clojure.lang.RT.load (RT.java:463)
are there any immediate gotchas I should be aware of? 🙂

alexmiller01:06:38

is that a Clojure thing or a Java thing?

markx01:06:39

@heath Looks like it’s a java lib? Try import instead of require.

lepistane05:06:23

hi guys quick question is there a way to https://github.com/clojure/tools.trace a macro?

jumar06:06:22

I doubt there is - with cider I'm getting Var #'... can't be traced because it's not bound to a function.

lepistane07:06:30

yeah makes sense thank you for checking it out

Danny Castonguay12:06:15

Hello. I have no problem running on Macos, but on Windows npx complains that 'clojure' is not found on system path. See screenshot. Any idea how to fix?

penryu19:06:39

I’d bet shadow-cljs is looking for clojure specifically. It might be as simple as copying CLJ.BAT to CLOJURE.BAT, but istr there’s some subtle difference between the two.

Danny Castonguay13:06:43

Thanks @UGPM7GTKJ! You were (partly) right. I'll have to investigate further if I find the time today but it's not quite working yet.

penryu19:06:16

On my system, clj is just an rlwrap’d clojure; and clojure is a pretty involved shell script that wraps a java clojure.main call. I’ve heard the Windows story is more complicated, and I no longer have any Windows machines to investigate. Sorry.

Ivan Koz12:06:34

May i ask why update-in implemented using local function up?

andy.fingerhut12:06:27

I am not the original author, so cannot answer why the original author chose that implementation of update-in, but I can make a guess. I suspect it may help with performance to do it that way, rather than making update-in recursive. update-in take a variable number of args using & args at the end of its arg list, but up does not.

Paulius Macernis14:06:47

Hi. I am wondering what pattern or language construction functional programming (including Clojure) uses in order to get the first successful result. Lets say I have functions A, B, C. Function A checks if function B or C returns the result not equal to 0 (for example). The important part - function A checks the returns of B and C in order. Which means function A returns B if B returns not 0. And functions A returns C if B returns 0. How do I solve such kind of problem in Clojure? 🙂

andy.fingerhut14:06:47

Do you want function A to return "the function B" if B returns a non-0 value? Or do you want function A to return "the value that function B returned"

andy.fingerhut14:06:46

If you meant "the function B", you could write A this way:

andy.fingerhut14:06:00

(defn A [x]
  (if (= (B x) 0)
    C
    B))

andy.fingerhut14:06:13

assuming that function B takes a single argument, here called x

Paulius Macernis15:06:14

@andy.fingerhut I am coming here from OOP world. I assume I would like to have the scenario "the value that function B returned", not "the function B". I am basically wondering if it is possible to overcome this problem without repeating the check twice in terms of memory (to not store the result of B) and CPU (to not run the B twice).

Ivan Koz15:06:28

why would you do that?

Ivan Koz15:06:44

just use conditional or reduced

andy.fingerhut15:06:48

Maybe something like this, then?

andy.fingerhut15:06:51

(defn A [x]
  (let [B-result (B x)]
    (if (not= B-result 0)
      B-result
      (C x))))

andy.fingerhut15:06:57

That stores the result of B, but I have a hard time imagining how you check whether the result of function B was 0 or not, without storing it somewhere, at least temporarily.

manutter5115:06:04

One common case is to have function B return nil to indicate “not the value you want,” then you can just do (defn a [x] (or (b x) (c x))

henrik13:06:08

@U9WPNPZE3 This is the best solution: adopt nil as return value. Note that you can keep stacking options in or; (or a b c d e f g…), and it'll return the first truthy alternative.

heath15:06:15

sorry to have asked then jetted yesterday. I added [net.corda/corda "4.0"] to the :dependencies in project.clj, and from the lein repl, when I do (import ’corda.core), I receive ClassNotFoundException corda.core java.net.URLClassLoader.findClass (URLClassLoader.java:382). Do I need to insert the import statement into its own module and then import that namespace instead of trying to play around with the library directly from the repl?

manutter5115:06:01

@heath Do you have a link to the corda docs?

Ivan Koz15:06:34

i dont think corda.core is a java class

Ivan Koz15:06:43

so use require instead

heath15:06:13

=> (require 'corda.core)

FileNotFoundException Could not locate corda/core__init.class or corda/core.clj on classpath.  clojure.lang.RT.load (RT.java:463)

Ivan Koz15:06:56

sorry its indeed a java lib

Ivan Koz15:06:14

but net.corda.core is a package not a class or namespace

Ivan Koz15:06:48

@heath just import any class from corda (not a package) and use it from repl

Ivan Koz15:06:48

you can see classes in javadoc

heath15:06:49

=> (import 'net.corda.client.jackson)

ClassNotFoundException net.corda.client.jackson  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

Ivan Koz15:06:08

jackson is also a package

heath15:06:16

=> (import 'net.corda.core.concurrent.JacksonSupport)

ClassNotFoundException net.corda.core.concurrent.JacksonSupport  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

manutter5115:06:31

But there is a JacksonSupport class in it.

heath15:06:36

=> (import 'net.corda.core.client.JacksonSupport)

ClassNotFoundException net.corda.core.client.JacksonSupport  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

manutter5115:06:59

net.corda.client.jackson.JacksonSupport I believe

manutter5115:06:15

You need the full package name as well as the class name

heath15:06:41

=> (import 'net.corda.core.client.jackson.JacksonSupport)

ClassNotFoundException net.corda.core.client.jackson.JacksonSupport  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

andy.fingerhut15:06:21

Try (import '(net.corda.core.client.jackson JacksonSupport)) I believe?

heath15:06:40

=> (import '(net.corda.core.client.jackson JacksonSupport))

ClassNotFoundException net.corda.core.client.jackson.JacksonSupport  java.net.URLClassLoader.findClass (URLClassLoader.java:382)

manutter5115:06:27

Are you running leiningen? You might get something informative out of running lein deps :tree and searching for corda-related strings.

manutter5115:06:41

Seems like that import shoulda worked tho

manutter5115:06:56

Looks like the corda stuff wasn’t pulled down from the repo before, and you just downloaded everything when you ran lein deps :tree — I think your import statement should work now?

manutter5115:06:35

I gotta run, good luck with that!

heath15:06:00

thanks for the help!

heath15:06:05

will continue poking and prying

Ivan Koz15:06:35

@heath so the thing is net.corda/corda is some kind of example project or a runtime, you need specific parts of it like, net.corda/corda-core and net.corda/corda-jackson as lein deps

Ivan Koz15:06:39

then just (import net.corda.client.jackson.JacksonSupport) etc

heath15:06:43

I went with net.corda/corda-core. Seeing in maven central more of these libraries

heath15:06:59

thanks for helping me get past this bump! 🙂

Ivan Koz15:06:32

yeah i'm not sure why there is corda/corda jar, it has just 2 classes you able to import and run Capsule and CordaCaplet and they are in the default package, so you import them just by (import Capsule) or (import CordaCaplet) then run their main method

Schmoho17:06:15

Hi there. I'm having recurrent problems with example apps and tutorial code not compiling because "Call[s] to clojure.core/refer-clojure did not conform to spec" - unfortunately I don't quite understand how to read the spec error messages and I can't seem to find any ns-forms that appear to be off syntax-wise. I've tried to read up on spec but I could not really gather what the messages try to tell me. Any hints on this maybe, some recommended reading?

noisesmith17:06:51

@d.eltzner can you paste your code and error output?

noisesmith17:06:31

also if there was no stack trace, the value of *e

Schmoho17:06:30

Well I can post the spec, the trace is humongous and the code is from https://github.com/omnyway-labs/re-crud/tree/master/example-app

noisesmith17:06:52

you can use the + button by the input bar to share the trace

noisesmith17:06:40

somewhere there's a :refer-clojure in an ns form, with an :as, which isn't valid

Schmoho17:06:56

the code was written for 1.8 and I've got 1.9 installed, I figure this is a compatibility issue but again, I'm having a hard time reading up on that

Schmoho17:06:08

so :as was deprecated?

noisesmith17:06:21

it was never allowed inside refer-clojure

noisesmith17:06:28

it silently did nothing once

noisesmith17:06:31

now it's an error

ghadi17:06:45

looks like it's inside a dependency figwheel-sidecar.repl

ghadi17:06:24

perhaps one of your dependencies is stale?

noisesmith17:06:32

oh that's probably right - best bet is probably to look for a newer figwheel plugin version

dpsutton17:06:44

0.5.18 instead of 0.5.9

Schmoho17:06:48

probably, just grepped on the code and there's no :as in :refer-clojure forms

ghadi17:06:02

yeah it's definitely not your code

dpsutton17:06:28

also probably change [com.cemerick/piggieback "0.2.1"] to [cider/piggieback "0.4.1"]

ghadi17:06:50

if you read the stacktrace backwards, you see a chain of namespaces loading each other figwheel_sidecar.repl_api => figwheel_sidecar.system => figwheel_sidecar.repl =&gt; clojure.core.async

2
dpsutton17:06:06

[cemerick.piggieback/wrap-cljs-repl] => [cider.piggieback/wrap-cljs-repl]

alexmiller17:06:13

the relevant line in that stack above I think is clojure/core/async.clj:9:1

ghadi17:06:33

ah yeah - I misread that 🙂

alexmiller17:06:22

that was something fixed long ago so using an old version of core.async that can be updated

ghadi17:06:07

it's probably safer @d.eltzner to update clojure.core.async alone, rather than risk changing the figwheel/piggieback deps

ghadi17:06:20

by safer I mean a better use of your time

alexmiller17:06:20

current version is 0.4.490

Schmoho17:06:36

first off, you folks are quite the heroes

Schmoho17:06:56

as far as I see core.async is not directly referenced in the code though

noisesmith17:06:08

other libraries use it

ghadi17:06:08

it's through a plugin or dependency

ghadi17:06:13

figwheel, namely

alexmiller17:06:13

and btw, those errors should be much better in Clojure 1.10

noisesmith17:06:19

@d.eltzner jvm deps are transitive

noisesmith17:06:37

you can normally only have one version of a dep, so you can make them use a newer one

alexmiller17:06:44

lein deps :tree would show you the full deps tree

alexmiller17:06:09

lein deps :why org.clojure/core.async will show you the path to that dep

👍 1
Lennart Buit06:06:45

Oh thats really cool!

ghadi17:06:20

oooh TIL ^

Schmoho17:06:32

Yup it was figwheel then. I don't quite get how I would "update core.async alone" though if it's a transitive dependency

ghadi17:06:12

add it as an explicit dependency top-level in your project

ghadi17:06:22

it will override the version of transitive dependencies

Schmoho17:06:32

I see. Cool.

noisesmith17:06:01

the deps are depth-first, so be sure to add it before anything that uses it transitively in the list

Schmoho17:06:48

Well that has been really helpful, particularly grateful for the hint on reading the trace.