Fork me on GitHub
#beginners
<
2018-01-12
>
Queerstronaut00:01:59

Hi guys! i'm just starting and I'm running it an issues whenever I lein run in my terminal I get the error "Exception in thread "main" java.lang.Exception: Cannot find anything to run for: clojure-noob.core" Ive googled many times, but the best answer I got was to check the project file to see in the main: is there, which it is. I've had my dad, who is a programmer look over it, code looks right, but doesn't know enough about clojure to figure out where the issues is stemming from. help, please.

noisesmith00:01:24

it needs to be called -main, not main

Queerstronaut00:01:16

in the project file or in the core file?

noisesmith00:01:31

in the namespace, the project file should list the namespace

noisesmith00:01:42

so if using leiningen in project.clj you would have :main clojure-noob.core and in src/clojure_noob/core.clj you would have (defn -main [& args] ...)

zsck00:01:26

I can't believe how powerful this language is. It's almost terrifying.

Queerstronaut00:01:05

OH NOW I SEEE @noisesmith that makes so much more sense thank you

zsck00:01:05

Could anyone link me to some reading material regarding writing highly testable Clojure code? Of course everything's great in the world of pure functions, but I really want to know how things look when things like databases come into the picture. I understand Clojure cares a lot about this kind of thing! 🙂

noisesmith00:01:31

No link off hand, sorry. A great rule of thumb is to separate logic from IO, most code that does any meaningful logic (that is, something worth testing) should be writable as a pure function, which is optimal for testing. Then the code that interacts with files or the network or other side effects can be a very thin wrapper around some library or built in functionality, using your pure functions for all data processing. There are libraries that help facilitate this approach including stuartsierra/component.

zsck01:01:54

Interesting, I'll check out this library.

chrinaldini09:01:02

Hi, I'm trying to set focus on an form input element by using reagent/create-class and :component-did-mount Not sure if this is the best way to go, so do anyone have a "best practice" for this I can look at? Thanks!

boldaslove15609:01:57

What problems can't be solved by lein or boot but can be solved by clj ?

sb11:01:24

Hello, why didn’t compile defmacro in Repl? did you see similar?

sb11:01:35

(defmacro hello 
          #_=>   [x]
          #_=>   (prn &form)
          #_=>   `(inc ~x))

CompilerException java.lang.RuntimeException: Unable to resolve symbol: defmacro in this context, compiling:(/private/var/folders/zz/zyxvpxvq6csfxvn_n0000000000000/T/form-init8739309985101977162.clj:1:1) 

schmee12:01:56

works for me:

user=> (defmacro hello [x] (prn &form) `(inc ~x))
#'user/hello
user=> (hello 123)
(hello 123)
124

sb12:01:22

I see.. Hmm..

schmee12:01:38

did you type it on one line or many lines?

sb12:01:25

I copied from sublime, but no problem before this. I think, something I installed or else

schmee12:01:03

ok, then I don’t know, sorry 😕

sb12:01:43

thx 😕 yes that is strange.. I try to find out what happens

sb15:01:16

ok solved with a restart. sorry

hansw13:01:40

If I was looking to create a web-app in Clojure that needed server-side rendering (e.g. return flat pages, not much Ajax), which clojure-webframework should I pick?

hansw13:01:30

Luminus? Or a there other contenders?

mbjarland13:01:05

@boldaslove156 executing standalone clojure scripts without creating a project comes to mind : )

mbjarland13:01:32

i.e.

$> echo '(println "Hello World!")' > test.clj
$> clj test.clj 
Hello World!
$> 
in a past life I was a groovy programmer and even today I write a lot of ad-hoc code for systems automation and command line usage and this kind of light footed ad-hoc write-and-throw-away dev process is perfect for that scenario

stephenm18:01:04

@hans378 I'm starting to use Rum. It's a library, not a framework, so not too big

admay19:01:36

@hans378 Clojure doesn’t necessarily have ‘frameworks’ in the conventional sense, i.e. Django, Rails, etc… More like conglomerates of libraries that come together to solve problems, i.e. Luminus. If you’re just getting started in Clojure web app development, I’d strongly suggest either using Luminus or following Web Development with Clojure (https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition). Luminus will get you up and running faster while WDwC is a much deeper dive into the subject

hansw19:01:53

@stephen067 i like the idea of a webapp toolkit as library, not a framework. Will look into Rum before I go for Luminus, which seems the defacto standard.

noisesmith19:01:14

to be clear, there is no luminus library, it's a collection of libraries - you can use rum with the libraries luminus provides (just leaving out the lib that renders to the dom)

stephenm19:01:12

Cool. Yes, these are all good points. I am basically following along with this talk: https://www.youtube.com/watch?v=lRHPZXKQVLk but using Rum instead of Hiccup, since I plan on adding React components later.

pablore20:01:14

Is it possible to use clojure.set/intersection with sets of maps given a map of which keywords to compare like in clojure.set/join? ie:

(join #{{:a 1 :b 2}} #{{:c 1 :d 4} {:c 5 :d 7} {:a :c}) => #{{:a 1 :c 1 :b 2 :d 4} {:c 5 :d 7}}

jgh20:01:48

would (apply join set_of_maps) do it?

jgh20:01:35

the code you provided there doesnt work btw

justinlee20:01:05

@stephen067 Could you say what luminus actually is for people who are generally familiar with the basic approaches to web development? “micro-framework” as it says on the front page doesn’t mean much to me.

jgh20:01:11

@pablore might be easier if you actually gave an example of what your input is and what your desired output is

pablore20:01:07

I want to intersect sets of maps like I would join them

jgh20:01:34

that’s not what i asked.

pablore20:01:56

im writing the example now

pablore20:01:35

(intersect #{{:id 1 :name "foo"}
                   {:id 2 :name "bar"}}
                #{{:uuid 1 :domain "asd"}
                   {:uuid 5 :domain "sss"}}
                {:id :uuid}) => #{{:id 1 :name "foo" :domain "asd}}

jgh20:01:12

seems like this would be pretty easy to do with reduce

jgh20:01:27

although maybe something like it doesn’t really exist already in the core lib

andy.fingerhut20:01:52

I don't know of anything in the core lib that does what you want. I would recommend copying clojure.core/intersection's implementation, and modifying it to your liking.

pablore21:01:31

ended up doing a filtering function for that

pablore21:01:35

thanks anyway!

noisesmith20:01:56

@lee.justin.m it's a large collection of libraries and default settings that you clone to make a new project

noisesmith20:01:11

(specifically via lein new)

stephenm20:01:08

@lee.justin.m I don't have any experience with Luminus. From what I read on the page, it is the closest thing in Clojure to Rails or Django, but not really since it doesn't look like it comes with "batteries included". I'd defer to what the others have said about it.

justinlee20:01:17

@noisesmith yea i got that much 😛

noisesmith20:01:58

what it actually is is a bunch of opinionated choices about libraries to use and how to use them

justinlee20:01:23

I was just hoping to understand what flavor of choices they made. Trying to skim through the landing page on the docs it seems like it is a templating language that hooks up to an RDBMS.

noisesmith20:01:36

it uses a lib that templates

noisesmith20:01:41

it uses a lib that uses a db

noisesmith20:01:48

it is nothing but lib choices

justinlee20:01:54

okay wait don’t parse my words too finely. i get that it is more than a language

noisesmith20:01:08

no, it's not even a thing that exists after creating your project

noisesmith20:01:12

it's a template to clone

noisesmith20:01:37

the luminus docs will guide you into choices you can make while rendering the template (creating a new project), but there's no luminus that ends up used in your codebase once you have the project

justinlee20:01:50

yes, but once you’ve cloned it, it is good to know what style of development you’ve gotten yourself into. it appears that the luminus way is to write some html with tags that get replaced. that’s what i mean by templating.

noisesmith20:01:11

that's... one thing that one lib luminus gives you does

noisesmith20:01:47

and it's perfectly valid to make a luminus project that doesn't use that lib http://www.luminusweb.net/docs

noisesmith20:01:57

here's some choices you can make while making a new luminus project http://www.luminusweb.net/docs/profiles.html

manutter5120:01:50

I would say that the clojure ecosystem doesn't really have a "rails" or "django," it's got a wide selection of libraries that you can mix and match to build a web app, and what luminus does is give you kind of a jump start on putting together a workable set of libs.

justinlee20:01:38

so its like super-lein for a collection of server and client side web development libraries and tools. the value add is to somewhat limit the available choices and do some work to ensure they all have a greater than zero chance of functioning once you install them (?)

noisesmith20:01:44

there was caribou (I was one of the core devs as my first clojure job half a decade ago) but I don't really recommend it for new work

justinlee20:01:13

and a bunch of documentation for what to do once you’ve isntalled

noisesmith20:01:17

leiningen looks at your project.clj and decides which deps you need, luminus creates a project.clj and a minimal working codebase using those libs

manutter5120:01:12

Yeah, actually I'd say the docs are a big value-add actually. Handy to have all in one place like that.

noisesmith20:01:18

you don't install things with clojure btw (in normal usage)- your dep manager keeps a cache of things you use and fills it as needed, and hooks them up each time you use it

justinlee20:01:08

so luminus is a lein add-on/plug-in with a collection of presets that makes it easy to install a variety of functional web development software for both client and sever side development; it also provides extensive documentation on how to use the software once you’ve installed it. something like that? because knowing that accelerates my understanding of what i’m reading by a big factor. it is also lets me know that it is not rails.

manutter5120:01:13

I remember caribou! It was pretty cool as I recall.

noisesmith20:01:41

@lee.justin.m it's a template that gives you a bunch of libs if you clone it

noisesmith20:01:20

it doesn't provide any add on or plug-in code

noisesmith20:01:16

and as mentioned previously, it doesn't install anything

noisesmith20:01:25

(other than leading to some things being cached etc.)

manutter5120:01:28

If you look up how to write a leiningen template it might be helpful in understanding what luminus actually is. I've written a lein template or too, it's not really hard.

noisesmith20:01:51

oh right! - a template is code that generates source files and config

justinlee20:01:58

okay. i mean aside from the fact that i’m using the wrong words, the substance seems right.

noisesmith20:01:30

well words mean things - luminus doesn't have code you use other than by generating your project for you (then you go ahead and edit etc.)

justinlee20:01:33

in my feeble brain, “causes stuff to be downloaded and available to the compiler” == install

noisesmith20:01:01

but it doesn't even do that - it generates a project file, leiningen does all the downloading and such based on that project file

manutter5120:01:02

That's roughly the idea, but I personally would say "generate" rather than "install"

justinlee20:01:32

oh come on that’s just silly. then you could say leiningen doesn’t really download anything because its really the operating system…

noisesmith20:01:48

what I'm saying is you run luminus, now you have a project file

noisesmith20:01:03

after that, you are done with luminus - it doesn't do anything other than generating some start up code and config

noisesmith20:01:32

you called it a "super lein" eariler - it generates a config file that lein can use but duplicates no lein functionality

manutter5120:01:47

When you say lein new foo my-app, leiningen goes and gets the foo template, which contains probably some predefined directory structure and template files, then does the usual variable interpolation to generate the project files for my-app

admay21:01:18

Anyone here test their specs for validity or is that overkill?

Kent21:01:22

Hey all, anyone here use Java and Clojure in the same project?

Kent21:01:34

I do and successfully have things running and building with Gradle.

Kent21:01:21

However, I have yet to find a way to run the project in my IDE, Intellij, since Intellij’s compilation of my Java code cannot see the compiled Clojure code. Any tips on getting things set up correctly?

noisesmith21:01:08

are you using cursive?

alexmiller21:01:12

presuming you’re using Cursive with IntelliJ, my experiences have been best with both Maven and Leiningen

alexmiller21:01:23

and have done both with Java + Clojure

Kent21:01:31

I am using the Intellij Cursive plugin.

Kent21:01:02

It isn’t an option for me at the moment to switch to Maven.

alexmiller21:01:12

personally, I find Gradle baffling :)

Kent21:01:12

I am not using the Cursive IDE however.

Kent21:01:32

I have heard that the constraints of Maven are good, which seems pretty accurate.

Kent21:01:40

I just am already used to Gradle so I go forward with that.

Kent21:01:56

Actually, the problem I have isn’t with Gradle. It is with my IntelliJ setup I believe.

alexmiller21:01:05

I’m not sure there is any difference between Cursive plugin and Cursive IDE

Kent21:01:09

At least, I think my problem is with IntelliJ

alexmiller21:01:28

you might want to ask on #cursive

alexmiller21:01:37

the author is there and can probably help

Kent21:01:49

Awesome. Is that a channel in this Slack or in another slack?

Kent21:01:56

I just don’t see the #cursive on the channel list

Kent21:01:03

ok. new to slack, a bit.

alexmiller21:01:51

it’s there :) you should have a link you can click from those messages

Kent22:01:02

Ok, thanks!

drewverlee23:01:32

Whats the syntax for maps with namespaces? I want to attach data to all keys in a map, is there a shorthand for that?

(f {:name "drew" :age 10}) 
=> {:person/name "drew" :person/age 10}
My immediate problem is that datascript seems to be returning a list contaning a map with the datoms i want and i’m looking for it just to return a list of maps (not a list of lists of maps). I think it might be related to this: http://docs.datomic.com/pull.html#multiple-results

alexmiller23:01:17

a) keywords can’t have metadata (they are cached and shared) and b) there is no syntax or function specifically for that

drewverlee23:01:46

maybe this isnt the right channel for the later part.

noisesmith23:01:27

@drewverlee if your clojure version supports it, clojure will show you the shorthand

Clojure 1.9.0
+user=> {:foo/bar 1 :foo/baz 2}
#:foo{:bar 1, :baz 2}

drewverlee23:01:04

Is there a way to add that information to the entire map though?

alexmiller23:01:29

What does that mean?

schmee23:01:19

I guess you want to change the namespace of the keys in a map? If so: Specter version:

user=> (def m {:name "drew" :age 10})
#'user/m
user=> (setval [MAP-KEYS NAMESPACE] "person" m)
{:person/age 10 :person/name "drew"}
Vanilla version:
user=> (into {} (for [[k v] m] [(keyword "person" (name k)) v]))
{:person/age 10 :person/name "drew"}

drewverlee00:01:34

Sorry Alex, on my phone. I was trying to do o what schmee showed. But it's probably not related to my core issue, I'll hunt around in the datomic docs to understand the behavior better.