This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-04-22
Channels
- # announcements (1)
- # beginners (179)
- # boot (8)
- # calva (3)
- # cider (4)
- # clara (3)
- # cljdoc (31)
- # clojure (9)
- # clojure-austin (1)
- # clojure-chicago (5)
- # clojure-dev (19)
- # clojure-nl (2)
- # clojure-uk (1)
- # clojurescript (13)
- # core-matrix (1)
- # cursive (86)
- # datascript (2)
- # datomic (13)
- # emacs (3)
- # figwheel-main (1)
- # fulcro (66)
- # off-topic (250)
- # pathom (7)
- # re-frame (19)
- # reitit (5)
- # sql (37)
- # uncomplicate (5)
when I run the variant, the error I get is "error printing return value (ClassCastException)
variant should work. are you sure stringy is defined as ["100" "200" "300"]
and not, say, [100 200 300]
?
I was tearing my hair out - I had defined stringy in the repl but the last one had no qoutes apparently
well I'm certainly glad I came here, otherwise I would have continued pulling my hair out
you could capture the result of (all-ns)
before you load anything, then compare the old result with (all-ns)
after the load
e.g. (let [prior (set (all-ns))] (load-string "(ns foobar1) (ns foobar2)") (clojure.set/difference (set (all-ns)) prior))
hm, I can't think of a less complex solution. it seems fairly reasonable to discover the side effect of an operation by diffing before and after. I expect it's reliable for most use cases, though given it's an uncommon problem to solve
Hi all
If i want deep dive into clojure collection processing (map, filter, reduce, etc.) where would be the best place?
I'm aware with https://github.com/nathanmarz/specter, but i want to learn without external libraries
specter has nothing to do with sequence transformation, i'm not sure where to start with functional abstractions like that. For me it was java streams and common lisp fp course
@pythonjokeun https://en.wikipedia.org/wiki/Higher-order_function https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29 https://en.wikipedia.org/wiki/Map_(higher-order_function) https://en.wikipedia.org/wiki/Filter_(higher-order_function)
then a book maybe? Clojure for the brave and true, programming clojure 3rd ed, joy of clojure 2nd ed
Correct me if i'm wrong but functions like map, filter, reduce, etc can be used for data processing right?
@pythonjokeun yes, they transform data, in terms of clojure they implemented on top of sequences
there is also transducers, its more or less the same but transformation and step(iteration) being separated, that's more advanced topic
i see
consider reading this https://www.braveclojure.com/foreword/
i've already read that book, but still missing the functional thinking when it comes to complex data structure
Is there any link about transducers?
long story short, i'm a data engineer, heavy user of python pandas, and apache spark dataframe
when it comes to clojure functional data processing i'm totally blank 😂
@alexcatalina https://www.youtube.com/watch?v=6mTbuzafcII https://www.youtube.com/watch?v=4KqUvG8HPYo https://labs.uswitch.com/transducers-from-the-ground-up-the-practice/
Thanks!
@pythonjokeun practice i guess
@nxtk i guess so. anyway thanks for all the links. much appreciated!
@pythonjokeun that maybe helpful to visualize whats going on https://stackoverflow.com/questions/35150231/java-streams-lazy-vs-fusion-vs-short-circuiting/35157305#35157305
I've clicked file -> new -> project -> deps in cursive and its generated a file with
{:deps {}}
inside but cursive shows me this error:I have clojure up to date with
brew upgrade clojure
both clj and clojure work on the terminal they start a repl with the latest version
@nxtk thanks!
@nxtk if i ask about data transformation stuff in the future, in which channel should i drop my question?
cool, thanks for the help, much appreciated!
Is it possible to unwrap the vector of args passed to the add
function, namely colls
, and pass the contents as arguments to mapv
?
if that's the behavior you want, then maybe reduce will cope better with arbitrary numbers of colls
yes, you have to reduce it
Mind to have a look at my question on SO https://stackoverflow.com/q/55795010/8488828 ?
Debugging question: If you have a very complicated function, and somewhere along the pipeline, a function inside that throws an error, is there a handy workflow (that does not involve inserting println
everywhere) to see the intermediate input (to that internal function) that caused the error?
(def test-data
[{:id 35462, :status :completed, :p 2640000, :i 261600}
{:id 35462, :status :created, :p 240000, :i 3200}
{:id 57217, :status :created, :p 470001, :i 48043}
{:id 57217, :status :completed, :p 1409999, :i 120105}])
(defn merge-tasks
[[id [{p1 :p i1 :i :as task1}
{p2 :p i2 :i}]]]
(if (= (:status task1) :created)
{:id id :p [p1 p2] :i [i1 i2]}
{:id id :p [p2 p1] :i [i2 i1]}))
(comment
(into [] (map merge-tasks (group-by :id test-data))))
@tabidots as first step to debug a very complex function i would write spec and few tests if needed
cider can instrument your function call if i'm correct https://cider.readthedocs.io/en/latest/debugging/
due to functional\\lispy nature of clojure, i find myself barely using debugger if at all
@pythonjokeun Thanks, I had come across trace
before but couldn’t figure out how to use it. I just re-installed it in my project and still can’t get it working. I’m getting Can't dynamically bind non-dynamic var:...
Is there no convenient way to get a full trace output with a function that already exists?
I like using https://github.com/vvvvalvalval/scope-capture as an informal way of debugging the insides of functions
just stick a (spy)
form around any piece of code and you can retrieve the local context afterwards
@tabidots var is a static container by default, can't bind it unless it's a dynamic one, but i don't know how to make it so, except def ^:dynamic
@nxtk thanks again!
@didibus this is an implementation of the baby-step giant-step algorithm. I have a fn called baby-step-giant-step
(dotrace (baby-step-giant-step 11 7 11))
(dotrace '(baby-step-giant-step 11 7 11))
(trace (baby-step-giant-step 11 7 11))
(dotrace [^:dynamic baby-step-giant-step] (baby-step-giant-step 11 7 11))
(def ^:dynamic bsgs baby-step-giant-step)
(dotrace (bsgs 11 7 11))
(dotrace [bsgs] (bsgs 11 7 11))
These all either don’t work or don’t give me anything (just the same error, with no additional info). The last one gave me TRACE t4135: (bsgs 11 7 11)
which isn’t very helpfulBut it's possible trace is too old. It used to be Vars defaulted to being dynamic. And that changed. Maybe trace wasn't updated till then
I have tried
(deftrace [bsgs] (baby-step-giant-step 11 7 11))
(deftrace ^:dynamic (baby-step-giant-step 11 7 11))
(deftrace ^:dynamic '(baby-step-giant-step 11 7 11))
and I just get First argument to def must be a Symbol
I have no idea what the dynamic thing is btw, I’m just trying different things to get some resultSo I did
(deftrace ^:dynamic baby-step-giant-step [α β p]...
with the rest of the original function copied from after that point@nxtk i'm curious on how you approach data transformation problem in clojure :thinking_face:
is there an official book / guide for "Solving Data Transformation Problem, The Ivan Koz Way" ?
@qythium I will give scope-capture
a try. It seems a little heavy but if it works then it works
I've never used it myself. But it seems deftrace alone should have done it. Or you need to use trace-ns, that makes it so all fns in a namespace will trace their inputs and outputs.
@qythium scope-capture
brings back memories of pre 1.10 stack-traces 🙈 Well, it didn’t specifically tell me what the inputs were at the point where the error occurred, but it did at least pinpoint the source of the error. From there it was easy to figure out. Thanks!
app:threedays.core=> (for [x (range 5)] {:id x})
({:id 0} {:id 1} {:id 2} {:id 3} {:id 4})
i want to achieve this {:x-0 {:id 0} :x-1 {:id 1}...} how can i get my expected result
there are several ways you could do it, but reduce
is the most general and good to know
another common way is to build up a sequence of [key value] vectors and call (into {})
on it
How does one import a record in a different namespace while also requiring functions from that namespace?
(ns collijion.core
(:require [cljfx.api :as fx]
[collijion.planet :refer [update-planet]])
(:import [collijion.planet Planet]))
Tried doing this, but I’m getting errors in the repl when I try to eval this ns formnote that if the namespace has dashes in it they have to be replaced by underscores, that tripped me up in the past
@qythium thank you now i made this: (into {} (for [x (range 5)] [:(str "id-" x){:id x}]))
Hi! I'm reading about clojure spec and I see that you can use s/fdef
to validate args and your function's return value. You can also use :pre
/`:post`. I don't really see when you should use one vs. the other though. Is one more in favor over the other?
I think spec pretty much covers pre/post functionality. Spec came later in Clojure's evolution, so it's probably fair to say that favor is slowly gravitating towards spec/fdef for that. But it's not like pre/post will be deprecated, and you can build a pretty fancy contract system with just pre/post
a spec'd function is only checked if you turn instrumentation on
pre/post is also inlined with function definitions, where as specs can be applied at a later time
That’s the default behavior, there are libraries that add :fn
/`:ret` checks ^^
so is best practice to enable it by default and then disable it globally for prod environments?
For pre/post? I think the intention behind the design was to allow for both options. Some folks might want to use pre/post for runtime validation
I don't think you can turn it on or off on a per name space level though, which you can do it spec
another gotcha about fdef and instrument is that if one of the args is a function, multiple representative arg-lists will be generated and provided to that function, which in some cases could have very surprising results
With side effecting functions you mean?
right
any function with state, or which does IO
is there a way to get clojure.java.jdbc
’s with-db-transaction
to utilize an existing db connection pool as opposed to a spec?
I’ve got a component
system with a connection pool already instantiated. starting up another connection from a db-spec
over and over again just to perform the same transaction feels unnecessary to me.
am I missing something here?
you can use {:datasource p}
, it's a valid db spec
that’s exactly what I was looking for. didn’t realize what the syntax was. thanks for the help!
that keyword might be wrong, checking...
@mss I edited the above, the actual key is :datasource
http://clojure-doc.org/articles/ecosystem/java_jdbc/reusing_connections.html
I have been running into a lot of can't find class path errors. Has anyone else experienced this issue? I am on Linux.
@sotrhraven Can you provide a bit more context/detail?
Would anyone be able to direct me to some tutorials on web development in Clojure that are high-quality/recent? I've found some tutorials/walk-throughs, but I usually end up getting frustrated 40-60% through, because there's some error or hangup or hiccup (pun intended) that's not mentioned in the tutorial, and generally isn't very google-able if you will, and now I'm left with a bunch of half-baked code, or a half-baked app I can't really move forward with, or debug because I'm still in the trying to learn phase.
I have been using leiningen and nightcode. For example I added compojure to my project.clj and when I use it in my myweb.clj it throws a can't find compojure init class etc.
Did you restart your REPL to pick up the newly added dependency?
Can you share more details of your project.clj
and the actual error you are getting? And also exactly when you are getting it?
I could but I have nuked my lein and all associated folders. Going to go with fresh lein install and such. I thought maybe I had set something up. I can provide a project.clj one sec
(defproject myweb "0.1.0-SNAPSHOT" :description "FIXME: write description" :url "http://example.com/FIXME" :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0" :url "https://www.eclipse.org/legal/epl-2.0/"} :dependencies [[org.clojure/clojure "1.10.0"] [compojure "1.6.1"]] :repl-options {:init-ns myweb.core})
Common problems are typos in the dependency (in project.clj
) which would fail when Leiningen tried to download the library or typos in the :require
, such as using the artifact name instead of the namespace name.
I was using clojars
Your project.clj
looks fine so I suspect the error is in your :require
in myweb.core
...
(ns myweb.core (:use compojure.core) (:require [compojure.route :as route] [ring.adapter.jetty :as jetty]))
Finding a course I can afford that is not kind of old I am finding difficult. I use udemy, clojure is not a popular topic.
What you have above will produce this error Could not locate ring/adapter/jetty__init.class
because you are missing the dependency for the Jetty adapter in Ring.
(so the error is not for Compojure, but for Ring)
add [ring "1.6.1"]
as a dependency and it'll work.
(and I can tell you're following an old tutorial because :use
is considered bad practice these days)
cool will give it a shot.
will you give this a look I am going to give this a go later. you have been very helpful. you might save me the trouble of getting into this and getting frustrated.
It doesn't use :use
here https://github.com/practicalli/clojure-webapps-example/blob/05-compojure/src/webdev/core.clj#L2-L6 -- it looks nice and up to date. Even uses Clojure 1.10 and Ring 1.7.1. Nice and new.
cool, Thank you. 😊
Looks like the later part of the tutorial is older -- still uses 0.3.x version of org.clojure/java.jdbc
so that should all be updated (but it should work as it is -- as long as the code and dependency versions match).
So I will keep an eye on the dependencies matching. I was worried there could have been some name collisions in the .m2 folder that were causing the problem. But this is just better. need to be more vigilant.
@lorenzo.evans94 Have you looked at the Web Development book https://pragprog.com/book/dswdcloj2/web-development-with-clojure-second-edition
I haven't attempted it yet, I've been reading For The True & The Brave/Programming Clojure, but if you think it's worth it, I'll definitely pick it up.
Did you restart your REPL to pick up the newly added dependency?