This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-01-01
Channels
- # beginners (71)
- # boot (148)
- # cider (21)
- # cljs-dev (2)
- # cljsjs (35)
- # clojure (212)
- # clojure-russia (42)
- # clojure-spec (36)
- # clojure-uk (28)
- # clojurescript (18)
- # cursive (2)
- # datascript (20)
- # datomic (2)
- # hoplon (2)
- # off-topic (355)
- # om (2)
- # onyx (1)
- # protorepl (1)
- # reagent (34)
- # ring-swagger (6)
- # rum (8)
- # sql (4)
- # untangled (64)
- # vim (22)
- # yada (1)
@richiardiandrea TL;DR: "yes" in both but I'd have to go research the syntax 🙂
@seancorfield basically I'd need to append ::jsonb
to a (?)
In honeysql
, I'm pretty sure you can do something like [(sql/call :cast ...) :alias]
but I'd have to experiment
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.
Ohok, I will experiment don't worry, now that I know, I could not find it, BT maybe I haven't looked deeply
Yes I use raw usually for this, in let me try, thanks!
Normally in SQL you can do something like CAST( column AS type ) AS alias
Uhm, nice, I was focusing on postgres' syntax but maybe I can use the above instead
An example of call
to generate a cast
: https://github.com/jkk/honeysql/blob/d700034f62548e91a13509e383991fa80fd15a59/test/honeysql/core_test.cljc#L76
@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
actually I don't even need the above 😉 It can be simplified
to:
(defn valueify-map
[m]
(mapv (comp sqlf/value second) m))
and in honeysql
, the values clause becomes: (values (mapv valueify-map members))
Cool... functions and composability FTW again! 🙂
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)
~(name fst)
I think?
That will turn a symbol (or a keyword) into a string.
And then ~@(map name ages)
maybe?
(On my phone so can't verify. Hope that helps)
@seancorfield nevermind, found it.. ~'
does exactly what i want
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
?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.
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?
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 ?
@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.
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.
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])
But it feels weird to me to call symbol
for that purpose
I call also call read-string
...
What is the proper way of writing foo
?
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?wild guess: try to restart the repl
@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.
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" .
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
When I see that level of modification of my code, I get nervous.
@tbaldridge I saw many issues in github Issues, and now I´m worried about using it
sorry about my sillies questions, midje was the first testing framework I´ve been using
anybody experienced with https://github.com/ericnormand/squarepeg ?
@fabrao, you can also take a look at https://github.com/clojure-expectations/expectations.
Autotesting is available via https://github.com/clojure-expectations/lein-autoexpect.
@fabrao I use clojure.test. Expectations also seems pretty good, although I've never used it.
trying to capture the inverse of a rule but not seeing how that would work (like "[^0-9]" meaning a non digit)
@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.
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.
Many other editors have that feature as well ^^
@tbaldridge run-all-tests rerun all tests? Not only the test changed? I used midje because it´s IDE free dependency
@fabrao run-all-tests is part of clojure.test: https://clojure.github.io/clojure/clojure.test-api.html#clojure.test/run-all-tests
all the IDEs are doing is running those (and other functions) and then formatting the results
@credulous I said that because tbaldrige is using Cursive to do his tests
Yeah, Cursive is just pretty printing my test results
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
*keystroke
So you can say "when I press CTRL+t, dump (run-all-tests)
into my repl"
btw. @tbaldridge is there any special reason why you chose Cursive over CIDER?
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.
I mean the Cursive debugger, the static analysis, the (IMO) better platform of the JVM (vs a custom single-threaded VM of emacs), etc.
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.
@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 😄
but it’s true, emacs is nice and all but it can be really hardcore if something breaks
yeah, it does
@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.
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
@tbaldridge that’s not weird!
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?
I've wanted that a lot of times.
you can, it's just buggy
I think riddley attempts to provide a more reliable version
if you don't mind the dependency
But, at least theoretically, you do have the trees and what you do with them is up to you.
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
(!! (macro-blah blah a b) .... ) -- then I need to expand the (macro-blah blah a b) to get its arity
the most recent reason I wanted it was for http://dev.clojure.org/jira/browse/TCHECK-98
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
@henriklundahl I tested now with expectations and lein-autoexpect and it seems to working good
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.
@gfredericks have you looked into clojure.tools.analyzer for this?
@tbaldridge I judged it would be bad for test.check to depend on it
using
{:expectations-options :before-run}
for before and {:expectations-options :after-run}
for clean up, and running it just onceI know it's a bit heavy handed, but it would do t he trick
yeah I agree esp with spec these days
@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
Is it fair to say that this sort of thing is not typically needed in typical Clojure usage?
(provided an alternate syntax so users can opt-in to parallel bindings)
@mingp usually nontrivial macros are relegated to libraries
In other words, you may need such things, but more likely someone else out there has already written it for you?
"need" is a strong word, but yeah
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.
some people get really excited about writing macros
I suspect because they've never inherited a codebase from somebody who got really excited about writing macros
+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 🙂
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.
Is there any way to test structure with expect testing lib? Like
(expect {:jitter number? :packetloss number? :latency number?} (icmp ""))
I see the others libs have more "tools" to validate something like this, see in midje
(just {:jitter number? :packetloss number? :latency number?})
I had to do something like this
(expect (set [:jitter :packetloss :latency]) (set (keys (icmp ""))))
after hearing rich, alex and stu say so many times that you should separate testing keys from values
but i dont want to divert you from your goals... dont get distracted just because of me 🙂
well, I see there are not complete testing lib, you need all of them and none of them 🙂
@fabrao, you can do e.g. (expect (more-> number? :jitter number? :packetloss number? :latency) {:jitter 1 :packetloss 2 :latency 3})
with expectations.
@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.
@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)
@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 🙂
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.
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 -.-
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.
did you see david nolan's gist about latest CLJS being able to generate your externs file for you?
i backed the indigogo campaign a couple years back... havent even played since then 😞 anyway... i think we're #off-topic 🙂
@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.
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.
There were a couple of performance regressions along the way, and a memory leak once. That's been about it.
@seancorfield do you use spec at production runtime? what do you use it for? conforming?
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).
We use spec heavily for validation and conforming input data. In production.
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.
BTW @fabrao you probably want more-of
in expectations which lets you do destructuring and "expect" predicates on components of data structures.
Or use clojure.spec of course
do you use spec validation at only the api boundaries? or just any function that would benefit?
are there actual bugs when using macroexpand-all within another macro's compile time evaluation -- or is it just hard to get right?
@notanon: right now we use it primarily at system boundaries (which is what Rich talked about when he introduced spec).
We plan to start using it to describe certain internal data structures and add generative testing and instrument soon.
Our codebase is very jdbc-heavy so a lot of side-effecting code that doesn't lend itself to that (generative testing).
jdbc btw is one of the endpoints where I have every table defined as a spec in my current project
@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
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.
@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.
silly question, how to check each element into collection ->
(expect ["1" "2" "3"] (in ["1" "2" "3"]))
(is (= [...] [...]))
(is (= (set coll1) (set coll2)))
or frequencies
instead of set
if you want to count duplicates
...it works; not sure what other notion of correct you're interested in
using frequencies
is genius 🙂
well, in midje I used contains to do this, but expect I see I have to transform all collections to set
midje probably has fancy stuff that I don't know about
If order doesn't matter you should probably already have a set.
@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).
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).
@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.
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.
@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)]))
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
ah, right. that would be interesting to me as well
I don't think so
you can actually do it with the new halt-when
transducer
[aside, maybe you should not bother doing that… :)]
not sure what the fastest way is without testing, but you can apply list
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
or call list*
directly
(list* [1 2 3]) ;; (1 2 3)
my suspicion is that that’s prob your best option
@alexmiller: thanks