Fork me on GitHub
#clojure
<
2018-11-19
>
andy.fingerhut00:11:39

I haven't used rewrite-clj before, but am aware of its existence, and it might be in the neighborhood of tools you are asking about: https://github.com/xsc/rewrite-clj

cfleming00:11:34

Hmm, thanks - in this case I don’t need formatting preservation. Genetic Programming has some useful stuff: http://www.thattommyhall.com/2013/08/23/genetic-programming-in-clojure-with-zippers/

cfleming00:11:38

I think that’s probably what I need.

didibus01:11:03

Question - I'm using Clojure-future-spec aplha17 and just migrated to Clojure 1.9 and I get: Caused by: java.lang.IllegalStateException: Attempting to call unbound fn: #'clojure.future/ident? Anyone knows about this?

seancorfield01:11:25

@didibus You might want to be a bit more specific about what you actually did to cause that exception. I just tried clojure-future-spec with clj and 1.9.0 and it seems to work...?

didibus01:11:14

Ya, it seems it is thrown when doing Class.forName("clojure.java.api.Clojure"); from Java

didibus01:11:02

Actually, I don't know. It is pretty strange, I get the error when I'm compiling my java tests

didibus01:11:10

Not even when running code

didibus01:11:42

Where I have imports for: import clojure.java.api.Clojure; import clojure.lang.IFn;

theeternalpulse03:11:23

What was the name of that tutorial site that teaches clojure through drawing with a graphics library online?

theeternalpulse04:11:52

no, it was a live coding site, with rows that had a tutorial and the code you typed would draw shapes on the right side

theeternalpulse04:11:04

I read that book though 🙂

edwaraco04:11:14

Ohh, I don't know what is. Please share me it When you achieve finding it 🙂

jaawerth04:11:12

@U1CUUKHDL the intro to the maria IDE? "learn clojure with shapes" https://www.maria.cloud/intro ?

👍 12
theeternalpulse04:11:21

Yes! I do remember it was a femenine name, I even got to trying "sophia" lol

Eric Ervin22:11:17

I have to check out Maria. I enjoyed the time I spent typing into Power Turtle. 🐢 http://timothypratley.github.io/power-turtle/

Hermes04:11:57

@jonoflayham Thank you very much I solved the issue.

andy.fingerhut06:11:30

No problem publishing small files here, but more common to publish links to things, when you know them, e.g. https://clojure.org/api/cheatsheet which also has a link to this page, with other versions: https://jafingerhut.github.io/

jwhitlark06:11:04

Has anyone seen an expect like tool or library, written in clojure? I want to say I ran across one a while back, but my google-fu is failing me at the moment.

noisesmith16:11:56

expect is a library for driving programs that communicate via stdio - basically it allows automating anything that provides a "repl" or "command line"

noisesmith16:11:15

I started work on a clojure expect once but didn't get very far

roklenarcic09:11:09

I have a lazy sequence of vectors. I want to flatten this structure (to lazy sequence of vectors' elements), while retaining the lazyness.

roklenarcic09:11:25

Is there a core function for this?

roklenarcic09:11:21

The only ones I've seen use varargs, which would require an apply, which would realize whole lazy sequence

cklaou09:11:20

@roklenarcic Maybe you could try (mapcat identity ...) ?

roklenarcic09:11:27

I think that's just (apply concat (apply map under the hood

roklenarcic09:11:05

I guess straight up flatten would work if vector elements aren't sequential

jaawerth15:11:59

(sequence cat col) would work. If you're doing a pipeline you can just add cat into any transducer pipeline you're composing to flatten it one level

urzds11:11:27

Hi! Is there something like contains-in? -- something that tells me whether a subsequent get-in will come up with something, just like contains? tells me whether get will work?

manuel11:11:21

Hi everybody. Is there an equivalent in deps.edn for Leiningen :repl-options {:init-ns ...} settings? In other words, can I start the the REPL into a specific namespace?

Alex Miller (Clojure team)14:11:56

clj -e "(ns clojure.set)" -r :)

manuel14:11:25

superb, thank you!

urzds12:11:24

And is there something like (defn f [...] {:pre [...]}) for fn?

Audrius12:11:57

#'routes what is this? is it a hashed symbol or something? 😄

mfikes12:11:45

It is the same as (var routes)

mfikes12:11:40

Sometimes vars are used instead for a little more indirection in places where you don't want to hold on to just a function value (because you want to redefine the function).

mfikes12:11:17

For example (inc 1) and (#'inc 1) both work, but if you have a case where maybe this is in a map

{:my-fn inc}
you can dynamically get new behavior if instead you hold onto #'inc

👍 4
Audrius12:11:04

thanks, but how this form is called in general?

andy.fingerhut15:11:55

@Audrius If by "how this form is called" you are asking "how do people refer to it when speaking to each other", it is sometimes called a var quote

Kari Marttila15:11:52

http://www.javamagazine.mozaicreader.com/NovemberDecember2018/Default/15/0#&amp;pageSet=18&amp;page=0 => Java has 90% market share of JVM languages, nothing new about that. But I was a bit (positively) surprised that the second popular JVM language is Clojure, not Scala or Kotlin.

dpsutton15:11:04

(in this sample of 3,234 responses)

Kari Marttila15:11:27

What do you think about Clojure's future? I have tried to convince some colleagues to use it in our corporation with some success.

Alex Miller (Clojure team)15:11:30

soon everyone will be using it

😁 4
🙂 4
mpenet15:11:52

and still will be in 50 years

Alex Miller (Clojure team)15:11:52

I say this as a completely unbiased bystander

👀 4
😂 4
dpsutton15:11:20

Clojure is a great language. the stuff that makes it great to me is the stuff that made 1.0-1.8 great. so new changes etc are either very nice and welcome or irrelevant to me. and the core good stuff that make it a great language won't be changed since the stewardship is so great

mpenet15:11:25

sample size is quite small and these kind of surveys are usually not really representative of the reality

Alex Miller (Clojure team)15:11:52

sample size was like 10k in this one wasn’t it? that’s actually pretty big imo (the annual Clojure survey is usually about 2k)

mpenet16:11:25

Relative to the number of actual users it's quite small

mpenet16:11:18

In the clojure case I suspect it's quite good

dpsutton15:11:40

10,500 apparently

Alex Miller (Clojure team)15:11:00

@kari.marttila the truth is that only you can and your organization can decide what technologies to base your business on and different people will make different choices based on their own needs and situation. Clojure is not going anywhere and is a viable option. I personally think it has vast advantages over some of the alternatives, but you should consider the tradeoffs as well.

manutter5115:11:20

Sometimes people compare languages and fail to distinguish between value and trendiness. Clojure may look trendy at some times and not-so-trendy at others, but it provides solid value for organizations that use it, and for that reason it has a future regardless of fashion.

Alex Miller (Clojure team)15:11:14

Clojure has always put a lot of effort into reducing the cost of change in your code over time. That has tremendous value to businesses but is sometimes difficult to communicate or to see in small or initial projects.

gklijs16:11:43

I really like Clojure, but I'm afraid it will gain a lot of users in the near future is pretty slim. A lot of Java developers seem really 'afraid' if the parentheses. Also to many people seem to put great value in having a big company backing a programming language.

noisesmith16:11:18

From my conversations the main friction has to do with programming philosophy and education. Eg. they are happy to use a language that has far fewer delimiters if it uses a conventional object-oriented design

noisesmith16:11:28

and I was horrified to see what happens when a java programmer figures out records and protocols before they internalize the basics of clojure...

😄 8
seancorfield16:11:48

Languages don't "need" to be mainstream-level successful tho' these days -- we have a lot of choice -- and if you stay on the JVM, being polyglot in a large company makes sense: let teams use whatever language they want, as long as everyone can call each other's libraries...

apohorecki16:11:05

I think it's generally easier to convince people to switch something that looks similar to what they already know - when I used to work primarily with Ruby, most of my colleagues were eyeing Elixir as an alternative, now when working with Java it's mostly Scala or Kotlin

mafcocinco16:11:34

@gklijs IIRC, Java and Clojure have the same number of parens (in some cases Java has more), it is just the placement that is different.

seancorfield16:11:35

@noisesmith Agreed. The biggest obstacle to Clojure -- and to FP in general -- is the mental shift from OO based on mutable state.

👍 16
seancorfield16:11:17

@mafcocinco Yup, obj.foo(bar,quux); => (foo obj bar quux) -- but it's surprising how many people find that a "hard" transformation to perform in their head 😐

mafcocinco16:11:21

indeed. it can be difficult when you have been doing OO for so long but it is definitely worth the investment. Personally, the amount of cognitive load was significantly reduced not having to remember different calling conventions.

borkdude16:11:54

I’ve had more trouble understanding OO (patterns) than FP.

👍 4
noisesmith16:11:30

that's true for me too, but I think it's a question of which you learned first

mafcocinco17:11:35

I would agree as well, but my core CS education was in Scheme and ML. I learned OOP the end of junior year/senior year of college and then had to use it for some 10 years at my first job.

borkdude17:11:09

could be. I learned FP and OO just some weeks behind each other at uni. FP was much more simple to me.

noisesmith17:11:23

maybe "found fluency with first" rather than "learned first"

mafcocinco17:11:06

Perhaps. My personal feeling is, placed side by side in front of say first year Comp Sci majors, most people will find FP easier to understand. What makes in challenging (opinion, no evidence) is the baggage of OOP.

noisesmith16:11:59

Clojure is more disciplined than most higher level languages I've seen in not having special cases to remember. There's still special cases, but they are remarkably rare.

☝️ 4
Kari Marttila17:11:07

I hope all the best for Clojure's future - Clojure is definitely my personal favorite language. Lisp REPL is the best productivity tool I have ever used.

Kari Marttila17:11:09

But in a big corporation you cannot always choose the language used in the project. However, I try to promote Clojure every time I can.

jaawerth17:11:33

in a corporation you often have to code things in a language 1) your team knows or has time to learn, and 2) it's easy to hire for or find more people to maintain. You're sometimes limited in what languages you can use by the "bus factor." Lisps always have to contend with this because the syntax looks scary to the uninitiated, but it seems like they always carry on regardless by picking up a following of talented devs

jaawerth17:11:47

and clojure does a great job of being FP-first but supporting other paradigms where needed, which you can't say about a number of other FP languages

andy.fingerhut18:11:06

Echoing Sean's comment above, I think that while you may hear complaints about syntax and think they are superficial (and I would agree), there are significant hurdles to people, including me, who are used to writing imperative for loops with if conditions inside of them, all day, to iterate over arrays or lists, and then to switch to Cloure, and just feel stupid that you don't know how to do really basic stuff.

andy.fingerhut18:11:28

That stupid was directed at my own remembered mental state, not anyone else. Maybe a better way to say it is: you feel like you went down multiple notches in competency all of a sudden.

noisesmith18:11:57

it's a sub-optimal skill tree strategy in the short term :D

JH18:11:01

Question, if I have a map

clj
{"FirstName" {:value "asdfas", :invalid? false}
   "MiddleInitial" {:value "a", :invalid? false}
   "LastName" {:value "asdf", :invalid? false}
   "EmailAddress" {:value ""}
   "PrimaryPhone" {:value ""}
   "DateOfBirth" {:value ""}
   "SocialSecurityNumber" {:value ""}}
` And I want to return the keys and the :value in the nested map how would I do so? Example output
clj
{"FirstName" "asdfas"
   "MiddleInitial" "a"
   "LastName" "asdf"
   "EmailAddress" ""
   "PrimaryPhone" ""
   "DateOfBirth" ""
   "SocialSecurityNumber" ""}
I tried using doseq but it seems to be geared more towards side effects (doseq [keyval map-to-destruct] (prn (key keyval) (:value (val keyval))))

noisesmith18:11:07

(into {} (map (fn [[k v]] [k (:value v)])) map-to-destruct)

😀 4
dpsutton18:11:08

this often comes up in tandem but the "order" might be different.

noisesmith18:11:21

that fn could be replace by #(update % 1 :value) but I think the fn version is clearer

jaawerth18:11:33

yeah that's how I'd do it ^

dpsutton18:11:10

(reduce-kv (fn [m k v] (assoc m k (:value v))) {} {:a {:value "a"} :b {:value "b"}}) is how i would do it. not a big fan of updating vectors positionally

emccue19:11:00

@jacob.haag I use clojure.algo.generic.functor for stuff like that

emccue19:11:11

(fmap :value m)

emccue19:11:40

(its a lib, but a tiny one)

emccue19:11:30

else, this is a nice helper

emccue19:11:57

not different from noisesmiths, but i like having it named

noisesmith19:11:12

it's different because mine uses transducers - but the behavior is the same

john19:11:01

It amazes me how easy it is for users to extend Clojure. In just a few lines of code, I just added the ability to leverage isa? hierarchies (and prefer-method-like disambiguation) in my predicate dispatch example on SO: https://stackoverflow.com/questions/53329709/dispatching-function-calls-on-different-formats-of-maps/53354967#53354967

john19:11:04

When things are kept simple, the pieces just fit together so much more easily

emccue19:11:37

@john what if you wanted to dispatch on [1] and [2]?

emccue19:11:53

(skimming your code)

john19:11:01

Can't, I don't think

john19:11:28

Vectors are assumed to be consumable by isa?

john19:11:46

But you could dispatch on 1

john19:11:17

assuming the args can take 1 as an argument

john19:11:04

It's not a perfect implementation

john19:11:20

Not as robust as defmultis in that regard

john19:11:34

If you see a way around that limitation, feel free to improve it

emccue19:11:37

eh, nothing springs to mind other than a hacky deftype

john19:11:57

By dispatch on [1] do you mean being able to do the implicit (nth [0 1 2] 1) when 1 is passed to [0 1 2]?

john19:11:10

Oh no, you mean actually dispatching on [1]... you're supposed to supply functions, not equal vals, so you're supposed to provide #(or (= % [1]) (= % [2])) in that case.

john19:11:57

The cool thing about predicate dispatch, it kinda documents functions

john19:11:47

and you could theoretically just pass one of the spec validator functions as a predicate

john19:11:53

I made a version that memoizes args->poly-fn for a given poly and invalidates the cache when another defpoly is called with that poly, but that's a pretty big hammer.

kenny20:11:22

Has anyone run into an issue with require'ing a namespace in multiple threads, one thread marking the ns as loaded before it is actually complete causing another thread to think the code is require'ed resulting in a function call occurring before it's ns is loaded, ultimately producing java.lang.RuntimeException: No such var: exception?

kenny20:11:26

@mfikes Is the workaround to explicitly require the ns?

mfikes20:11:48

The ClojureScript compiler started having this issue, I believe, after parallel compilation was added to it. (IIRC, when compiling ClojureScript code in parallel, there is a possibility that one namespace might cause a compilation thread to require some Clojure code—for macros—while another races with it). Regardless, you can see that the ClojureScript solution serializes all requires.

wilkerlucio22:11:05

hello, using deps.edn I'm trying to override a dep from maven (that comes from another dep) with one in git, but when I try I'm getting Unable to compare versions for, is there a way around this?

seancorfield22:11:14

@wilkerlucio How are you currently trying to "override" the dep?

wilkerlucio22:11:31

by adding on my project deps, like:

wilkerlucio22:11:32

camel-snake-kebab      {:git/url ""
                          :sha "865416c2cec019cee92d8d3892d20a64559a4054"}

seancorfield22:11:49

(tools.deps cannot compare versions from different providers because they have no ordering)

seancorfield22:11:21

You'll need to add an alias with :override-deps to specify the Git version (and then specify that alias when invoking clj)

wilkerlucio22:11:18

@seancorfield thanks, that works 🙂

seancorfield22:11:53

(we use :override-deps heavily at World Singles Networks to "pin" versions of all the libraries we use in multiple subprojects)

jaawerth23:11:36

@seancorfield speaking of, have you had any luck with private git repos? initially I ran into this problem https://dev.clojure.org/jira/browse/TDEPS-31 but after performing the workaround in the linked blog post, it also decided it didn't like my ssh key (I tried both my initial ed25519 key and then an RSA one, both loaded into my ssh-agent, to no avail)

seancorfield00:11:54

I haven't tried it with private Git repos, sorry.

dominicm09:11:48

@U9QQRN612 delete http://gitlab.com from your known hosts file before running the workaround.

jaawerth23:11:57

I still have some tinkering to do - in the meantime I just went back to using a local version

stephenwithav23:11:14

Is there a good sqrt function for BigInts in an existing Clojure package?