Fork me on GitHub
#clojure
<
2017-01-01
>
seancorfield00:01:20

@richiardiandrea TL;DR: "yes" in both but I'd have to go research the syntax 🙂

richiardiandrea00:01:12

@seancorfield basically I'd need to append ::jsonb to a (?)

seancorfield00:01:40

In honeysql, I'm pretty sure you can do something like [(sql/call :cast ...) :alias] but I'd have to experiment

seancorfield00:01:22

Whatever you need to write in SQL is possible to be done in both -- raw SQL string in java.jdbc or a call in HoneySQL.

richiardiandrea00:01:33

Ohok, I will experiment don't worry, now that I know, I could not find it, BT maybe I haven't looked deeply

richiardiandrea00:01:09

Yes I use raw usually for this, in let me try, thanks!

seancorfield00:01:20

Normally in SQL you can do something like CAST( column AS type ) AS alias

richiardiandrea00:01:54

Uhm, nice, I was focusing on postgres' syntax but maybe I can use the above instead

richiardiandrea01:01:39

@seancorfield I did not go for the cast eventually, but your link about made me implement a simpler and more portable solution:

(defn valueify-map
  [m]
  (mapv #(value (get m (first %))) m))
This correctly isolates the data as parameter (which in my case is the column value) and thanks to some jdbc/ISQLParameter magic extend-type I can don't need to pass strings and cast to jsonb

richiardiandrea01:01:51

actually I don't even need the above 😉 It can be simplified

richiardiandrea01:01:11

to:

(defn valueify-map
  [m]
  (mapv (comp sqlf/value second) m))

richiardiandrea01:01:46

and in honeysql, the values clause becomes: (values (mapv valueify-map members))

seancorfield02:01:58

Cool... functions and composability FTW again! 🙂

neupsh07:01:32

is there a way to use argument (literal form) passed to macro without namespace qualification? basically i want to write a macro such that (defmacro mymacro [fst & args] (someotherfunc "someotherarg" "~fst" "~@args")), where i want fst passed without quotes when calling macro and in the macro i want to convert it to string.. same with the other args (need to find a way to quote each item in the args as well wihout namespace qualification)

seancorfield07:01:04

~(name fst) I think?

seancorfield07:01:31

That will turn a symbol (or a keyword) into a string.

seancorfield07:01:35

And then ~@(map name ages) maybe?

seancorfield07:01:00

(On my phone so can't verify. Hope that helps)

neupsh07:01:22

@seancorfield nevermind, found it.. ~' does exactly what i want

neupsh07:01:39

unquote-quote is what its called

lambeta08:01:52

Hi hivemind, I try to configure my own init.el, but I am confused about

(eval-when-compile
  (require 'use-package))
why do we need eval-when-compile for require?

lambeta08:01:24

here, from emacs self-documetation, > If you’re using another package, but only need macros from it (the byte compiler will expand those), then ‘eval-when-compile’ can be used to load it for compiling, but not executing.

lambeta08:01:39

I try to figure it out, guess load means read code text to lisp objects and then compile those to byte code, executing means run byte code in elisp interpreter. Is it right?

kim012:01:13

I’m a newbie to clojure .. liking what I see .. but after scala and haskell .. I wonder why did clojure take the decision to be untyped .. do some view this as a strong point? why ?

tbaldridge14:01:06

@kim0 I take it as a very strong point. I wrote a gist about it recently: https://gist.github.com/halgari/f431b2d1094e4ec1e933969969489854 Clojure is the only language that allows me to do what I describe there.

tbaldridge14:01:11

or more correctly, I get those features, but don't get typing...I want the features bad enough that the fact that they aren't typed doesn't bother me.

Yehonathan Sharvit14:01:02

I’d like to write a function foo that receives a string s and returns a list with the value of s without the quotes as a single element. A possible implementation, I wrote:

(defn foo [s]
  (list (symbol s)))

(def my-string "[1 2]")
(foo my-string) ; ([1 2])

Yehonathan Sharvit14:01:19

But it feels weird to me to call symbol for that purpose

Yehonathan Sharvit14:01:27

I call also call read-string...

Yehonathan Sharvit14:01:39

What is the proper way of writing foo?

fabrao15:01:19

Hello all, I´m using midje for testing, but I don´t know what is happening here:

(ns test.core 
 (:use [clojure.tools.logging :as log]))

(defn debug-message [lo]
  (log/debug lo))

(against-background [(before :contents (println "=> SETUP") :after (println "CLEAN UP <="))]
  (fact ""
    (debug-message "== FACT")))
FACT logs out twice. Am I missing something?

pesterhazy15:01:07

wild guess: try to restart the repl

fabrao15:01:32

It´s in :autotest

fabrao15:01:29

I tried to restart autotest, but same behavior

fabrao15:01:51

it seems that it´s happend when using :autotest mode

tbaldridge15:01:22

@fabrao sadly this pretty much sums up my experience with Midje....to much magic. I was never able to understand why it did some of the things it did. I highly recommend using a simpler testing library. Clojure.test handles almost everything I've thrown at it, and it's super easy to understand...it's just clojure with a few macros that pretty up some text output.

tbaldridge15:01:43

Unfortunately the mission of Midje is such that it requires the library to modify the semantics of Clojure. Since the semantics are now different debugging is much harder since we're no longer discussing the execution of Clojure code. We're discussing the execution of the Midje "virtual machine" .

tbaldridge15:01:32

As you can see here: fact is a macro that parses out your test forms and does all sorts of analysis/re-writing: https://github.com/marick/Midje/blob/master/src/midje/sweet.clj#L170

tbaldridge15:01:54

When I see that level of modification of my code, I get nervous.

fabrao15:01:04

@tbaldridge I saw many issues in github Issues, and now I´m worried about using it

fabrao15:01:22

so, your advice is using clojure.test?

fabrao16:01:53

how about autotest? Is that possible?

fabrao16:01:12

sorry about my sillies questions, midje was the first testing framework I´ve been using

tbaldridge16:01:41

@fabrao I use clojure.test. Expectations also seems pretty good, although I've never used it.

selfsame16:01:12

trying to capture the inverse of a rule but not seeing how that would work (like "[^0-9]" meaning a non digit)

tbaldridge16:01:03

@fabrao personally I use clojure.test with a REPL. Clojure.test has functions like "run-all-tests" that allow you to re-run your tests with a single command. I also use Cursive (Intelij IDE) but other editors also have clojure.test integration. So in Cursive, I have "rerun tests in current namespace" bound to CTRL+SHIFT+T and "rerun test under cursor" to CTRL+SHIFT+Y. So my workflow is write code...rerun tests, fix a bug, rerun tests.

tbaldridge16:01:44

This also works great for me since OSX seems to have a filesystem lag where auto-run testers take about 10 sec to kick off. So the method I use is faster for me.

tbaldridge16:01:36

Many other editors have that feature as well ^^

fabrao16:01:26

@tbaldridge run-all-tests rerun all tests? Not only the test changed? I used midje because it´s IDE free dependency

tbaldridge16:01:14

all the IDEs are doing is running those (and other functions) and then formatting the results

credmp16:01:34

@fabrao I don't know of a testing lib that has an IDE dependency....

fabrao16:01:44

@credulous I said that because tbaldrige is using Cursive to do his tests

fabrao16:01:09

I´m using Atom with Clojure package

nooga16:01:24

@fabrao that doesn’t really matter

tbaldridge16:01:25

Yeah, Cursive is just pretty printing my test results

tbaldridge16:01:00

You can get the same as long as you can get Atom to put a arbitrary from into your repl when you type a keystroek

tbaldridge16:01:29

So you can say "when I press CTRL+t, dump (run-all-tests) into my repl"

nooga16:01:27

btw. @tbaldridge is there any special reason why you chose Cursive over CIDER?

tbaldridge16:01:44

I got tired of the mess that is Emacs. And the deep integration Cursive has with the JVM is nice. I can ALT+. into decompiled java sources from Clojure.

tbaldridge16:01:25

I mean the Cursive debugger, the static analysis, the (IMO) better platform of the JVM (vs a custom single-threaded VM of emacs), etc.

credmp16:01:49

@fabrao I guess in Atom you can just Ctrl-Alt-x to run the tests

tbaldridge16:01:51

Many of those are possible in Emacs, but I just got tired of having to do it all myself and it breaking all the time.

kim016:01:35

I’m looking for an editor too .. Is lighttable too buggy?

nooga16:01:10

@tbaldridge Thanks, haven’t thought about that. I started playing with clojure in LightTable a couple of years back and then just made a giant leap to emacs, build my own .emacs, never looked back at other IDEs. I wanted to try Cursive several times but somehow didn’t and now I’m looking for reasons to try it out 😄

nooga16:01:48

but it’s true, emacs is nice and all but it can be really hardcore if something breaks

fabrao16:01:06

Lighttable gets slow when you using too much rs

nooga16:01:03

it’s written in cljs and runs in one of those webkit containers right?

tbaldridge16:01:21

yeah, it does

tbaldridge16:01:26

@nooga I'm also one of those weird people who want an IDE that works perfectly, and does everything for one language out-of-the-box. So I'm a big fan of PyCharm, VisualStudio (for C#), etc. I'd rather have my editor tuned for one language, than so adaptable that it works "good enough" for 10 languages.

nooga16:01:02

theres one thing in cider drives me insane - it seems to misdirect errors coming from random threads so often you find yourself discovering exceptions in some forgotten buffer after debugging core.async heavy code for 2 hours because it doesn’t seem to do anything

nooga16:01:56

@tbaldridge that’s not weird!

qqq16:01:31

when writing a defmacro, is it possible for the macro to say: I want all my children to macroexpand first -- and I want the result of their macro expansion?

gfredericks16:01:32

I've wanted that a lot of times.

qqq16:01:15

I was expecting an answer of "yes, but you have to call this function"

mingp16:01:37

Are you allowed to explicitly call macroexpand-all in the macro body or something?

gfredericks16:01:47

you can, it's just buggy

gfredericks16:01:58

I think riddley attempts to provide a more reliable version

gfredericks16:01:02

if you don't mind the dependency

mingp16:01:03

It does sound like an unusual use-case.

mingp16:01:22

But, at least theoretically, you do have the trees and what you do with them is up to you.

nooga16:01:34

I can’t imagine what would I use it for

qqq16:01:37

the XY problem is that I'm writing a macro (!! .... ) which infers the arity of a cuntion, and allows us to do haskell style no () function curryingcalling

qqq16:01:51

so for each chid of !!, I need to fully expand it to get its arity

qqq16:01:07

for the first arg of !!, I need to fully expand it to get its arity

qqq16:01:35

(!! (macro-blah blah a b) .... ) -- then I need to expand the (macro-blah blah a b) to get its arity

gfredericks16:01:13

the most recent reason I wanted it was for http://dev.clojure.org/jira/browse/TCHECK-98

gfredericks16:01:49

it would make the macro rather smarter and allow the user to not have to think as much about the implementation of generators, but you could argue that's not a good reason to make a Very Complicated Thing

fabrao16:01:27

@henriklundahl I tested now with expectations and lein-autoexpect and it seems to working good

tbaldridge16:01:50

Yeah, deep walking macros need this sort of thing a lot. core.async's go needs something like this, so we wrote our own. But that mostly entails using an analyzer.

tbaldridge16:01:05

@gfredericks have you looked into clojure.tools.analyzer for this?

gfredericks16:01:17

@tbaldridge I judged it would be bad for test.check to depend on it

fabrao16:01:20

using

{:expectations-options :before-run}
for before and
{:expectations-options :after-run}
for clean up, and running it just once

tbaldridge16:01:20

I know it's a bit heavy handed, but it would do t he trick

tbaldridge16:01:37

yeah I agree esp with spec these days

gfredericks16:01:43

@tbaldridge and alex judged it would be bad for me to write that macro in the first place, so I took a different approach and stopped thinking about it

mingp16:01:57

Is it fair to say that this sort of thing is not typically needed in typical Clojure usage?

gfredericks16:01:05

(provided an alternate syntax so users can opt-in to parallel bindings)

gfredericks16:01:55

@mingp usually nontrivial macros are relegated to libraries

mingp16:01:21

In other words, you may need such things, but more likely someone else out there has already written it for you?

gfredericks16:01:40

"need" is a strong word, but yeah

mingp16:01:58

Fair enough. Thanks.

mingp16:01:57

I was always confused to hear that quote, from Paul Graham if I recall correctly, about the original Viaweb Lisp code-base being some double-digit percent macro implementations.

gfredericks16:01:19

some people get really excited about writing macros

gfredericks16:01:34

I suspect because they've never inherited a codebase from somebody who got really excited about writing macros

mingp16:01:08

I did have a "OMG! Macros are great!" phase in university.

sveri16:01:49

+1 for clojure.test and its integration into clojure. Also there is test-refresh for rerunning tests on file change. And +1 for cursive and all the reasons @tbaldridge stated a IDE is good for 🙂

mingp17:01:23

How is Counterclockwise these days, out of curiosity?

mingp17:01:35

I liked it in the past, but never had the chance to try it recently.

sveri17:01:12

Good question, I have used that in the first months when learning clojure, it was pretty good back then already. There is even a "standalone" version.

fabrao17:01:27

Is there any way to test structure with expect testing lib? Like

(expect {:jitter number? :packetloss number? :latency number?} (icmp ""))

fabrao17:01:22

I see the others libs have more "tools" to validate something like this, see in midje

(just {:jitter number? :packetloss number? :latency number?})

fabrao17:01:49

is that in the same way with clojure.test?

notanon17:01:08

whats just asserting? that those keys are the only keys and/or they're all numbers?

fabrao17:01:57

my needs is just check structure keys and if values are numbers

fabrao17:01:09

I had to do something like this

(expect (set [:jitter :packetloss :latency]) (set (keys (icmp ""))))

notanon17:01:42

thats what i was going to suggest, test the keys and then test the values

notanon17:01:58

i'd look to clojure.spec though

notanon17:01:09

not something i would unit test

notanon17:01:26

thats just me personally tho

sveri18:01:34

I guess thats exactly one of the things spec is good for

notanon18:01:44

after hearing rich, alex and stu say so many times that you should separate testing keys from values

notanon18:01:53

i can't think of it any other way now 🙂

notanon18:01:18

makes so much sense once it's pointed out

fabrao18:01:29

but clojure.spec isn´t still beta?

notanon18:01:51

alpha i believe

fabrao18:01:27

sorry , alpha, so are you using it in production ?

notanon18:01:47

i'm not saying you should use it, that's up to you.

notanon18:01:53

the thing about spec tho, you don't use it in prod

notanon18:01:05

you use it during development

fabrao18:01:18

hum, understood

notanon18:01:26

but i dont want to divert you from your goals... dont get distracted just because of me 🙂

notanon18:01:42

i use spec to help model my business objects

notanon18:01:46

and generate sample data

fabrao18:01:53

well, I see there are not complete testing lib, you need all of them and none of them 🙂

henriklundahl18:01:01

@fabrao, you can do e.g. (expect (more-> number? :jitter number? :packetloss number? :latency) {:jitter 1 :packetloss 2 :latency 3}) with expectations.

sveri18:01:29

@fabrao I think WorldSingles where @seancorfield works is pretty famous for running clojure alpha versions in production since years. And I would bet there are more. Which says a lot about the quality of clojure. Before spec I used schema or core.typed for validating the shape of my data, but since spec came along I switched and cannot complain so far. There were some minor API changes in the versions between alpha1 and the current alpha, but thats expected I would say.

notanon18:01:31

@sveri i've been doing a lot of JS work the last 4 or 5 years... and coming from such an undisciplined, constantly churning, etc ecosystem to the clojure ecosystem is so great. the constant focus on stability and reliability and ...professionalism is so refreshing i can't even think of other languages anymore. when i look at all the changes to JS standard with ES2015 and 2016... it's completely untenable for professional development (IMHO)

sveri18:01:11

@notanon I cannot say much about the JS ecosystem. I go there from time to time to see what its all about and am totally amazed about basically everything. You can start a new project every 6th month and be presented with new "best practices" 😄 I code daily with Java and have to say this is similar to clojure, so I am kind of accustomed to that quality and I think you can feel that Hickey has a professional background and also almost every other clojure library maintainer that I can imagine. Also its the same for clojurescript, it has only become better. I can not think of a single change that was making things worse 🙂

mingp18:01:00

Oh, yes, I've definitely experienced JS ecosystem churn at my job. One of the biggest pains in using a bleeding-edge ES-whatever to ES6 transpiler is getting all the rest of your tooling (testing, code coverage, etc.) to play along nicely. On one hand, lots of nice shiny new stuff. On the other hand, major growing pains.

sveri19:01:11

Yea, I think about playing screeps from time to time, but the thing that keeps me away is that I have to code in javascript -.-

notanon19:01:42

make a CLJS binding for us 🙂

sveri19:01:46

I tried when it came out, but did not succeed because of my lack of understanding of commonjs and how it works with cljs or not. Maybe things are different now.

notanon19:01:38

did you see david nolan's gist about latest CLJS being able to generate your externs file for you?

sveri19:01:47

Yea, I read that

notanon19:01:50

i've been looking for an excuse to try it out

sveri19:01:08

Well, the screeps simulator is free 😉

notanon19:01:54

i backed the indigogo campaign a couple years back... havent even played since then 😞 anyway... i think we're #off-topic 🙂

seancorfield19:01:52

@fabrao: we have Clojure 1.9 Alpha 14 in production right now. Rock solid. And heavy use of clojure.spec in several of our apps.

seancorfield19:01:42

We first took Clojure to production in 2011 on 1.3 alpha 7 or 8. We've run alphas and betas in production ever since.

seancorfield19:01:26

There were a couple of performance regressions along the way, and a memory leak once. That's been about it.

fabrao19:01:31

ok, I´ll give a try about spec, thanks a lot

notanon19:01:13

@seancorfield do you use spec at production runtime? what do you use it for? conforming?

seancorfield19:01:39

There's a backport library for 1.8 if you're really too nervous about the alpha (but, frankly, I'd rather trust the official alpha than a community backport).

seancorfield19:01:09

We use spec heavily for validation and conforming input data. In production.

seancorfield19:01:01

We only use it a bit for testing right now. Plan to expand that in the coming months -- I need to do some work on Expectations to make that easier.

seancorfield19:01:48

BTW @fabrao you probably want more-of in expectations which lets you do destructuring and "expect" predicates on components of data structures.

seancorfield19:01:07

Or use clojure.spec of course simple_smile

notanon19:01:38

do you use spec validation at only the api boundaries? or just any function that would benefit?

notanon19:01:48

or something else

qqq19:01:31

are there actual bugs when using macroexpand-all within another macro's compile time evaluation -- or is it just hard to get right?

seancorfield19:01:11

@notanon: right now we use it primarily at system boundaries (which is what Rich talked about when he introduced spec).

seancorfield19:01:13

We plan to start using it to describe certain internal data structures and add generative testing and instrument soon.

seancorfield19:01:35

Our codebase is very jdbc-heavy so a lot of side-effecting code that doesn't lend itself to that (generative testing).

sveri19:01:50

jdbc btw is one of the endpoints where I have every table defined as a spec in my current project

notanon20:01:36

@seancorfield @sveri good to know. thanks for the info. i've been trying to find the really great places to apply spec... without going crazy using something just because it's cool and new and fun

sveri20:01:20

For me it is almost exclusively about documentation. I am a spare time hobby clojure coder, so the code I write on never goes as deep into my memories as the one I work on 8h a day. It is very important for me to be able to recognize a datastructure as fast as possible without searching through several layers of functions or namespaces.

joshjones20:01:01

@notanon look no further than functions you already have (which ideally are referentially transparent) -- i've had several cases where I wrote a generator for a spec (or spec did it for me), and then found out that my function did not handle some corner cases.

fabrao20:01:11

silly question, how to check each element into collection ->

(expect ["1" "2" "3"] (in ["1" "2" "3"]))

fabrao20:01:34

I tried with from-each, but very confused

gfredericks20:01:41

(is (= [...] [...]))

fabrao20:01:04

but If the order is changed?

gfredericks20:01:15

(is (= (set coll1) (set coll2)))

gfredericks20:01:29

or frequencies instead of set if you want to count duplicates

fabrao20:01:45

is correct to use collection transform?

gfredericks20:01:03

...it works; not sure what other notion of correct you're interested in

pesterhazy20:01:10

using frequencies is genius 🙂

fabrao20:01:16

well, in midje I used contains to do this, but expect I see I have to transform all collections to set

fabrao20:01:41

to doesn´t matter order

gfredericks20:01:50

midje probably has fancy stuff that I don't know about

seancorfield20:01:04

If order doesn't matter you should probably already have a set.

fabrao20:01:50

LOL, I didn´t think about

seancorfield20:01:09

@sveri: re: spec'ing tables: you mostly need to ensure you're not trying to save additional keys (which jdbc will detect and complain about already) or data types (most of which jdbc will already either validate or conform for you).

fabrao20:01:25

I have to change my datastruct

seancorfield20:01:04

I might use spec to validate a domain model entity and conform it to a persistent model. That didn't provide as much value as I'd hoped last time I tried it tho'. Definitely getting more value out of input validation (and conforming to internal formats, from strings).

sveri21:01:32

@seancorfield Yea, thats true, but like I said above. Most of the usefulness of spec for me is documentation. Not having to open my .up.sql file is a win for me already.

sveri21:01:05

Btw. thanks for your jdbc library, I switched to it and prefer it to hugsql / korma and all the other stuff out there, its simple and easy to use.

lvh22:01:00

Is there something like a take-from, which is like drop-while with an inverted pred?

lvh22:01:20

I’m trying to say “seq of things after this object"

metametadata22:01:30

@lvh something like this?

(defn find-and-take-after
  "Returns the first found element and the seq of elements after it.
  Returns [nil _] if element was not found."
  [pred coll]
  (let [s (drop-while (complement pred) coll)]
    [(first s) (rest s)]))

lvh22:01:07

yeah that’s basically what I did; I was wondering if there was a thing in the stdlib that did that and I missed it

metametadata22:01:51

ah, right. that would be interesting to me as well

gfredericks22:01:57

I don't think so

Alex Miller (Clojure team)23:01:58

you can actually do it with the new halt-when transducer

qqq23:01:13

for list -> vector, I have vec . For vec -> list, what is the fastest way to convert?

Alex Miller (Clojure team)23:01:00

[aside, maybe you should not bother doing that… :)]

Alex Miller (Clojure team)23:01:17

not sure what the fastest way is without testing, but you can apply list

qqq23:01:26

I need to, as a result of (1) a pattern matching library I wrote and (2) loop/recur, where I can "rest", which convets the vec to list after the first one

Alex Miller (Clojure team)23:01:05

(list* [1 2 3]) ;; (1 2 3)

Alex Miller (Clojure team)23:01:33

my suspicion is that that’s prob your best option