Fork me on GitHub
#beginners
<
2019-04-13
>
dumrat08:04:46

Hi all, Created a file named scripts/migration.clj: It starts like: (ns sindu.migration ... (`sindu` is the name of root folder.) Create a main function inside the file.

(defn -main []
  (println "sindu.migration/main"))
Created a deps.edn at root:
{:deps
 {enlive {:mvn/version "1.1.6"}
  ragtime {:mvn/version "0.8.0"}
  org.clojure/java.jdbc {:mvn/version "0.7.9"}
  mysql/mysql-connector-java {:mvn/version "8.0.15"}}
 :paths ["src" "resources" "scripts"]}
Then tried calling main function of scripts/migration.clj: clj -m sindu.migration I get errors:
Exception in thread "main" java.io.FileNotFoundException: Could not locate sindu/migration__init.class, sindu/migration.clj or sindu/migration.cljc on classpath.
	at clojure.lang.RT.load(RT.java:466)
	at clojure.lang.RT.load(RT.java:428)
	at clojure.core$load$fn__6824.invoke(core.clj:6126)
	at clojure.core$load.invokeStatic(core.clj:6125)
	at clojure.core$load.doInvoke(core.clj:6109)
	at clojure.lang.RestFn.invoke(RestFn.java:408)
	at clojure.core$load_one.invokeStatic(core.clj:5908)
	at clojure.core$load_one.invoke(core.clj:5903)
	at clojure.core$load_lib$fn__6765.invoke(core.clj:5948)
	at clojure.core$load_lib.invokeStatic(core.clj:5947)
	at clojure.core$load_lib.doInvoke(core.clj:5928)
	at clojure.lang.RestFn.applyTo(RestFn.java:142)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at clojure.core$load_libs.invokeStatic(core.clj:5985)
	at clojure.core$load_libs.doInvoke(core.clj:5969)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.core$apply.invokeStatic(core.clj:667)
	at clojure.core$require.invokeStatic(core.clj:6007)
	at clojure.main$main_opt.invokeStatic(main.clj:491)
	at clojure.main$main_opt.invoke(main.clj:487)
	at clojure.main$main.invokeStatic(main.clj:598)
	at clojure.main$main.doInvoke(main.clj:561)
	at clojure.lang.RestFn.applyTo(RestFn.java:137)
	at clojure.lang.Var.applyTo(Var.java:705)
	at clojure.main.main(main.java:37)
What am I doing wrong?

alexmiller11:04:47

File should be at scripts/sindu/migration.clj to match the ns

tabidots11:04:44

@ hey, are you dumrat on the Project Euler forums? Nice to see you here! One of the only other Clojurians on there.

dumrat17:04:45

@ Do you do Project Euler as well?

tabidots17:04:49

Yes, since February, but after solving about 90 problems, it’s getting too hard to remain enjoyable 😅 most recently I solved #437 and that took me a week (studying time, optimization, etc)

dumrat17:04:11

I did the first 92, and got stuck with 93 and sort of gave up. Never really got into the harder ones I guess.

dumrat17:04:52

But I found that I generally enjoyed solving the problems in Clojure more

tajoddin.shima09:04:02

Hi I'm new with honeysql I have a function that supposes to return all the states where client-id equals with c-id and their counter are between from and to my function is attached. but I get class cast exception:: java.lang.Long to Clojure.lang.IFn any suggestion? It's happen because clojure take from in (from :state) as input from instead of honeysql/from

seancorfield19:04:31

Your local from is shadowing the helper function from so you are effectively "calling" a long value (in from) as a function. @

lady3janepl10:04:23

Hey, possibly I’m trying to do something strongly not recommended 😄 is there a way to override a function deep down a call stack?

jaihindhreddy18:04:14

binding is probably better if it's only in one thread.

lady3janepl10:04:54

ie. I’m calling library.public-fn which calls library.other-fn which calls library.format-string

lady3janepl10:04:23

and I’d like to change output of format-string (say, kebab case instead of snake case)

victorbjelkholm42910:04:28

would probably work

lady3janepl10:04:47

thanks 🙂 I’m reading the docs now!

alexmiller11:04:46

But this is of course a dirty thing to do and you typically shouldn’t do it unless you’re in a test

lady3janepl20:04:47

It’s a static page generator (Cryogen), so it’ll never run anywhere but my local machine. I could do this properly and duplicate a lot of the code... but it’s convenient that I don’t have to.

alexmiller11:04:17

There are also scenarios where it won’t work

victorbjelkholm42912:04:53

@alexmiller is there another cleaner way of doing it if it's a third-party library you don't control? (except forking, changing it/making it possible to change, send patch) Feels like inherently, monkey-patching code will always be a bit dirty

alexmiller23:04:33

In Clojure, monkey-patching like this over a lib is unusual and considered bad form. It won’t compose with anything else well.

jaihindhreddy18:04:55

What's the implication of the difference b/w rest and next. I understand next returns nil if there are no more elements and rest returns an empty sequence instead, but I'm unable to see what difference it makes in usage.

lilactown18:04:05

I think that rest is kind of the more LISP-y form, whereas next is more Clojure-y

lilactown18:04:09

if that makes any sense at all

lockdown-18:04:54

next is (seq (rest coll))

lilactown18:04:48

in LISP, the empty list was frequently conflated with false or nil

jaihindhreddy18:04:51

Yeah, got that from "Clojure for LISP Programmers". Empty seqs aren't unified with false and nil because we want to distinguish b/w the kind of data structure. Thanks!

lilactown18:04:31

yep. next might be better to use when e.g. recursing through a list. that way you can just check for nil instead of having to call empty? on the next result

lockdown-18:04:31

comes down to, do you want nil or an empty coll as a return value?

lockdown-18:04:06

you may want one or the other

jarvinenemil19:04:01

Autocomplete has stopped working for me, for "js" in clojurescript, like (js/ using cider and emacs. Anyone else who have had the same issue? I am using Figwheel

seancorfield19:04:18

@jarvinenemil Maybe ask in #lein-figwheel or #emacs if no one is around here to help?

jarvinenemil20:04:24

will do, thanks @seancorfield

somedude31420:04:22

How do I literally get val1 from x (`(def x {-1 nil, 1 "val1", 2 "val2", 3 "val3"})`) by val1. not (get x 1)? I need to do that because x is used as an enum.

lennart.buit20:04:05

so you want to do a reverse lookup?

lennart.buit20:04:24

otherwise, elaborate ^^!

somedude31421:04:20

This is what I need but how can I simplify it: (get x (get (clojure.set/map-invert x) "val1"))

zane00:04:40

You could also use clojure.core/some.

jaihindhreddy20:04:44

If you want the symbol val1 you might wanna store symbols in the map (def x '{1 val1 2 val2}) and do (get x 1), or you can call symbol on the return value to create the symbol val1 out of the string "val1". I strongly suspect you're doing something that isn't idiomatic, and so more context would be helpful.

somedude31421:04:10

Very likely but it's a complex system that I am not ready to introduce changes to

somedude31421:04:08

The result is basically the same result of (get x 1) but I want the code to show val1 is being used instead of 1, if possible without the complexity of (get x (get (clojure.set/map-invert x) "val1"))

lennart.buit21:04:03

wait huh, this will just give you “val1”, doesn’t it? But only if it was in the vals of the map to begin with

lennart.buit21:04:32

that’s a strange way to navigate a map, from right to left to right. I don’t think we (-- or at least I, can only speak for myself --) can offer much help in “simplifying” that other than urging you to reconsider this solution you have right now

somedude31421:04:03

Ok, thanks for the advice. From my perspective the previous developer should've used the keys as vals and vice versa 😕