This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-08-11
Channels
- # aws (2)
- # babashka (11)
- # beginners (107)
- # calva (6)
- # cljsrn (18)
- # clojure (180)
- # clojure-australia (6)
- # clojure-europe (54)
- # clojure-losangeles (9)
- # clojure-nl (4)
- # clojure-uk (13)
- # clojureladies (1)
- # clojurescript (57)
- # clojureverse-ops (1)
- # consultantsdirectory (1)
- # cursive (48)
- # datomic (11)
- # defnpodcast (3)
- # degree9 (1)
- # deps-new (5)
- # depstar (21)
- # docker (2)
- # fulcro (15)
- # helix (32)
- # kaocha (1)
- # lsp (21)
- # malli (15)
- # meander (15)
- # news-and-articles (2)
- # nextjournal (1)
- # off-topic (42)
- # pathom (3)
- # podcasts (1)
- # polylith (73)
- # protojure (1)
- # re-frame (43)
- # reagent (1)
- # releases (1)
- # restql (1)
- # schema (1)
- # sci (1)
- # shadow-cljs (23)
- # spacemacs (7)
- # sql (5)
- # tools-deps (42)
- # vim (15)
- # xtdb (3)
I want to iterate over this map and run a function on each phone number... I have been trying it with doseq, but I keep running into errors. Any advice? (pretty new to clojure here). (Phone numbers belong to friends, blurred out in example code)
(defonce people (atom {"dane"
{:name "dane" :phone "+1######"}
"me"
{:name "me" :phone "+1#########"}
"john"
{:name "john" :phone "+1########"}
"steve"
{:name "steve" :phone "+1########"}
"anoushe"
{:name "anoushe" :phone "+1########"}
"dominique"
{:name "dominique" :phone "+1#######"}
"flynn"
{:name "flynn" :phone "+15555555555"}
"ted"
{:name "ted" :phone "+1########"}}))
get rid of the complication. make a function that does what you want on a single phone number and then figure out how to do it multiple times
(defn text [phone-number] (twilio/send ...))
and then (run! text (map :phone @people))
or (reduce (fn [text-results person] (conj text-results (text (:phone person)))) [] @people)
or whatever you need
@dpsutton You might have a slight typo (it's hard to read the example). Perhaps it should be (run! text (map :phone (vals @people)))
?
probably. i didn't pay attention to the shape very much and assumed it was a vector of maps. but yeah whatever the shape calls for
I am building a cli app, I can build a uberjar ok. But when trying to use lein-bin
https://github.com/Raynes/lein-bin
I get following error
> lein --version
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
Leiningen 2.9.6 on Java 17 OpenJDK 64-Bit Server VM
> lein bin
OpenJDK 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
'bin' is not a task. See 'lein help'.
Here is my project.clj
(defproject gen-types "0.1.0-SNAPSHOT"
:description "xyz"
:dependencies [[org.clojure/clojure "1.10.1"],
[clj-http "3.12.3"]
[org.clojure/core.match "1.0.0"]
[lein-bin "0.3.4"]
[tupelo "21.07.08"]]
:main gen_types.core/-main
:paths ["src"]
:repl-options {:init-ns gen_types.core}
:profiles {:uberjar {:aot [gen_types.core]
:main gen_types.core}}
:aot [gen_types.core]
:bin {:name "gen-types"
:bin-path "./bin"
:bootclasspath true})
Googling didn’t help. Any hints?@U01J3DB39R6 Essentially for the same reason these 0-argument calls work and return the values they do:
dev=> (and)
true
dev=> (+)
0
dev=> (*)
1
Hello!
Imagine I need to traverse a long sequence x
(e. g. all integer numbers) until I find a pair of elements with indices n and (n+1) such that there is a particular relation between x[n]
and x[n+1]
.
What is the preferred Clojurian tool for traversing such sequence with having access to both current and previous (or next) element?
I feel that I could do this with transducers, but maybe there are other constructs.
If I understand correctly, this can be implemented using the partition
function's step
argument. (https://clojuredocs.org/clojure.core/partition)
i would do
(let [xs (range)]
(loop [[x_n x_n1] xs
idx 0]
(if (f x_n x_n1)
idx
(recur (rest xs) (inc idx)))))
(->> (range) (partition 3 1) (take 5))
((0 1 2) (1 2 3) (2 3 4) (3 4 5) (4 5 6))
@U7ZL911B3 @dpsutton Thanks! Will try it out.
can anybody confirm whether Cursive is even supported/documented for Windows?
i am on about my 3rd day of trying to make Clojure work in windows with SOME kind of modern-ish workflow and I can't find anything usable
@davidkcaudill Have you asked in the #cursive channel where the author/maintainer @cfleming is and can respond?
nope, will do!
@davidkcaudill I pointed you at the #cursive channel on Monday 🙂
i probably just moved on to try one of the seven other semi-working things i've monkeyed with this week
my HOPE is that i can have roughly the same workflow on Mac and windows
The only way I've gotten "the same" workflow on Mac and Windows is to use WSL2 on Windows but YMMV.
emacs i guess?
(I have no idea how Cursive works on Windows with WSL2 -- VS Code has a really slick integration: it effectively runs nearly everything on WSL2 as a headless server and you have the usual slick UI on the Windows side that talks to it)
Emacs is... its own hill to climb... I used it on and off for twenty years but just got tired of dealing with its quirks (and switched to Atom in 2015, then VS Code a year or so ago).
yeah i am just trying to get to the place where i can spend the time learning the language
I like the VS Code syncs all of its settings and extensions across all your machines. So if I install something on the Mac, it appears on my Windows laptop shortly after, and vice versa.
is this Calva or something else?
VS Code handles all the sync on its own. I have Calva installed for all the code assist/static analysis. But we don't use nREPL at work so I have that disabled (and use Clover instead with a Socket REPL). For the vast majority of VS Code Clojurians, Calva is going to be all you need.
I didn't realize VS Code sync'd everything so well when I set it all up on my Mac so I'd taken careful notes about what extensions I installed and what settings I'd tweaked... then I installed it on Windows, signed into GitHub for the sync and... bingo! Everything just magically appeared on Windows, from my Mac!
ok, trying Calva now I guess.
There's a #calva channel (of course) -- and the Getting Started experience in Calva is really good! @pez has spent a lot of time and effort on that.
yeah these docs are tremendous
(just bear in mind timezones -- the maintainer of Cursive is in NZ and pez is in Sweden)
solo projects in both cases?
ok so one glaring thing missing in my onboarding to this language is expectations. I have worked a lot in REPL oriented languages(R, Python, PowerShell), but I don't know what to expect in terms of dev experience. Can I connect a REPL with a running process? how should i expect this process to be different than working on a compiled language?
I would expect clojure's repl to feel most like a shell. Other languages are usually built around notions of programs existing in files, so things like parsing, analysis, compilation/interpretation are often built around operations on files
but shells, as command line interfaces have semantics around interpetting/running a command at a time, and usually process script files as just one command after another
and while clojure is compiled, the unit of compilation is top level form (what you type into a repl) so it has more in common with that shell style execution
something to keep in mind is the jvm is multithreaded, so it is very easy to have multiple repls connected to the same clojure process, or to fire off other threads to do things in the repl (again more similar sort of to shells then a lot of languages with repls that don't have good multithreading support)
For instance, in a lot of powershell and R development, your commands are fed to an interpreter and it's easy to inspect a given object and determine what's in it...but also sometimes messy because of runspace surprises
Similarly, sometimes i have had to connect a Scala REPL to stuff like spark and poke around as part of debugging
Loading a Clojure source file == reading (string -> Clojure data) and evaluating each top level form, so identical to you typing it into a REPL
there is no interpreter (small lie, there kind of is for very simple cases but above is still true)
loading a compiled Clojure file is a bit different but designed to mimic the above in most respects
you cannot generally connect a REPL to a running process, unless that process was started with that intent (which is pretty easy to do). if you do connect, you are doing the same thing as above. vars can be redefined at the repl, allowing you to change the running program.
thank you! What's the most common way that people use the REPL to debug?
this is a large and highly varied topic :)
https://clojure.org/guides/repl/enhancing_your_repl_workflow#debugging-tools-and-techniques is a start (the greater guide that's in may lead you to other tools too)
In Clojure "debugging" and "programming" at the REPL are to a large degree the same thing rather than two topics
ok so what's the best way to inspect/reflect an object in the REPL? like in Python one would use dir(object)
I am seeing inspect()
recommended a lot but it doesn't work in REPL...which lead me down the rathole of how to add libraries to the REPL
What sort of "object" @davidkcaudill?
Clojure's data structures just print "as-is".
ow my brain
but essentially one would do this in other languages to learn the methods and properties of an object
I mean, we interop with Java objects from time to time, but Clojure doesn't really have objects -- just data.
and data has no methods or properties
Data is just data.
Or clojure.pprint/pprint
if you want the data laid out nicely.
type()
is helpful too
less than you'd think :)
(keys some-map)
might be helpful for you.
oh i like that one
yeah i generally need ways to poke/learn as i work, this is all helpful, thanks folks!
i am ok "trusting the process" with learning a language but i don't think i've ever felt like i suspended disbelief this long in order to learn one
it's gonna take me all week to get over this weird implementation of and
Clojure uses the Boolean operators or and and. or returns either the first truthy value or the last value. and returns the first falsey value or, if no values are falsey, the last truthy value.
logical false = nil | false logical true = everything else
ok but:
user=> (= false nil)
false
so nil is not equal to false, but both would evaluate to false in a conditional?
ok makes sense!
you can use the boolean
function to coerce logical boolean to actual boolean
other predicates of use: true?
false?
nil?
and this is probably a good time to point to https://clojure.org/api/cheatsheet
excellent thank you!
That is actually the case in many languages. Javascript does the same and if im not mistaken python too.
i can't vouch for JS but i can confirm that Python doesn't do this
(looking for the and)
ok so "first truthy" is a what i'd consider a common language pattern
but returning the LAST thing if it's not? that's peculiar to me.
and i guess the SRE half of me is mortified
@davidkcaudill
I just had a long-ass discussion about nil
in here just one or two days ago. And I think I finally understand what it means and why it is valuable to have it be falsy, what nil-punning is, why it is is there, why we use seq
to check if a sequence still has stuff in it, why there is a difference between rest
and next
. How certain functions flow nicely into each other like get
, nth
, if-let
, when-let
and so on. nil
is a value that signals “not there” or “end of line” and similar things in a given context. If that meaning has to break out of a context we have these wonderful things in keywords to communicate more.