This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-30
Channels
- # babashka (1)
- # beginners (86)
- # boot (5)
- # calva (21)
- # cider (26)
- # clj-kondo (10)
- # cljs-dev (5)
- # cljsrn (3)
- # clojure (181)
- # clojure-europe (22)
- # clojure-germany (11)
- # clojure-italy (3)
- # clojure-nl (7)
- # clojure-spec (6)
- # clojure-sweden (6)
- # clojure-uk (65)
- # clojuredesign-podcast (1)
- # clojurescript (71)
- # core-logic (2)
- # cryogen (15)
- # data-science (9)
- # datomic (7)
- # duct (4)
- # emacs (4)
- # events (1)
- # exercism (1)
- # fulcro (136)
- # funcool (1)
- # joker (6)
- # kaocha (3)
- # lambdaisland (28)
- # lumo (3)
- # malli (5)
- # mount (1)
- # off-topic (13)
- # re-frame (14)
- # ring (10)
- # shadow-cljs (20)
- # sql (5)
- # tools-deps (5)
- # tree-sitter (1)
- # uncomplicate (9)
You can even instrument in production, the only reason to not instrument is performance. So if you're not concerned about that, you could choose to have things instrumented all the time.
Another reason: if you have a higher order function, instrumentation will perform generative testing...
spec
: How important is it to a n00b, really?
@jings.bill Clojure existed for many years without it, but I think it's something that is important to learn.
I resisted learning it for a couple of years, because I was too busy learning everything else. When I finally did, it seemed quite trivial to integrate into my mental model. (And very much worth it š)
Whatāre the payoffs? (From where I stand here, the #1 payoff seems to beā¦ grokking error messages!)
Having descriptions of your data structures. Being able to validate data against such descriptions. Being to able to generate examples of your data for testing.
I wrote about our use of Spec at work last year https://corfield.org/blog/2019/09/13/using-spec/
Interesting. Validating doesnāt seemā¦ super interesting to me right now, except as it relates to another sort of basic question bumbling along in my head, which isā¦ how best to represent data in Clojure When I started working on the back end of my little toy Clojure project, I jumped to thinking, āOkay, what sort of entities will I have in this, and what sort of data will they have?ā And I looked in the Clojure toolbox and it seemed like Record gave me the sort of thing I was looking for now, the more I play around and look around the ecosystem, the more it seems like my choice is a little odd, and doesnāt actually achieve much. but I still think to myself: āhow am I not going to drive myself insane with loosy goosy untyped hashmaps and lists flying aroundā (because I was scarred at an early age by making a right mess of things in python)
Exactly my feeling! Especially because in python I was walking away from passing dictionaries around towards using named tuples or data classes. Bit counter-intuitive that Clojure seems to be pushing you in exactly the opposite direction š
Right. But if you cross the line to using Record like a named tupleā¦ you actually find that, unlike in Python, the Record doesnāt give you any new sugar. So why bother?
and it seeeeems like it may be the case that spec is in fact a clojure-y answer to my concern here?
Hello, I just tried to use the command line tools clj
and clojure
with a deps.edn
file instead of what I have been using, which is Leiningen. My installed tools are missing clj
and clojure
doesn't seem to work. I get:
clojure -Sdeps
Execution error (FileNotFoundException) at .FileInputStream/open0 (FileInputStream.java:-2).
-Sdeps (No such file or directory)
Full report at:
/tmp/clojure-14940499844028101044.edn
I'm running Kali linux and lein seems to continue working just fineI also tried installing the tools using the script at http://clojure.org, but those seemed to suffer the same problem(s) and I don't see any further documentation about what I might be missing
@beamjack Sounds like you might have some old, unofficial clojure
script installed earlier?
I thought probably the package is not kept up to date or something like that, but surely the install script from the getting started guide should have worked?
$ more `which clojure`
#!/usr/bin/env bash
# Version = 1.10.1.507
set -e
function join { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
# Extract opts
print_classpath=false
what does that command show for you?oh I think I know what it is. I had installed via the script to a different prefix, and then tried to use clj
which would not have used my prefix when invoking clojure
it was invoking the packaged/incorrect clojure
at /usr/bin/clojure
yep:
# more $(which clojure)
#!/bin/sh
if [ "x$CLASSPATH" = "x" ] ; then
extra_classpath=""
else
extra_classpath=":$CLASSPATH"
fi
while true ; do
case "$1" in
-cp | -classpath)
extra_classpath=":$2"
shift 2 ;;
--)
shift
break ;;
*)
break ;;
esac
done
if [ "x$1" = "x" -a "x`which rlwrap`" != "x" ] ; then
rlwrap="rlwrap -r -c -C clojure -f /etc/rlwrap/clojure1.10 -b (){}[],^%
\$#@\"\";:''|\\"
fi
exec $rlwrap java -cp /usr/share/java/clojure-1.10.jar"$extra_classpath" clojur
e.main "$@"
Yeah. And it seems like type-based dispatch is a less frequently used tool in the toolbox than Iām used to from previous experience
I havenāt needed it so far and I donāt think I will need it in this project. although weāll see
@jings.bill I tend to use records with protocols, if I want type-based dispatch and/or more performance than multi-methods.
But otherwise hash maps are the go-to data structure for most things.
Cool. And spec gives me the ability to document and enforce expectations for hash maps, as well as other higher level functionality built off those expectations
That is in line with my impressions, but clarifies the whole ecosystem a bit. Thanks!
Does reitit offer a way to capture params that are multiple path parts?
Specifically, I want to capture a path param like
/path/{rest/of/the/path}
I don't know what syntax reitit uses but in compojure that would just be /path/:stuff
and then you'd have that all in stuff
(and you can use regex to specify a pattern if you want)
I tried that, but reitit only supports a non-slashed string in that slot
Digging into the source, I think there's support for a /path/{*path}
that'll make it available under path
confirmed.
@seancorfield I feel like you're always on here when I'm struggling through some after-work project and I just wanted to say thanks š
I'm on Pacific time so I'm the last one to go to bed in America! š
I've got to look at reitit some time. I see a lot of folks asking questions about it and I don't know the answers.
the reitit route-syntax is defined here, for future reference: https://cljdoc.org/d/metosin/reitit/CURRENT/doc/basics/route-syntax
Hello guys. Do you have any recommendations for links for beginners to learning clojure ?
Hey, I guess you mean for learning Clojure in general? I really enjoyed https://www.braveclojure.com
If you do all the Elementary and Easy it will be a good basis, all of Medium is good.
I have also been using the mentored track at http://exercism.io and it was quite good
Always have a REPL open to test commands when starting out. The interactive feedback loop from programming with a REPL is where lisps derive much of their effectiveness.
I have an if statement with three conditions, is there an easier way to have these three conditions evaluated than wrapping them with two 'and's?
Could every-pred
be what you are looking for?
https://clojuredocs.org/clojure.core/every-pred
Every-pred
is not just for sequences?
user=> ((every-pred number? even?) 2)
true
user=> ((every-pred number? even?) 3)
false
user=> ((every-pred number? even?) "2")
false
and
can take more than two things.
(and nil false false nil 2)
returns 2.
@U883WCP5Z (and nil false false nil 2)
returns nil
and
returns either the first falsey value it encounters or the last truthy one
Oops sorry the example was for or
. And would look like this:
(and 1 2 3 4 5 5 nil)
returns nil
I realize that I might have misunderstood what you asked for, but if you want a "three way if", there's cond
(defn describe-apple-arity [n]
(cond (= n 0) "Zero apples"
(= n 1) "One apple"
(= n 2) "Two apples"
(< 2 n) "Many apples"
:else "Sorry, I don't know how to describe that"))
Always have a REPL open to test commands when starting out. The interactive feedback loop from programming with a REPL is where lisps derive much of their effectiveness.
I am trying this code: (str (take 5 "1234"))
and getting "1234"
How to make the string to wrap around if taking more than it contains?
Howdy y'all what is best practice when dealing with side effecty things. Do try & catch ? For instance i'm using clj-http and i have try catch around each http call which doesn't feel right.
is there a convention (or doc?) which specifies how to name memoized and non-memoized versions of a fn?
iāve seen foo
and foo*
often, but nobody mentions it in any style guides that Iāve found
foo
and foo*
I have often seen as foo
being the normal published API, and foo*
is some implementation function/macro that does most of the work.
I have not personally seen that naming convention used for memoized vs. non-memoized versions of a function, nor any other convention that relates those two things.
If the memoized version was something I wanted to call out as the unusual version of a function, because of the memory usage it can incur, I would probably use the name of the unmemorized function appended with -memo
or similar.
Hello! I asked this question over at Clojureverse https://clojureverse.org/t/library-stack-for-isomorphic-webapp-these-decisions-make-me-feel-at-sea/5651. Iām stuck in a kind of stack anxiety state, where Fulcro seems nearly overwhelming in its complexity and the suite of concepts needed to even navigate its example code (even with the amazing fulcro-rad-example), but Iām worried I might be setting myself up for needless complexity if I start with something like just rum, then add citrus for state management (regardless of whether I start with an SPA or server side stuff) and slowly build up and add libraries as needed. Eventually the thing I want to build will be a PWA, but I like the whole idea of progressive enhancement and an isomorphic development model. Any advice is appreciated, even if itās just āgo study fulcro moreā.
donāt be hard on yourself. Fulcro is great UI/state-management library, but it is NOT the way most of Clojure projects are written
if youāre new to Clojure and to Fulcro it will be hard to learn, at this stage Fulcro may not be worth it
Reagent/Re-frame or, mentioned by you, Rum/Citrus are good choices, that are less way complicated and have smaller learning curve
DataScript is nice, but also, NOT a must-have. itās great for querying data, simplifies data modeling if you know how to use it, but itās slow when you have a lot of data. You can build big, nice, performant application without it
Iād say, if you have to choose between Fulcro and Rum and youāre just learning, go with Rum. Itāll be way easier to have application running and learn step-by-step. When you use Fulcro you have to know it all, or it wonāt make sense. Itās a long, interesting journey, but maybe for later. Rum is nice choice, you wonāt be disappointed
lastly, if you go with Rum, or Reagent, more people will be able to help you, because more people understand how those work and itād be way easier to communicate with others about problems you approach, when building your app
thanks so much for this reply! this is kind of what I think Iām going to do. Iām not new to clojure exactly; Iāve worked through all of yogthosā Web Dev book so Iām familiar with reagent/reframe. I saw Fulcro as having most of the sort of nice-to-have affordances for what I want to build, but maybe starting simpler is the way to go.
Itās one of those situations where if someone had taken me aside when I started building apps in Angular and said hey, learn redux or something like it before it all becomes an imperative mess, I might not have believed them until I found myself in said mess without the luxury to just refactor. So my real worry is that Iāll end up building my own Fulcro. But by then if thatās the problem, then thereās a really easy solution, I suppose.
If you end up in a situation where you build your own Fulcro thatās gonna be really lovely problem to have š and if that happens to be the case, youāre gonna know why, exactly, you need Fulcro, so it should be easier to learn it
AFAICT, a pwa doesn't need to be isomorphic or requries a spa, so if you remove those two your complexity decreases a lot.
I wouldn't dismiss a RDBMS, datomic is nice but it assumes you are experienced and know what you are doing enough to avoid having corrupt data.
I know it doesnāt have to be isomorphic, I just wish there was a kind of progressively-enhanced story for development. I mostly work on a game-like education app thatās an SPA/mobile app, so I donāt know much about the PWA story without it first being an SPA.