This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-04-02
Channels
- # asami (5)
- # aws (16)
- # babashka (41)
- # babashka-sci-dev (44)
- # beginners (157)
- # biff (3)
- # cider (1)
- # clj-commons (1)
- # cljdoc (22)
- # clojure (7)
- # clojure-dev (5)
- # clojure-europe (13)
- # clojure-nl (1)
- # clojure-uk (1)
- # clojurescript (17)
- # core-typed (13)
- # cursive (14)
- # datascript (10)
- # events (1)
- # fulcro (2)
- # graalvm (2)
- # gratitude (1)
- # jobs (3)
- # lsp (229)
- # pathom (2)
- # pedestal (3)
- # portal (53)
- # re-frame (7)
- # remote-jobs (1)
- # spacemacs (14)
- # xtdb (6)
Anyone know of good no-frills guides for getting a minimalist ClojureScript project up and running from scratch, that integrates well with IntelliJ/Cursive? I've been out of the CLJS game for a while and frankly what's out there from my searches is pretty confusing to me. I'd prefer to take a deps.edn
and/or shadow-cljs
route if feasible. Ultimate goal is to get a Reagent site going, if that changes anything
Nope, sorry, no idea about cursive. I do use https://github.com/bhauman/figwheel-main-template to generate a deps.edn project with ClojureScript and reagent. It's all I've needed so far. Haven't found the time to study the detailed shadow-cljs guide yet
hey guys, i'm looking for a better way to program clojure, interested in using it in a part of my company's streaming pipeline in my downtime, but i'm an acme user that writes primarily go (ocaml, rust and chicken scheme too) and the experience has been excruciatingly painful so far, was just giving cursive a shot with ideaj but it's super overwhelming, would anyone recommend sticking it out or should i try something else? can't really use vim due to lackluster colemak support, don't use emacs, etc...
If you can help us understand what you find painful, we should be able to help you better. What is bothering you the most?
So with my go/chicken/ocaml, I have keybinds set up to very quickly get information about libraries, etc, and I've memorised the standard libraries for the two, with clojure I know F all, and am wondering if there's a better way to build programs using it instead of “writing, running the build process” without any type info, documentation, etc
Whether there's a way to quickly use the repl since I don't have that type safety the other languages afford me
using acme for everything across the board, having code that looks for file changes and recompiles is super ez, since i'll know with the type system most of the time whether something went south, that's not including using LSP though, i haven't found the tooling mature enough to use it for anything and i cbf patching it up
So how do you use the REPL currently?
Ideally, most of us have the repl hooked up to the editor and evaluate code from within the editor without switching over to the repl
there's a program someone has written which lets you port over stdin to a repl running with lein, but i haven't found that very stable so far
for instance, i am on VSCode, and I’ll type in (+ 2 3)
for instance and hit alt-enter
that will evaluate and show me the evaluated result in the editor itself
nice, would appreciate someone sharing a screencast of them doing some development in a more "interactive" environment that's not revolving around build and pray
Build and pray is not what we do. If you are doing that, then clearly something is wrong
the screenshot above is from within my editor where you can see I’ve evaluated some arbitrary code
is there any way to quickly get a TLDR of something similar to this in a command line tool in simple text hooked up to a pager?
This is of course possible with Cursive
you only wish to use Acme?
I am not sure how much Clojure support is available in Acme.
and nah open to whatever just found it a wild and whacky experience ideaj + cursive, like off the bat opening up a project doesn't create any clojure files and i can't even see how to make one
Have you used intellij before?
Then, you’re probably fighting too many things
Is there any reason for the hurry? My recommendation is to slow down and take your time learning things
this isn't the first time playing around for me and this time thought it made sense to ask
Playing around is one thing
but using it in a systematic way to build is another
Yes, that would be useful indeed
Do watch that video shared above
The build tooling…I am not sure that’s the place I’d begin mucking around with
There is also Eric Normand’s set of courses
having something that lets me use external libraries like code to take stuff off our queue would be a good place to start for me, that way i can work on my goal
That does sound ambitious. Best of luck.
@U039WAHFF4L I use Rebel Readline if I'm doing some quick experiments https://practical.li/clojure/clojure-cli/repl/ Although the vast majority is via an editor. There are many to choose from that support Clojure well https://practical.li/clojure/clojure-editors/
Here is a succinct demo by @U0ETXRFEW of “the idiomatic Clojure interactive workflow” using Visual Studio Code with Calva. Even if Visual Studio Code is not your default/preferred editor, it is arguably the quickest and easiest way to get up-and-running and familiar with Clojure. Then you can apply what you've learned in your preferred editor afterwards. https://youtu.be/d0K1oaFGvuQ
![calva](https://emoji.slack-edge.com/T03RZGPFR/calva/dd3c8169a48a7e4a.png)
![clojure-spin](https://emoji.slack-edge.com/T03RZGPFR/clojure-spin/aea1be92af1f8856.gif)
I'd also recommend running Calva's Getting Started REPL. It will guide you both in getting a nice REPL workflow and introduce you to the Clojure language as well.
cheers peeps, played around with cursive and ultimately got too frustrated with how it tried to be smart with the bracket matching and would refuse to close out (not allowing me to do it for me), while not reliably loading the file into the repl, so coming back before i take the leap and experiment with vsc, would anyone recommend a tool that could get me something similar to the following (this is how my code works here...):
aka simple command line tool that takes an argument of a package, then lists what's in it, without any fluff, i can wire that up pretty easily
Without meaning to sound overbearing or rude, I feel like you are trying to shoehorn your way of working instead of trying to understand how things are. Perhaps if you give it a fair shot without wanting it to work the way you wish for it to work might bring out the best out of the tools?
Honestly, VSCode or Cursive work perfectly fine
The bracket matching is often quite helpful and most of us usually leave it on.
Why not check out the video where @U0ETXRFEW explains his workflow?
surely there's a program out there that just lists what a package provides without any extra action, i'm willing to experiment with new tooling
cursive i found was buggy, i have lots of tools built into my current environment so i'd like to use it to benefit from thoes
All you wish for is something that autocompletes? Is that it?
ideally documentation that's easily queryable using a command line tool that produces simple text and a way to send information to a repl
if you are jacked into a REPL then simply typing in (doc name-of-func)
should get you some documentation
Documentation is often written as a part of the function definition itself and is queryable. It is merely data on a function or a var
for instance
(defn add "adds two numbers" [a b] (+ a b))
Then, add can be queried later on the REPL
okay so what you're saying is that to get documentation it would be better to query the repl
Look up `ns-publics)
The language is highly reflective
Data can be associated to a lot of entities, if not all and can then thus be queried
what i'm gonna do now is enumerate the available stdlib namespaces, pump them out into a file, have some code that gets that information very quickly into something i can use as a list, then that should be enough, cheers
Don’t run
I understand you have a plan
But my genuine advice is to go about learning the language first instead of fixating on your eventual outcome. My experience is that this approach causes a lot of people to flame out and give up
Clojure is genuinely different and takes a little getting used to
yea i get what you're saying, just for me to program i have to have tools to know what functions are available, ideally without asking google for help every two seconds, just trying to have a way to quickly get the names of what's out there so i can grep for what i'm looking for
for chicken scheme i have a huge list compiled by this one program that makes pressing command and / very easy to get that, then it goes deeper, i'll have a tool ready to query the repl in the future instead
appreciate the advice and am gonna play around with vsc next and the more standard workflows to experiment with the tutorials people have written then go from there
This is my VSCode setup
As you can see, I typed in the function map
and hovering my cursor on it immediately fetched me the doc
I am not sure if you really need to rebuild tooling just for your purpose. I believe that a lot of what you seek is already there
<looks around to see if somebody else can help me convey what I am trying to say. I feel like i am failing>
nah i get it, chats to the repl to use doc to get info on the function under the cursor, what i'm looking for is a way to get information like this very quickly, but this is fine since i can chain the question of what's available in a namespace with some scripting, would you recommend any way to get all the available namespaces at a point in time?
aka i can just search the list and it fuzzy matches it and opens up documentation, so i'm 90% of the way through having something similar with what you just shared, cheers
all-ns
No arguments
(all-ns)
#!/usr/bin/env clojure
(defn -main "" []
(print 123))
(-main)
is there a better way to do this if i want to script around with it? to implicitly call the entrypoint?With acme I'd try to set up something to send a file or form over a socket to a running REPL process Same for doc for symbol at point, source for symbol, etc
Working in Clojure heavily relies on having a running REPL process and communicating with it. I recommend going over this section for useful references https://clojure.org/guides/repl/launching_a_basic_repl
#!/usr/bin/env clojure
(def format-module-name #(apply str % "/" %&))
(defn get-modules
"Take the namespaces available in the toplevel and return the functions
in fun formatted strings."
[]
(map
(fn [ns]
(map (partial format-module-name (ns-name ns))
(keys (ns-publics ns))))
(all-ns)))
(map println (flatten (get-modules)))
been golfing around for the last while, would anyone recommend a better way to write this?(defn get-modules [] (map (comp str symbol) (mapcat (comp vals ns-publics) (all-ns))))
No need to flatten
No need for format module either
Again,I recommend not building this up as a set of CLI utilities but as a set of dynamic functions invoked from the REPL
Yes. Me too
And send all this code to your running REPL instead of running a clojure process each time
If you are using VSCode or Cursive, you wouldn’t need to build all this tooling to begin with
There's also a bunch of existing tooling you can build on. For example, both calva and cider share back end code in clojure
So don't try to shoehorn clojure to work with acme like acme does things. Make acme participate in how clojure does things instead (if you insist on using acme)
so cause of the sequences, all of this is lazy til it hits the function with side effects?
thanks for your help guys, this works perfectly for me, got lein running as a server, now to implement some stuff to do exec, cheers
#!/bin/sh -e
alias exec_stdin="gonrepl -a :7182 2>&1"
get_namespaces() {
exec_stdin <<EOF
(map
(comp println str symbol)
(mapcat (comp vals ns-publics) (all-ns)))
EOF
}
doc="$(get_namespaces | dmenu)"
[ -z "$doc" ] && exit 1
echo "(clojure.repl/doc $doc)" \
| exec_stdin \
| PlumbAndClean "/clojure/doc/$doc/"
https://clojure.org/api/cheatsheet This is also a great way to explore the std lib. But yeah, if you can't get a repl driven workflow going with Acme where you evaluate expressions in your source code I think you might bounce off Clojure because that is why most of us are here almost. It is where a lot of the joy and flow comes from imo. That is why everyone is concerned about reiterating that to you.
A quick google search resulted in a couple of possible avenues to explore: https://github.com/mkmik/acmeclj and http://blog.mattyw.net/blog/2013/10/17/clojure-programming-in-acme/
regarding acme: I think the best bet would be to start a socket repl and use nc
to send code to it
# start the server in the terminal
justin@abjection:~$ clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"
Clojure 1.10.1
user=>
# send input with nc or any other cli program that writes to a socket:
justin@abjection:~$ echo '(+ 1 1)' | nc localhost 5555
user=> 2
user=>
^C
![clojure-spin](https://emoji.slack-edge.com/T03RZGPFR/clojure-spin/aea1be92af1f8856.gif)
@U051SS2EU this is perfect, thanks! I'm also trying to get an acme setup going, but what you provided is basically 99% there
I'm also planning to adapt the code from https://github.com/mkmik/acmeclj responsible for intercepting B2 clicks, and make it do echo '$selection' | nc localhost 5555
instead
this + starting the clojure
socket REPL in win
should get me an environment with an interactive REPL you can type in, and also a way to send code from any file into the REPL too
that's how it should be, awesome
https://clojure.org/reference/transducers says that transducers
> specify only the essence of the transformation in terms of an individual element.
How is it possible to use dedupe
in a transducer if transducers only look at individual elements? Dedupe needs to compare consecutive elements to do its thing. What am I misunderstanding here?
edit: nevermind, I see this is explained further in https://clojure.org/reference/transducers#_transducers_with_reduction_state
The missing part is "statefull transducer".
I see that. Thank you. This stuff is pretty hard to understand at first. Going to take a good bit of review to get the concepts to stick.
For some of us it is hard to understand at the upteempth time going through it. lol But I'll keep trying
Hello everyone, I'm currently working on my learning-project (basically a glorified CRUD-App), which i wrote in clojurescript. It's my first ever clojure/script app and I wanted to keep everything really simple. Therefore I decided not to use a database but store everything in a map wrapped in a reagent atom. I (naively) thought: at some point I will just write the map to disk to save my 'database'. I just realized that I cannot do this from clojurescript (for good reasons) so it looks like I need to set up some kind of clojure backend for the database. I'm in need of some guidance how to do this. I'm currently using figwheel-main for the reloading and deps.edn for dependencies. I'd like to avoid using leiningen, since I'm used to deps.edn now. I looked around for good tutorials but it's difficult since there are so many different libraries and combinations of tools people use. Can someone recommend a simple way to do this or a tutorial which is also keeping complexity to a minimum? Thank you!
@U0372PMDM60 just out of curiosity - if you don't have a lot of data and it's good enough to work only on your local machine; perhaps you can just 'save' the data to the browser localstorage?
This could be as naive and simple as:
;; write
(.setItem js/localStorage "db" (pr-str @db-atom))
;; read
(reset! db-atom (cljs.reader/read-string (.getItem js/localStorage "db")))
And if you do decide to go the backend route, most recommend starting small with ring
and maybe compojure
. Here is a short tutorial that could help get ya started: https://www.youtube.com/watch?v=M97jWSKoV3k
Thank you both! I thought about using localStorage. Since I planned extending it with a backend at some point anyway maybe it's just time to get into that. Thank you for the video link. Looks promising!
If you get more ambitious on the backend, this example app uses the same technologies and goes more in depth: https://github.com/seancorfield/usermanager-example The author is very active on here (this whole community is quieter on the weekends just fyi).
Is there anything in clojure.core
like a atom
but which is not thread-safe? Like, sometimes if you want a local "atom", but don't want the overhead of thread-safety? (Assuming there is some overhead of synchronization)
volatile!
you should consider Box to be internal implementation, not public API
Or an array