Fork me on GitHub
#beginners
<
2019-07-21
>
m13102:07:30

I dont like deps edn - to me, other than NIH it seems to be unable to do anything lein cant already do

m13102:07:06

Also i am biased as my deps based inexperience caused me to be unable to have emacs cider jack in autoload my core.clj file in a deps project, but same using lein has no issues

seancorfield05:07:13

@m131 As someone who used Leiningen for years at work, then Boot for years, and now CLI / deps.edn for everything at work, I can tell you that it has plenty of pros.

seancorfield05:07:27

Comparing it to Leiningen directly is a mistake and misses the point.

seancorfield05:07:52

But, if you're only doing basic stuff in simple projects, there's really very little between the tools: they all start a REPL, they all run Clojure code. The differences become evident only when you need to customize how the tools behave in complex project environments.

slack.jcpsantiago07:07:57

has anyone setup CircleCI with Codecov? I don't understand the file variable... where is CircleCI placing the test reports by default?

dan26611:07:07

Hey, I've got a clojurescript + hoplon question!

dan26611:07:17

I am trying to iterate over elements stored in a javelin formula cell in hoplon using for-tpl

dan26611:07:12

My code is identical to this: (var names have been changed for readability)

dan26611:07:06

What I would THINK this would return based on my shaky understanding of hoplon for-tpl and javelin formula cells: each element in the collection created by ""(take count (iterate element (element))""

dan26611:07:59

But what I actually get is this: ""[#object [javelin.core.Cell 0] #<HoplonElement: DIV>]"" (my element happens to be a vector of a javelin cell and a hoplon div). This looks to be the javelin formula cell, but I can't figure out how to access the data I want!

dan26611:07:16

Fixed! Turns out the reason I couldn't use deref on the object was because everything needs to be nested under a div

lady3janepl11:07:37

what does the naming convention with * as the last function character mean?

alexmiller12:07:04

In this case, the * functions are primitives understood by the compiler

bronsa15:07:34

I think you might have read let* instead of list* :) there's nothing special about list*

alexmiller12:07:32

And sometimes that convention is used elsewhere - the * function is the “impl” version and then the unstarred version is the “public” version

alexmiller12:07:04

That’s not a universal convention though

lady3janepl12:07:06

thank you! I think the original example I encountered was of the "impl/public" variety 🙂

lady3janepl14:07:25

Is there a good pattern for when you want to map over a collection, but in rare cases one input element should generate multiple output elements?

lady3janepl14:07:00

(I could do a mapcat, but having to return a single-element vector for majority of the elements seems like an overkill)

lady3janepl14:07:05

(very contrived example: (1, 2, 3) should generate (false, true, false) but (1, :twice, 3) should generate (false, nil, nil, false))

mfikes14:07:31

@lady3janepl Are you wanting to optimize this case for execution speed? Or code clarity?

lady3janepl14:07:17

code clarity; usecase is static site generator

lady3janepl14:07:58

expected input in the form of nested maps, expected output html, I'm attempting to write nicely composable functions 🙂

lady3janepl15:07:01

ended up with a reduce-kv which for most keys does a (conj result (case k ...)) but for the special key, concatenates to result instead.

lady3janepl15:07:29

(I liked when the functions were simple cases better though)

mfikes15:07:57

mapcat seems like the most readily understandable construct, but I see what you mean... I guess in your case it is doing mostly a map returning non-collections

lady3janepl15:07:39

(specifically, I'm generating <meta> tags for open graph data, where they have a convention that for an array of something, you should repeat the meta tag multiple times)

jcb15:07:18

How do you concatenate a string to every element of a collection of strings? thanks!

noisesmith15:07:29

one simple way: (map #(str % " foo") ["a" "b" "c"])

noisesmith15:07:49

=> (map #(str % " foo") ["a" "b" "c"])
("a foo" "b foo" "c foo")

noisesmith16:07:21

#() is a shorthand for (fn [] ) which doesn't require naming arguments, and only allows a single form in the body

jcb16:07:38

Thanks @noisesmith !

orlandomr2716:07:43

Hello, I´m Orlando from Nicaragua. Former COBOL, C, Visual Fox Pro, Oracle, C#.Net developer, now manager, who´s having fun again with Clojure

hmaurer16:07:13

Hi! How can I start a repl with clj and deps.edn in a particular namespace? If I start the repl then do (in-ns 'hello) it doesn’t work (as if the namespace isn’t loaded). The only way I can get it to woork is by doing this:

user=> (require 'hello)
user=>(in-ns 'hello)
hello=>

seancorfield16:07:51

@hmaurer You can give those forms on the command-line (so you could also provide them via :main-opts in an alias

(! 686)-> clj -e "(require 'example.main)(in-ns 'example.main)" -r
#object[clojure.lang.Namespace 0x5ba88be8 "example.main"]
example.main=> 

hmaurer17:07:33

Ok, fair enough!

seancorfield17:07:24

{:aliases
 {:repl
  {:main-opts ["-e" "(require,'example.main)(in-ns,'example.main)" "-r"]}}}
and then clj -A:repl

seancorfield16:07:31

But I would ask why you care what ns the REPL starts in? I think it's better to stay in user and require things in via aliases as needed...

noisesmith16:07:42

my favorite: (doto 'foo.bar (require :reload) in-ns)

noisesmith16:07:02

that way I can run it again when my code runs, and it leaves me in a decent state if anything goes wrong

noisesmith16:07:51

(I think I learned this trick by watching over @technomancy's shoulder, but not certain)

hmaurer17:07:55

@noisesmith ah nice, ty!

noisesmith17:07:42

often while developing I will repeatedly run (doto 'foo.bar-test (require 'foo.bar :reload) in-ns (clojure.test/run-tests)) - a one liner that reloads my source and the tests, then runs all the tests

noisesmith17:07:17

(I find it useful to be in the test ns while developing often - weak tdd)

noisesmith17:07:30

and even if I reboot my box, or just have to restart a repl, the command line history has a standalone in it that I can find easily with control-r, that loads everything I was most recently developing and runs the tests

noisesmith17:07:08

I combine this with a script that finds all files that are different between my branch and origin/master into a new instance of my editor, and voila - probably the simplest possible version of project history and reload

noisesmith17:07:36

#!/bin/sh
git fetch
nvim $(git diff --name-only origin/master)

hmaurer17:07:16

that’s exactly what I was looking for; super simple 🙂 ty

hmaurer17:07:08

follow-up question: when I call (>!! some-chan some-vlaue) in the repl, it blocks until the value is picked up from the channel (with core.async). I would like to interrupt this, but Ctrl-C exits the repl completely (on os x). any idea?

noisesmith17:07:03

that's inherent with the clj repl as is, there's probably some trick with signal handlers but nrepl / repl-y already has this set up

hmaurer17:07:30

ah ok; so no easy way to do it with clj repl?

noisesmith17:07:36

also you can just use put! instead of >!! - optionally with a callback that logs / prints

noisesmith17:07:00

@hmaurer probably the lowest effort would be using nrepl in clj - there's alreayd projects that make this simple

hmaurer17:07:43

yeah I’ve used nrepl before; I just wanted to get it to work with clj since it’s dead simple for some things

noisesmith17:07:44

this makes me realize I want to find out how the repl-y client signal handler interrupts the last input without shutting down the client or vm...

hmaurer17:07:58

@noisesmith please let me know if you do 😛

noisesmith17:07:33

so nrepl has a built in :interrupt-id tag that you can pass the id of a pending input

noisesmith17:07:05

next step would be to see how nrepl handles :interrupt-id and cancels that operation

noisesmith17:07:57

tl;dr looks like "replace eval with something that sets things up to be registered and interruptable"

noisesmith17:07:03

(for the repl itself at least)

noisesmith17:07:35

so back to my first reply - the easy way is to use nrepl via clj (there's a few setups for doing this, I'm not certain which one is the best pick)

alexmiller02:07:23

If there is something to add here - please do. It's a wiki.

noisesmith03:07:31

it's a legitimate question for me - I have seen nrepl setups for clj, but haven't used any of them in anger

noisesmith03:07:38

I will add one if I know it works well

noisesmith17:07:42

(you could start two clj processes, one which starts an nrepl server (that's a one liner) and another that starts a REPL-y client (likely another one liner)

noisesmith17:07:51

that's what lein is doing under the hood, starting two jvms

noisesmith17:07:47

in fact instead of using Control-C you can just connect another repl to the same vm, and leave the other one running