Fork me on GitHub
#beginners
<
2021-01-06
>
Pascal02:01:19

I am a total beginner to programming so please excuse if this question is very rudimentary. I am beginning to learn Clojure using the book Clojure for the brave and true. I have successfully installed Java, Clojure, and Leiningen. The first step is to run lein new app clojure-noob When I do so I get the following response from my terminal Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release. Generating a project called clojure-noob based on the 'app' template. Could not create directory /Users/Pascal/clojure-noob. Maybe it already exists? See also :force or --force according to the book I should be getting a response as follows | .gitignore | doc | intro.md | project.clj | README.md | resources | src | clojure_noob | | | core.clj | test | | clojure_noob | | | core_test.clj Please any help would be appreciated. I am really excited to begin my coding journey.

andy.fingerhut02:01:28

You can ignore the "were deprecated" warning line, I think. Should be harmless.

andy.fingerhut02:01:17

The "Could not create directory ..." message I can only reproduce if I do the command twice -- the first time it succeeds, the second time it gives that error because the directory was already created by the first time I ran it.

andy.fingerhut02:01:29

I would suggest checking to see if there is a clojure-noob directory, and if there is, delete it. After you have confirmed you have deleted it, try the lein new app clojure-noob command again.

Pascal03:01:02

Thank you, not sure if that is because even try to create a file with a different name it says could not create a directory maybe it already exists

seancorfield04:01:32

Perhaps it is a permissions issue and for some reason you don't have permissions (in your home directory?) to create new files. Are you on macOS or Linux? And what version of macOS? (they've been making it increasingly unfriendly to developers lately, IMO)

salam06:01:49

welcome to Clojurians, @U01JFA3F1A5! 🙂 judging by "/Users/Pascal/clojure-noob", you must be on macOS. in your home directory (which is "/Users/Pascal"), execute the following command and report back what you get in the output: lein new app clojure-noob --force && find clojure-noob

🙏 3
salam07:01:25

you should hopefully get an output that looks like the following and if you do, congratulations, you did it!

Generating a project called clojure-noob based on the 'app' template.
clojure-noob
clojure-noob/project.clj
clojure-noob/README.md
clojure-noob/doc
clojure-noob/doc/intro.md
clojure-noob/.gitignore
clojure-noob/.hgignore
clojure-noob/src
clojure-noob/src/clojure_noob
clojure-noob/src/clojure_noob/core.clj
clojure-noob/test
clojure-noob/test/clojure_noob
clojure-noob/test/clojure_noob/core_test.clj
clojure-noob/LICENSE
clojure-noob/CHANGELOG.md
clojure-noob/resources

Christian09:01:28

@diego559 If you have more questions, you can also consult #adventofcode

Christian10:01:25

Is there a shorter way to write this? I know there is the & operator that gives all the rest of a list, but I cannot get it to work. Also google is really bad for the search of a single character

(->> (number-formatter "1234567890")
     (apply #(format "(%s) %s-%s" %1 %2 %3))) ;; &% instead of %1 %2 %3?

Max Deineko10:01:34

%& should do it

noisesmith15:01:58

to be clear there are no operators in clojure, & is a destructuring syntax, and %& is a magic symbol inside #() that is translated into a destructured binding

👀 3
noisesmith16:01:14

(I call it magic because % tokens inside #() don't even follow normal parsing rules)

caumond10:01:07

Hi, shouldn't you replace the #() form with a (fn [& args) (apply format "(%s) %s-%s args)

caumond10:01:53

I'm not sure to know what is number-formatter

Christian10:01:15

custom funtion, that returns a list with three elements

Christian10:01:11

I never think of the fn and always do #()

Christian10:01:23

I'll try this

caumond10:01:56

(defn number-formatter[str] (list 1 2 3)) (->> (number-formatter "1234567890") (apply (fn [& args] (apply format "(%s) %s-%s" args))))

caumond10:01:12

it works here: "(1) 2-3"

Christian10:01:51

Hm. Not sure if this is prettier:

(apply #(format "(%s) %s-%s" %1 %2 %3))
or
(apply (fn [& args] (apply format "(%s) %s-%s" args)

caumond10:01:18

I must confess I share your point

caumond10:01:38

another way is destructuring

Christian10:01:46

I'm surprised there is no &% that I can just use to throw everything in that migth come.

euccastro16:01:13

you already found a better solution, but fwiw there's such a thing, just spelled backwards:

user=> (#(apply + %&) 1 2 3)
6

✅ 3
Christian10:01:59

(apply format "(%s) %s-%s")

Christian10:01:31

Now it's pretty. Thanks for the input, it made me think about what apply does

caumond10:01:43

ah ok, I was wondering why you have that first level of apply

caumond10:01:30

I understand now

roelof11:01:45

What the hell does the brave book wants me to do here :

You used (comp :intelligence :attributes) to create a function that returns a character's intelligence. Create a new function, attr, that you can call like (attr :intelligence) and that does the same thing.

roelof11:01:53

this is the example

(def character
  {:name "Smooches McCutes"
   :attributes {:intelligence 10
                :strength 4
                :dexterity 5}})
(def c-int (comp :intelligence :attributes))
(def c-str (comp :strength :attributes))
(def c-dex (comp :dexterity :attributes))

(c-int character)
; => 10

(c-str character)
; => 4

(c-dex character)
; => 5

roelof11:01:39

so it looks to me I have to write a function that takes out a attribute and prints it Am I right ?

Mno11:01:00

"Create a new function, attr, (...)" means that it wants you to create a new funciĂłn with the name attr

Mno11:01:15

My best guess is that's is the problem

Mno11:01:15

so you have (c-int character) that takes a character and gives you that character’s intelligence

Mno11:01:24

now it’s asking for you to make a function attr that takes the keyword of the attribute :intelligence and returns that number (attr :intelligence) => 10

Schpaa11:01:58

@roelof: perhaps it wants you to parameterise one of the elements in the comp function (without giving the answer away)…

Old account11:01:18

is compojure, reitit and pedestal same sort of thing?

Schpaa11:01:05

compojure and reitit are routers, pedestal I’m not sure of, I think it has some relation to interceptors

Schpaa11:01:37

I guess pedestal is more like a framework, a bigger thing

simongray12:01:38

@stebokas All three can be used to make web services. Pedestal has more stuff out of the box, but otherwise they’re quite comparable and a simple hello world example can be made in just a few lines of code in each of them. • Compojure uses the Ring handler model (functions wrapping functions) and a more traditionally Lispy way of defining routes using macros called GET, PUT, POST, etc. • Pedestal is a data-oriented library for making web services made by Cognitect (the company maintaining Clojure). It uses Clojure data for everything: defining routes, data for setting up servers, and data for defining its alternative to Ring handlers (interceptors). I like it a lot. • Reitit is sort of Metosin’s clone of the routing portion of Pedestal (with Metosin’s Sieppari being a clone of the interceptor chain). It is more actively maintained than Pedestal currently is and according to Metosin it’s slightly faster too, but currently not as feature complete - and not aiming to be - but unlike Pedestal it can be used in the frontend too (i.e. in ClojureScript). Obviously, there are other things to say about it too, but I haven’t used it myself.

👍 3
simongray12:01:48

@schpaencoder Shhhh! We don’t use the F-word around here 😛

😮 3
😁 6
Old account12:01:15

fu-ction :face_with_hand_over_mouth: or is it f-mework 😄

Schpaa12:01:55

what about fulcro?

😄 3
😅 3
simongray13:01:55

The taboo is actually so strong that even fulcro doesn’t dare call itself a framework on its Github page. The F-word is used on the Fulcro website, but hidden away in a testimonial at the bottom of the page 😉

simongray13:01:39

@stebokas it’s of course not function :)

😂 3
Old account15:01:12

but this taboo is ridiculous because for example ring calls users code :thinking_face:

caumond12:01:33

thx @simongray, that kind of synthesis is not easy to find

🙏 3
Harley Waagmeester12:01:17

are there any performance or idiomatic concerns that would dictate choosing between using 'alter-var-root' or using atoms ?

Alex Miller (Clojure team)14:01:09

you should probably use atoms for most things where you might ask this question

noisesmith16:01:35

I've usually seen alter-var-root done for monkey-patching, eg. for debugging / diagnostic purposes - agreed that atoms are the go-to for mutation

noisesmith16:01:28

@U01EFUL1A8M is that the right link? I don't see alter-var-root mentioned at all

dgb2316:01:35

@U051SS2EU yes, but it seems to be a good primer or inspiration for atom/ref etc. usage. I didn’t even know alter-var-root existed until now. I guess it is used in very specific cases, while atoms (and the other constructs) are more typical.

dgb2316:01:31

Programming Clojure also has a nice section about these constructs if I remember correctly btw.

Harley Waagmeester17:01:05

@U01EFUL1A8M thanks, that's a great read

👍 3
Harley Waagmeester17:01:35

anyways, i'm considering transactions now

noisesmith17:01:32

in practical usage transactions / refs / agents are special case tools and not what's commonly needed

noisesmith17:01:54

the normal approach is an atom holding a hash map with all the related state

noisesmith17:01:19

refs end up being an optimization when the contention of one atom is a bottleneck (rare)

Harley Waagmeester17:01:43

i'm using an internal database of atoms that are vectors that hold data, it works slick and cleans up spaghetti code by separating formatting and report generation from data acquisition which is difficult if i try to be immutably iodiomatic, i'd really like to be a clojure functional guru... but alas my roots are imperative from my C upbringing

noisesmith17:01:03

the normal way to do this would be a single atom holding a hash map from some key to a vector

noisesmith17:01:26

or better yet, to use a pipeline from data acquisition to report generation rather than storing the data in a place as program logic

Harley Waagmeester17:01:32

hmm.. i use a hash map of keys to the database atom s

noisesmith17:01:56

atoms inside hash-maps is a code smell, a single atom holding that map is almost always better

noisesmith17:01:09

(not to say there are no exceptions, but those are rare)

Harley Waagmeester17:01:32

sure, i can try it differently, i might like it better that way

noisesmith17:01:56

functions like update / update-in when combined with swap! make this straightforward

noisesmith17:01:07

(it's definitely clumsy without them)

Harley Waagmeester17:01:58

yes, the database gets re-populated often as it just holds information from external programs that are executed, so i actually have a loop construct that resets all the atoms, if have there is just one atom to reset that is far less clumsy, i always start out with a huge mess of code that i perfect when i finally realize what i am doing after someone tells me what i should do 🙂

Harley Waagmeester17:01:15

@U051SS2EU thank you, your insight is really impressive

noisesmith18:01:52

shoulders of giants, years of suffering from my own mistakes, and all that 🍻

FHE14:01:17

Hi folks. I've been slowly trying to put together a set-up for ClojureScript, and recently got a recommendation to go with the 'Clojure CLI tools'. I just got out of the long prerequisite step of installing WSL2 and Ubuntu and getting it to actually work, but now I'm having a hard time finding a guide on what to do next. None of the resources I've found on Clojure CLI tool installation mention anything about WSL2. What should I do next?

zackteo14:01:51

I think you will find better leverage by installing directly on windows as oppose to going through wsl

zackteo14:01:59

What setup are you looking towards having? Like what editor are you planning to use?

FHE14:01:59

Oof. I had used Leiningen before, but then got steered in the direction of WSL2 and ClojureCLI. Just manually updated Windows (no idea why my computer said it was 'up to date' when it was two whole Windows version behind!), and got WSL2 with Ubuntu working. Are you saying I don't need any of it?

FHE14:01:41

Actually, where do Clojure CLI tools get installed? Windows, or the Linux VM?

FHE14:01:05

(and if the VM, then would it have to keep getting re-installed every time you run the VM??)

zackteo14:01:40

I'm abit unsure about clojurescript - I just remember my friend was able to get things working better through windows

zackteo14:01:43

actually ....

zackteo14:01:10

What are you looking to do with ClojureScript exactly?

zackteo14:01:06

@UH5SE3NM9 I think you might have been beating on the wrong bush. I think for set-up, what you should either be looking at is https://figwheel.org/ or https://github.com/thheller/shadow-cljs

Alex Miller (Clojure team)14:01:43

but if you're doing WSL2, then just the normal linux instructions on https://clojure.org/guides/getting_started are probably the right answer

👍 3
FHE14:01:44

I did take a stab at using shadow-cljs in my second-latest attempt to into CLJS again a few months ago, but it went off the rails. The guide just started to make less sense. 😕

FHE14:01:39

By the way, at that figwheel page you linked to, @UUSQHP535, it mentions Clojure CLI tools on an Apple machine only.

FHE14:01:33

No mention of WSL(2) I can see at any of the links actually.

FHE14:01:07

I don't know how I ended up with this to-do list: 1. Install WSL2 (which requires a huge Windows update) 2. Install Clojure CLI tools.

FHE14:01:29

@seancorfield I think the recommendation came from you. What am I spacing out on?

FHE14:01:21

Thanks for the help so far by the way, all.

FHE14:01:37

I guess I might try again with Leiningen and/or shadow-cljs

Christian14:01:44

What's your IDE?

Christian14:01:14

I see the benefit using VS Code on the windows host and have all the code run on the wsl

Christian14:01:25

but I know nothing about emacs, sorry

pavlosmelissinos14:01:39

> (and if the VM, then would it have to keep getting re-installed every time you run the VM??) No, the data persists. Do you lose your data when you turn off your machine? It's the same thing. WSL is your best bet imho, for the sole reason that it offers a proper bash experience. Just fire up WSL and follow the clojure cli tools installation instruction for linux, like @U064X3EF3 said.

FHE14:01:38

Neither do I. 😉 ...but with the many, many decisions to be made about the toolchain (is there a better term to use?) I've already settled on Doom Emacs + CIDER.

FHE14:01:02

@UEQPKG7HQ Great to know (about the persistence). Thanks.

Christian14:01:06

The thing about wsl is, that you have a command line linux right in your windows. You can even access all the files. With wsl2 you can even use the gpu for calculations

Christian14:01:31

Here is a guide to use emacs on windows that runs from the wsl: https://emacsredux.com/blog/2020/09/23/using-emacs-on-windows-with-wsl2/

FHE14:01:29

@U01E6385CN8 Thanks. I will take a look. I will have to find something that discusses Clojure at some point too. I did not even know I had to do separate reading on just getting Emacs and WSL2 to play nicely together, though!

FHE14:01:58

By the way, I keep getting pulled away from the computer, but I will try to check in on this thread throughout the day. In any case I should be on more consistently this evening.

Christian14:01:13

I hope I can stick with vs code and don't have to switch to emacs for some reason. learning a language is hard enough, I wouldn't want to learn a dwarf-fortress-y IDE on the side.#

FHE14:01:59

If you do try it, we can talk. I'm a noob at that too. org-mode is amazing though. It alone is worth the the price of admission to some people, I hear.

FHE14:01:44

I had just heard Emacs+CIDER was the best for Clojure.

FHE14:01:06

After trying Emacs I didn't love the heavy use of key chording (with Shift/Ctrl/Alt) and could imagine RSI from it, so I looked a bit further and found Doom.

FHE14:01:29

I also tried Vim and found it kind of mind-melting, but I'm game for short-term pain for long-term gain.

pavlosmelissinos14:01:01

@UH5SE3NM9 You can always run emacs in terminal mode from within wsl (`emacs -nw`) if you don't need the GUI. You can also ask at the #emacs channel, I'm sure others before you have faced similar issues. @U01E6385CN8 switching from an IDE to emacs was definitely one of the best decisions I've made in recent years, for various reasons, but you're right. Trying to juggle learning emacs AND clojure would definitely have been hard.

FHE15:01:12

@UEQPKG7HQ I have not tried the non-GUI Emacs yet, but Doom strips away the menus and even some of the info bar stuff (which I want to figure out how to get back!), so maybe terminal Emacs wouldn't be that bad.

FHE15:01:20

Why exactly was the switch worthwhile to you? I'm committed to trying to learn it all at once, but it would still be good to know (and @U01E6385CN8 might want to know too. 😉

pavlosmelissinos16:01:10

I'm all for learning it all at once but don't overdo it or you might get frustrated enough to quit both 😛 > Why exactly was the switch worthwhile to you? built-in ergonomics: • distraction-free environment/complete lack of annoying menus and sidebars • the keyboard is a first class citizen • much more lightweight than probably every fully-fledged IDE out there (advanced static analysis can be helpful but having it enabled all the time has its drawbacks; I was having memory issues with intellij/cursive on a machine with 16GB with just a couple of repls open and a browser) • extreme customizability (in lisp!) • version control your emacs.d directory and you have your emacs setup everywhere you go org-mode, magit, dired I could go on... I'm a new user too (~2 months in) but I don't think I could ever go back edit: multicursor has also been really useful so far! edit2: CIDER/clojure-mode too, obviously! ---------- Having a uniform environment is definitely a big deal. Everything is a buffer and interactive: magit status/diff, source/text files, directories. One major issue beginners (including me!) have with emacs is that you have to like learn 10 combos by heart to be even remotely productive but in the long term that's a good thing. Because the experience is consistent!

seancorfield18:01:11

@UH5SE3NM9 people have suggested WSL2/Ubuntu because then all of the tutorials for macOS/Linux will apply -- I am using VS Code (on Windows, with the Remote-WSL2 extension) and everything Clojure-related runs on WSL2/Ubuntu, so I don't have to think about Windows at all: I can follow any tutorials out there. I'm just getting back to ClojureScript after a long absence, and I'm using the Clojure CLI and Figwheel Main (on WSL2) and just following the docs on https://figwheel.org/ and it all "just works".

seancorfield18:01:19

I used Emacs on and off for years but switched to Atom about four years ago and then to VS Code in the last few months.

seancorfield18:01:06

(I got tired of spending so much time caring and tending for my Emacs configuration and wanted something that "just worked" and kept itself up to date!)

👍 6
zackteo01:01:09

@UH5SE3NM9 I use doom emacs and cider. If you are new to emacs and are doing clojurescript. You will likely find better leverage using vscode! It can be quite daunting trying to pick up both a new language and emacs at the same time. And cider can be improved for ClojureScript support - also because ClojureScript just generally has more moving parts

zackteo01:01:38

I think you are referring to brew ? People mainly use it for apple. And while I personally don't use it. You can definitely use it in Linux and by extension wsl

zackteo01:01:29

If you do want to stick to emacs (which I have a feeling you will 😅) and have doom emacs specific questions i can try to help (there also a very helpful discord channel with the creator and there's a small telegram group if you are interested) tho I understand your main problem is wrt setting up for ClojureScript.

FHE02:01:43

@UUSQHP535 Great. I have haunted the Discord channel with a few painfully nooby questions, but I might reach out to you about it too. I must say, it should be made impossible for anyone to install Doom Emacs without coming across huge bold text stating that reflex hits of [Ctrl]-[z] and even [Ctrl]-[v] will gaslight you. I hit C-v to try to paste something, saw what looked like horrible mangling of my text (just a page-down, but looks a lot like deleting a page of text), then hit C-z to reverse the changes only to have that not work and instead break some shortcuts and/or enable others (no idea it switched between normal shortcuts and evil/vim shortcuts), then just quit the program and lose work and curl up into a ball in the corner just to escape the insanity.

zackteo02:01:14

Yeahhhh ... thats why learning emacs and clojure might not be super ideal 😅 i use emacs bindings within doom emacs btw (non EVIL). I had a year of using emacs as my daily driver before, exploring clojure :x

seancorfield02:01:29

@UH5SE3NM9 It's pretty fair to say that any Emacs distro in its default setup is going to have a very non-intuitive set of key bindings and that the "default, normal" key bindings people expect from every other editor in the (modern) world are going to do "Bad Things(tm)".

zackteo02:01:49

This is the doom emacs telegram group is @doomemacs btw

FHE02:01:04

Oh, and I had to go through the process above multiple times before piecing together what exactly was going wrong---what 2 shortcut key combos that until Emacs had been universal and were at muscle-memory status were hijacked by Emacs/evil for other functions.

seancorfield02:01:40

That's not really fair: Emacs has been around since long before modern editors standardized on different key bindings.

FHE02:01:49

I did have a couple of 1- or 2-month bursts of using Emacs before, but never to do anything productive because the learning curve didn't allow for it.

FHE02:01:33

@seancorfield Absolutely. I just mean they had been universal in my experience.

seancorfield02:01:55

When Emacs appeared, there really were no conventions for copy/paste/etc. Emacs picked a set of keys and consistently kept them for many decades. I started using Emacs in the 17.x days in the mid-'80s. I stopped using it day-in, day-out in the 19.x days some time in the '90s. Then came back to it once I started doing Clojure (I think late 23.x days?).

zackteo02:01:23

The problem i guess was that emacs was consistent but keyboard layouts weren't 😅 thankfully i am using a split keyboard with thumb clusters

FHE02:01:49

Also, Ctrl-v and Ctrl-z are baked right into the OS I'm using (Windows, and isn't that the case in at least most Linux distros too?), in addition to every program I'd ever used before, hence the 'hijacking' viewpoint, despite the history completely explaining it. 😉

FHE02:01:18

I'm not writing Emacs off for it of course. If its the best I'll work for it. I battled typing like a 2-year-old to learn the Dvorak keyboard layout and I'll battle through this.

FHE02:01:10

Should I maybe go with winner-mode, though? I kind of want to give Doom Emacs a good long try before thinking about changing anything, but...

seancorfield02:01:48

@UH5SE3NM9 As I've said, I experimented with a bunch of editors when I learned Clojure -- including Emacs -- but happily switched to Atom and now VS Code. I think if you have experience already with an editor you like, you should just stick with it (as long as it supports Clojure).

👍 3
seancorfield03:01:17

I honestly don't see any compelling reasons for folks to switch from their current editor to Emacs, unless they actually want to learn Emacs.

FHE03:01:30

I can see it being hard to learn something when every other piece of software is a force in the opposite direction.

zackteo03:01:00

^ and in the learning emacs case oftentimes doing learning emacs and clojure simultaneously is a recipe for disaster 😅

👍 3
FHE03:01:02

The only editors I've used have been Eclipse for Java and NotePad++ for HTML and CSS.

seancorfield03:01:49

Ah, there used to be a pretty good plugin for Eclipse but sadly no more. IntelliJ/Cursive might be more familiar to you? (and more productive for learning)

FHE03:01:24

I'm OK with not knowing how to perform a function and having to look it up the first 10 or 100 times. Unexpected effects are the only real problem. Maybe winner-mode would prevent most or all of that. I'm just afraid it might break something about Emacs or Doom.

FHE03:01:22

I also thought it might rob me of the opportunity to get on board with the better Emacs way (of 'yank' etc)...but now that I write out the problem and no I'm not going to stop using C-v and C-z as usual just about everywhere else, I think I'm ready to figure out how to make just that one tweak to Emacs/Doom.

seancorfield03:01:25

I believe there are Emacs modes that install "sane" (modern) key bindings for at least cut/copy/paste/undo -- but I've never tried them.

zackteo03:01:28

Are you getting confused about both vim and emacs keybindings? If you want to continue with emacs. Maybe spacemacs or emacs prelude (maintained by the creator of cider) might be better?

FHE03:01:46

@seancorfield I think winner-mode does exactly that.

zackteo03:01:41

Theres also a emacs "distribution" which does that. Believe that was what he is referring to

seancorfield03:01:03

I like that I can go between almost any macOS app and my editor and have the "same" key bindings, and also between any Windows app and my editor. And that I have the exact same key bindings in my editor on macOS and Windows for all the Clojure-related stuff.

FHE03:01:35

Correction: I just looked it up and it does nothing like that. My mistake. winner-mode instead makes includes window manipulation actions accessible by the undo and redo commands. Also neat.

zackteo03:01:56

😅 yes ... I can be a pain when I leave emacs and keep trying to copy and paste with c-w and c-y

😂 3
FHE03:01:31

@seancorfield What keybindings are you referring to?

FHE03:01:44

Just the main 5? copy, cut, paste, undo, redo?

FHE03:01:57

...and maybe select-all.

seancorfield03:01:36

Since I stopped using Emacs four years ago, I no longer have to think about that :rolling_on_the_floor_laughing:

FHE03:01:59

but are those the ones you were thinking about when you wrote that?

seancorfield03:01:44

Pretty much all key bindings behave the same across all apps and my editor, on each platform (yes, those key bindings are different between macOS and Windows to some extent, but they are still "internally consistent").

seancorfield03:01:53

ctrl-f = find (cmd-f on macOS). ctrl-g = find again (cmd-g on macOS), cut, copy, paste, undo, ctrl-s = save (cmd-s on macOS)... etc etc etc

seancorfield03:01:39

Emacs throws that whole thing out the window... 😐 including terminology around "window" etc 🙂

seancorfield03:01:55

Don't get me wrong: I totally understand the power of Emacs and its ecosystem -- it's pretty much an operating system all on its own, and it has an IRC package (which I used a lot in my early days with Clojure) and email and usenet (anyone remember that?) and org-mode (which I admit I never really "grokked") and so on.

seancorfield03:01:25

And I might actually consider Emacs again if it had a decent socket REPL client for Clojure (it doesn't).

seancorfield03:01:14

But I don't use/want CIDER or nREPL or any of that middleware etc. I want a plain socket REPL and I want sane key bindings for every action.

FHE03:01:16

Then again, I guess I could take the plunge into vim bindings. I only tried out vim for a few hours once, but I heard it's so-o-o good eventually even though it's hard to begin with.

FHE03:01:56

What's wrong with CIDER (he said, finally getting back on topic about Clojure/ClojureScript)?

FHE03:01:50

I had heard Emacs+CIDER was the most popular and best choice for clj(s) development.

seancorfield03:01:53

I used vi for years in "ancient times" but I never found it productive for anything beyond very simple text editing and I cannot use it for Clojure -- I tried (because it has a plain socket REPL integration via Conjure, at least for neovim).

seancorfield03:01:03

Popular != best.

seancorfield03:01:00

I think it's cargo-culting. A lot of early Clojure adopters used Emacs and slime and then cider became "a better slime" but foisting Emacs on new Clojure developers is actually holding Clojure back.

FHE03:01:22

I fully agree that popular =/= best. I heard it was best and popular (and with the popularity comes easier-to-come-by help resources, I reasoned.

seancorfield03:01:55

Over the years, Emacs usage has dropped in the Clojure community to 43% (from maybe 70% in the early days?)

seancorfield03:01:11

IntelliJ/Cursive has grown to 32%

seancorfield03:01:27

VS Code is next at 10%

FHE03:01:53

Oh hey, I just stumbled upon one of your videos yesterday, I meant to mention! ...and in it you use Atom?

seancorfield03:01:03

Yeah, those videos are Atom/Chlorine. I use VS Code/Clover now but it's pretty much identical.

seancorfield03:01:12

I used REBL in those videos, I use Reveal now.

seancorfield03:01:15

Looking back at State of Clojure over the years, back in 2014, Emacs was already down to 43%, but IntelliJ back then was only 14% with vim just behind it.

seancorfield03:01:48

By 2020, vim had fallen behind VS Code.

seancorfield03:01:06

(and Atom was only a few %)

FHE03:01:58

Where is all this editor choice data from?

seancorfield03:01:59

State of Clojure survey results through the years

seancorfield03:01:23

2013 and earlier seem to have disappeared after Chas Emerick reorganized his website.

FHE03:01:34

I'm not seeing that info. If I search for 'editor' on that page, or even on the page for 2020 linked to at the bottom, I get no survey results.

FHE03:01:43

Nevermind...they used 'development environment'. People don't think about searchability enough...

FHE03:01:50

I might try Cursive, but only after I've put together a working project with Emacs or if I really hate it before that point. Actually I will try it (but not until then). I won't know what I'm missing if I don't.

seancorfield03:01:10

I just searched for emacs 🙂

FHE03:01:36

Yeah, searching for 'emacs' was my 2nd approach

seancorfield03:01:25

I hate Cursive more than Emacs -- but it's IntelliJ I hate really. I always have. I tried many versions -- IntelliJ even gave me free licenses (as a vocal blogger, hoping I would review it favorably). I just hate it 😞

FHE03:01:55

Oh wow. I retract my earlier statement.

FHE03:01:07

I guess I could try VSCode

seancorfield03:01:18

They gave me free licenses for three different versions I think, over the years. I never wrote a negative review tho'. I just don't think that's fair. Editors are so very subjective.

FHE03:01:25

What do you think of LightTable and...the other one whose name escapes me.

FHE03:01:38

NightCode

seancorfield03:01:50

I quite liked Eclipse (but would never want to go back to it now). LightTable was great at the time but has been unmaintained for years.

FHE03:01:54

Those are specifically for clojure, right?

seancorfield03:01:01

NightCode is too simplistic to be useful for real projects.

seancorfield03:01:33

I used LT for quite a while (switched from Emacs to LT but then switched back to Emacs).

FHE03:01:04

I was thinking Emacs would be better because it can be used for more things, but maybe that's not how I should be thinking. I spend a long, long time trying to decide on the best language for me to learn (that could easily or at least plausibly run on desktop+mobile+web), and I've already committed to clojure(script), so I really should be open to clj(s)-centric editors.

seancorfield03:01:18

I don't think there's any single "best" anything. It all depends on the trade offs you want to make.

👌 3
seancorfield03:01:13

For me, in the context within which I work, VS Code is perfectly suitable (we're an Atlassian shop at work and the Jira/BitBucket extensions for VS Code are great; and git support in general is really good).

seancorfield03:01:49

I'd like better parinfer/paredit support in VS Code (Atom was slightly better overall, but better in some areas and worse in others).

FHE03:01:56

Not sure what adjective to use. I just wanted the best choice for me, my goals being to maybe program for all those platforms.

seancorfield03:01:21

Magit in Emacs is pretty darn good. Paredit is obviously great in Emacs (but I don't know if there's a Parinfer package?)

FHE03:01:26

So you went Emacs-LigtTable-Emacs-Atom-VSCode? Wow

FHE03:01:51

Are paredit and parinfer in competition or would a person use both? I think the clojure...thing (not mode, but can't remember the term) for Doom Emacs has one of them by default...parinfer I think.

seancorfield03:01:58

And I used several different things before that.

seancorfield03:01:17

Lots of people use both parinfer and paredit

seancorfield03:01:37

I change my editor setup quite often -- because I don't believe there is a single "best" and I think even the "best trade off" changes frequently over time.

FHE03:01:09

Maybe I'll be tweaking Doom Emacs more than I thought, sooner than I thought. Sigh.

FHE03:01:54

Trying to get back on track for now, though...I finally did get WSL2+Ubuntu working. It only took my spare time over almost a week. lol

seancorfield03:01:45

Sorry 🙂 But at least that should only be a one-off task!

FHE03:01:13

I'm trying to figure out how to install Clojure CLI tools, which I vaguely recall was to be the next step.

seancorfield03:01:55

Have you installed linuxbrew on WSL2?

seancorfield03:01:21

(type brew on Ubuntu and see what it says you should apt install)

FHE03:01:11

Someone back in this thread mentioned that WSL2 instances of Ubuntu are persistent, so things can be installed there.

seancorfield03:01:24

Absolutely, yes.

FHE03:01:34

Is it persistent even through rebooting my laptop??

seancorfield03:01:42

Almost everything on this Windows laptop is actually on WSL2.

seancorfield03:01:01

Yes (I'm not sure what that is so surprising?).

seancorfield03:01:44

Microsoft are very serious about bringing in developers by having WSL2 be really solid.

FHE03:01:29

Well in the YouTube video I followed for installing WSL2, the person demonstrates the commands 'exit' and 'shutdown'. I thought for sure shutdown would wink the thing out of existence.

seancorfield03:01:41

You might also want to install the new Microsoft Terminal (I think you can get preview builds from the Microsoft Store? I started with prerelease builds from GitHub)

FHE04:01:07

You mean an updated cmd? or powershell?

seancorfield04:01:44

It's a wrapper that provides a tabbed UI around any number of shells you want, including cmd, PS, and Ubuntu

seancorfield04:01:31

The new tab menu in Microsoft Terminal:

zackteo04:01:01

I use lispy. Makes things much easier if you sit down to learn it

zackteo04:01:00

It is paraedit but with 1 key bindings

FHE04:01:09

I'm stuck atm. Through this whole clojure set-up process I'm writing up the steps so I don't have to go through this pain again, and I'm doing it in Doom Emacs to learn it...but I can't figure out how to undo an accidental deletion of a bunch of my text

FHE04:01:20

I'm even pressing the correct undo shortcut ('u'), but It just toggles between like latest state and the second-last state, like barebones Notepad!!!! This is crazy.

zackteo04:01:12

How about you remove evil mode for now ... https://github.com/zackteo/.doom.d

FHE04:01:37

I might resort to loading a previous version of the file to grab that chunk of text. Unbelievable.

FHE04:01:10

I do know I just hit C-z to toggle evil-mode on and off.

zackteo04:01:28

It might help to use undo tree ... you probably recursively undid stuff

FHE04:01:49

but if I switch out of evil-mode I have to look up what the undo command is in plain emacs, and it's not as intuitive as 'u'. It's something more annoping.

FHE04:01:10

*annoying

zackteo04:01:33

Errrrrr but are you familiar with vim

zackteo04:01:22

At this point you are learning a hybrid of vim and emacs ... as you navigate clojure ... not sure how to describe how bad i feel this endeavour is 😅

👍 3
FHE04:01:24

I'm not familiar with vim other than dd and u. lol

FHE04:01:40

I do know Doom Emacs uses undo-tree

FHE04:01:11

I just looked up the undo-tree webpage and my brain melted after the 1st paragraph.

FHE04:01:53

I guess I'm just supposed to hammer 'u' potentially many times, even if it looks like it's not doing anything, because eventually it will get me back to where I want to be??

zackteo04:01:13

Yeahhh which I why i really suggest you pick either emacs or vim first 😅 and not both

FHE04:01:21

Hey it worked! ...but I overshot the mark. Now to look up how to redo. Sigh.

FHE04:01:47

Well I have used emacs in the past, just not a ton.

zackteo04:01:43

And for emacs, it might be good to use either https://www.spacemacs.org/ or https://github.com/bbatsov/prelude

FHE04:01:58

I hadn't heard of prelude, but I did seriously consider spacemacs until i heard doom emacs was basically the same but better

FHE04:01:35

Oh, and I'm not seeing the tree graphic shown on the undo-tree page. maybe it's something else

FHE04:01:46

@seancorfield I'm about to give up on undo-redo and just reload my notes, and just install Windows Terminal. Is it a replacement for cmd and powershell and the WSL prompt??

zackteo04:01:07

Prelude is done by the creator of cider. It sticks with emacs defaults so it is less complicated

FHE04:01:16

ARGH. I am following the directions here, but I can't get undo to reverse direction and redo. It just keeps eating away more of my text!!!!! http://ergoemacs.org/emacs/emacs_best_redo_mode.html

FHE04:01:27

@UUSQHP535 Do you know how to redo?

zackteo04:01:42

Look at my config

zackteo04:01:17

My undo is C-/ and redo is C-/ with shift

seancorfield04:01:12

@UH5SE3NM9 I answered that over half an hour ago: "It's a wrapper that provides a tabbed UI around any number of shells you want, including cmd, PS, and Ubuntu"

seancorfield04:01:53

And that links to the Microsoft Store where you can install it (and the preview version).

FHE04:01:47

BUT I just get the error message 'C-? is undefined'

FHE04:01:06

Nothing is working to redo!

FHE04:01:47

@seancorfield Sorry. I must have missed that older comment.

seancorfield04:01:35

NP. It's a fast conversation 🙂

FHE05:01:12

@UUSQHP535 Finally got rescued from my undo-redo fiasco thanks to a kind soul on the Doom Emacs Discord channel (and no thanks to answers on StackOverflow that did not work for Doom Emacs at least: https://stackoverflow.com/questions/3527142/how-do-you-redo-changes-after-undo-with-emacs

FHE05:01:20

With Doom Emacs -- C-/ for undo works, but -- C-g C-/ for redo does not...it just undoes more! and -- S-C-/ (i.e. C-?) for redo, required for spacemacs and prelude apparently, also does not work...it just throws the error 'C-? is not defined'

FHE05:01:56

With Doom Emacs, AFAICT you need to be in evil-mode (toggle in and out with 'C-z'), and then it's: -- 'u' for undo, and -- 'C-r' for redo ...pretty nice actually...once you know it!

zackteo05:01:39

Yeah S-C-/ is my own key binding

FHE05:01:58

@UUSQHP535 Ahhh. I finally accomplished a tiny something (though not in clojurescript yet). I dusted off my StackExchange account I haven't used in years and posted the answer for Doom Emacs users I could have used a couple of hours ago at https://stackoverflow.com/questions/3527142/how-do-you-redo-changes-after-undo-with-emacs

FHE05:01:42

@seancorfield Following your question about linuxbrew... I get: $ brew Command 'brew' not found, did you mean: command 'qbrew' from deb qbrew (0.4.1-8build1) command 'brec' from deb bplay (0.991-10build1) Try: sudo apt install <deb name>

FHE05:01:59

I have not done anything to the VM yet.

FHE05:01:51

I guess I'll just follow the Linux installation instructions here: https://clojure.org/guides/getting_started

FHE05:01:44

Oof. I guess I'm back to needing to install Java and everything, only a different installation procedure (for Linux) this time...

FHE06:01:56

Actually since this thread is so long (and I've derailed it so many times), and to help make the info more findable, I think I'll start fresh. New post in main #beginners thread incoming...

FHE14:01:33

For a bit of background, I went through the quick start guide a year or two ago and made an uber-simple webpage that used ClojureScript. I'm trying to get a more fleshed-out set-up ('toolchain'? what should I call it?), but am having a really hard time getting all the pieces together. After about 3 weeks of spare time spent on this I'm still not at the point of entering a single line of code and it's demoralizing.

roelof14:01:49

@hobosarefriends @schpaencoder I have no clue that is why I asked here. Bummer that most of the challenges in learning book are so vague..

Mno14:01:19

I’m certain it’s asking for a function named attr that takes in a keyword :intelligence and returns the attribute for that key.

(defn attr [k] ~your code here~)
(attr :intelligence)
=> 10

popeye14:01:06

how to get the sub string of a string in clojure, ex- hello@word, i want string before @ expected output is hello ?

andy.fingerhut14:01:09

There are regex matching functions that can pull apart pieces of a string if you are familiar with regex matching, e.g. re-find and re-match.

andy.fingerhut14:01:58

If in this case you simply want to find the first @ character and get everything before that, there is the Java .indexOf method for looking for the first index of a paraticular character in a string, and the subs Clojure function for getting a substring of a string based on first index and number of characters.

andy.fingerhut14:01:41

http://ClojureDocs.org has some examples of using those functions (except .indexOf, since it is a Java method, which you can do Google search for the API)

Mno14:01:00

there’s also clojure.string/split if you want both the before and after of the @

Mno14:01:18

(clojure.string/split "hello@word" #"@") => [“hello” “word”]

popeye14:01:26

will try 🙂

👍 6
popeye17:01:36

in my example index-of helped , Thanks 🙂

roelof15:01:06

which channel can I use the best for web development questions ?

Mno15:01:35

I’m not aware of a channel for web development existing specifically, there are however channels for most of the libraries you’d use. I’d recommend asking about general web stuff here or maybe even #clojure, and once you decide on what libraries/approach you’re going to take you can ask more specific questions in the channels for those libraries.

Mno15:01:47

for a tutorial of a web related things, I believe I’ve seen people to point to https://practicalli.github.io/clojure-webapps/content-plan.html and for an example https://github.com/seancorfield/usermanager-example springs to mind.

Mno15:01:36

To be honest I haven’t looked much at either, maybe someone else has suggestions with more experience behind them.

Malik Kennedy15:01:26

https://github.com/gothinkster/realworld Also has some Clojure and ClojureScript example/real-world web projects

roelof16:01:24

was more thinking of tutorials to learn to make websites and choose my own parts https://codepen.io/rwobben/full/xxVepxG

roelof16:01:46

and if I then make such a layout with some reactive parts like going to the next page or showing some info

llsouder17:01:34

Why doesn't this work?

llsouder17:01:36

(map (take 2) [[1 2 3] [1 2 3]])

llsouder17:01:46

I know the right way is

llsouder17:01:58

(map #(take 2 %) [[1 2 3] [1 2 3]])

llsouder17:01:14

but (take 2) evaluates to a function

hiredman17:01:08

it returns a transducer, not a partial application of take

✔️ 3
popeye17:01:45

Team I have a json structure , How can i fetch the data between { and }, Can that be possible in clojure regular expression ?

#json structure 1
  [json structure 2
    {json structure 3
 
    }
  ]
#

clyfe17:01:35

Parse the json to edn then acces the subtree you want via get-in Regex generally not a good idea for this stuff.

popeye17:01:02

output is json structure 3

noisesmith17:01:46

if the json is restricted enough it's possible with regex, but the normal thing would be to use a json parsing library

noisesmith17:01:50

clojure or cljs?

popeye17:01:44

but how can give prefix and suffix to { and }

noisesmith17:01:52

a json library eg. clojure.data.json is simpler and less fragile than a regex

noisesmith17:01:41

but to literally answer the question, you would need "\\{" and "\\}" to escape the special meaning {} have in regex

noisesmith17:01:54

@popeyepwr but consider what happens when structure 3 has another } inside it

noisesmith17:01:26

which is why we have actual parsers to construct real data structures, like data.json

popeye17:01:22

yeah i understand that we should use data.json, but i get the text of file where i need to fetch those words

dpsutton17:01:25

i'm not sure i follow that objection. data.json will parse text to return data structures

roelof18:01:36

@seancorfield do you have some tutorials or pieces I can study so I can learn web development when I finish the brave book

clyfe19:01:30

Maybe start with James Reeves's talks listed here https://www.booleanknot.com/

seancorfield19:01:36

@roelof I don't know what to recommend. I suspect the Web Development with Clojure book will be too advanced for you right now -- but that's normally what I recommend for people who've mastered the basics. I would suggest playing with https://github.com/seancorfield/usermanager-example and reading the code and making sure you understand how that all works before you buy that book.

Pavel KlavĂ­k19:01:32

Web Development with Clojure is ok book but ignore the first chapter since it introduces everything and explains it in subsequent chapters. There are a few difficulties you will have to tackle. Understanding web development in general (HTTP, HTML, CSS, JS, using DB). Understanding Clojure specific libraries. And learning how to put everything together. In my case, I just started with frontend, playing with React, Reagent and Re-frame. I added backend several months later, following Web Development book. I would recommend by building a small app and learning everything along the way.

seancorfield19:01:52

☝️:skin-tone-2: Definitely this: start small (with perhaps just Ring if you're building a back end server-side rendered app, or just Re-frame if you're building a front end only app) and make sure you understand that before adding more things.

seancorfield19:01:22

Web dev with Clojure is "simple" (in the Clojure sense) but it is definitely not "easy".

clyfe20:01:42

There is a lot of fragmentation and paths and variants and minutiae advantages to libs, it takes a long time to make a mental map of the landscape

roelof20:01:53

first project I had in mind was to make a front and back-end app where I display some data from a external api

roelof20:01:25

and I it is no problem that It takes a long time

roelof20:01:43

and im willing to start very simple if needed

clyfe20:01:06

assuming you already grok http, my preferred path would be: start with https://github.com/ring-clojure/ring & https://github.com/ring-clojure/ring-defaults (get familiar with each middleware in ring-defaults), then https://github.com/duct-framework/duct, then maybe http://pedestal.io/ and https://github.com/metosin/reitit - this be just the backend (api or classic html generation) for frontend / spa: https://github.com/reagent-project/reagent & http://day8.github.io/re-frame/re-frame/ are established, then maybe http://fulcro.fulcrologic.com/

Pavel KlavĂ­k20:01:01

If you start with frontend, you can just mock-up some data and work on their visualization, maybe making it interactive. Later you can work on downloading data. Or you can flip it around and just write static HTML generator on backend using hiccup library.

clyfe20:01:45

for getting data from places: https://github.com/seancorfield/next-jdbc is great, https://github.com/dakrone/clj-http for api calls is common

roelof20:01:28

no, luminus or another framework ?

roelof20:01:09

I will begin with the ring readme

👍 3
roelof20:01:18

and play with that

roelof20:01:23

for now GN

roelof20:01:03

I think the next weeks/months I will studie and try to understand the path that @UCCHXTXV4 pointed out

roelof20:01:27

but for now more chapters from the brave book on the menu

popeye19:01:52

which is the best way to iterate on vector? I am trying with loop-recur, with 2 value,, so when i call (next v) it fail at the last

Pavel KlavĂ­k20:01:40

One rarely needs to use loop recur, instead using higher order functions such as map, filter, reduce, makes things more understandable.

Pavel KlavĂ­k20:01:10

If you want to do some computation with all pairs of values, you can first apply (partition 2 1 vect) to get all pairs.

seancorfield19:01:34

@popeyepwr It depends what you're trying to do. What problem are you solving?

sova-soars-the-sora20:01:22

@popeyepwr (first) and (rest) not helpful?

popeye20:01:56

Yeah I used some other way to find out my issue

popeye21:01:46

(contains? (set (str/split "select abc" #" ")) #{"select"} ) is returning false, which function can be used to make sure values present in set is present in string..?

jaihindhreddy10:01:27

You're checking whether the set of words contains the singleton set #{"select"}. This will work:

(contains?
  (set (str/split "select abc" #" "))
  "select")
Although, perhaps https://clojuredocs.org/clojure.string/includes_q might be what you want:
(str/includes? "select abc" "select")
Bear in mind that it doesn't do the exact same thing. For example, the both vary with the string "selecting abc".

dpsutton21:01:13

evaluate just the (set (str/split ...)) and see what you get. and then consider if #{select"} is a member of that set

popeye21:01:06

ya doing same? set can have multiple values #{"select" "insert"}

dpsutton21:01:07

yes. and that set doesn't contain any sets. so (contains? #{"select" "insert"} #{"select"}) will be false. it has two elements "select" and "insert", not a set containing "select"

dgb2323:01:25

I have a bit of a weird question. Are people using logic programming to compose/render/validate interactive html forms? I’ve been doing web-dev for 8y but I’ve never encountered a way to handle them that wasn’t in some way painful or unsatisfactory at least. What’s important to me is not just validation, but also guiding the user as well as possible (UX) on one hand, but also having a declarative way to model them AKA a way that is closer to a specification that you can talk about with a domain expert / customer etc. than to “code”. Forms are painful by default already. I’d like to be more productive, easily correct and clear when doing them. Forms with sufficient amounts of complexity/rules have always bothered me. Simple tools like json-schema are not powerful enough to model them in a data-driven. declarative way. More powerful things like clojure.spec have caught my eye, but I’m wary of parsing spec forms (clojure expressions) or creating them dynamically (based on stored data etc.). So typically I write some ad-hoc recursive logic. Typically it goes like this: You make an effort to pin down the rules and constraints with a client, expert or based on an API etc. Then there is a huge gap. And then there is your form model, fields, validation, special cases, ui updates etc. pp When I was reading a bit about core.logic I immediately thought: Hey this is much closer to the initial specification of a (complex) form! Can it do this? Clojure has libraries for html data-structures (hiccup etc.) So my intuition is that there might be some way to unify (sic!) logic programming and modelling forms.

dgb2323:01:01

I’ll dive a bit more into core.logic and try to find a good book on the subject out of sheer interest anyway. I guess my question is: Is my intuition completely wrong?