beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
Pascal 2021-01-06T02:31:19.244700Z

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.

2021-01-06T02:45:28.245200Z

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

2021-01-06T02:46:17.245400Z

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.

2021-01-06T02:47:29.245600Z

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.

Pascal 2021-01-06T03:03:02.245800Z

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

seancorfield 2021-01-06T04:26:32.247500Z

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)

salam 2021-01-06T06:31:49.248300Z

welcome to Clojurians, @abane288! 🙂 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

🙏 1
salam 2021-01-06T07:03:25.249100Z

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

Christian 2021-01-06T09:23:28.249700Z

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

Christian 2021-01-06T10:12:25.251400Z

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?

caumond 2021-01-06T10:21:07.252900Z

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

caumond 2021-01-06T10:21:53.253400Z

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

Christian 2021-01-06T10:22:15.253700Z

custom funtion, that returns a list with three elements

2021-01-06T10:22:34.253900Z

%& should do it

Christian 2021-01-06T10:23:11.254600Z

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

Christian 2021-01-06T10:23:23.254900Z

I'll try this

caumond 2021-01-06T10:24:56.255400Z

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

caumond 2021-01-06T10:25:12.255600Z

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

Christian 2021-01-06T10:26:51.256100Z

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)

caumond 2021-01-06T10:27:18.256400Z

I must confess I share your point

caumond 2021-01-06T10:27:38.257Z

another way is destructuring

Christian 2021-01-06T10:27:46.257300Z

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

Christian 2021-01-06T10:28:57.257600Z

This works:

Christian 2021-01-06T10:28:59.257800Z

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

Christian 2021-01-06T10:29:31.258400Z

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

caumond 2021-01-06T10:29:43.258700Z

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

caumond 2021-01-06T10:31:30.259200Z

I understand now

roelof 2021-01-06T11:15:45.259900Z

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.

roelof 2021-01-06T11:16:53.260300Z

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

roelof 2021-01-06T11:17:39.261200Z

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

Mno 2021-01-06T11:20:00.263100Z

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

Mno 2021-01-06T11:20:15.263400Z

My best guess is that's is the problem

Mno 2021-01-06T11:22:15.265300Z

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

Mno 2021-01-06T11:24:24.267800Z

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

Schpaa 2021-01-06T11:24:58.268500Z

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

Audrius 2021-01-06T11:50:18.269400Z

is compojure, reitit and pedestal same sort of thing?

Schpaa 2021-01-06T11:54:05.270900Z

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

Schpaa 2021-01-06T11:55:37.271200Z

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

simongray 2021-01-06T12:09:38.278900Z

@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.

👍 1
simongray 2021-01-06T12:14:48.280100Z

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

😁 2
😮 1
caumond 2021-01-06T12:15:33.280700Z

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

🙏 1
Audrius 2021-01-06T12:18:15.281100Z

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

Schpaa 2021-01-06T12:26:55.281400Z

what about fulcro?

😄 1
😅 1
Harley Waagmeester 2021-01-06T12:45:17.283300Z

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

dgb23 2021-01-06T12:55:33.283400Z

Not a direct answer, but related to your question: https://gist.github.com/reborg/dc8b0c96c397a56668905e2767fd697f#when-should-i-use-atomsrefsagents

simongray 2021-01-06T13:13:55.283700Z

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 😉

simongray 2021-01-06T13:14:39.283900Z

@stebokas it’s of course not function :)

😂 1
FHE 2021-01-06T14:09:17.287500Z

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?

zackteo 2021-01-06T14:10:51.289100Z

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

FHE 2021-01-06T14:12:33.291Z

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.

zackteo 2021-01-06T14:13:59.291100Z

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

FHE 2021-01-06T14:14:59.291300Z

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?

FHE 2021-01-06T14:15:41.291500Z

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

FHE 2021-01-06T14:16:05.291700Z

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

zackteo 2021-01-06T14:16:40.291900Z

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

zackteo 2021-01-06T14:16:43.292100Z

actually ....

zackteo 2021-01-06T14:17:10.292300Z

What are you looking to do with ClojureScript exactly?

zackteo 2021-01-06T14:25:06.292500Z

@factorhengineering 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

alexmiller 2021-01-06T14:25:38.292900Z

https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows may be helpful re the CLJ tools on windows

alexmiller 2021-01-06T14:26:43.293300Z

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

👍 1
FHE 2021-01-06T14:28:44.293600Z

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. 😕

FHE 2021-01-06T14:30:39.294300Z

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

FHE 2021-01-06T14:31:33.294500Z

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

FHE 2021-01-06T14:33:07.294700Z

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.

FHE 2021-01-06T14:33:29.294900Z

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

FHE 2021-01-06T14:34:21.295100Z

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

FHE 2021-01-06T14:34:37.295300Z

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

Christian 2021-01-06T14:34:44.295500Z

What's your IDE?

FHE 2021-01-06T14:34:49.295700Z

Emacs

Christian 2021-01-06T14:35:14.295900Z

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

Christian 2021-01-06T14:35:25.296100Z

but I know nothing about emacs, sorry

pavlosmelissinos 2021-01-06T14:35:39.296300Z

> (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 @alexmiller said.

FHE 2021-01-06T14:36:38.296500Z

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.

FHE 2021-01-06T14:37:02.296700Z

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

Christian 2021-01-06T14:38:06.296900Z

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

Christian 2021-01-06T14:40:31.297700Z

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/

alexmiller 2021-01-06T14:41:09.299100Z

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

roelof 2021-01-06T14:41:49.300400Z

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

popeye 2021-01-06T14:42:06.300700Z

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

2021-01-06T14:43:09.301300Z

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.

FHE 2021-01-06T14:43:29.301700Z

@christiaaan 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!

FHE 2021-01-06T14:43:58.301900Z

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.

2021-01-06T14:43:58.302Z

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.

2021-01-06T14:44:41.302300Z

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)

Mno 2021-01-06T14:46:00.302500Z

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

Christian 2021-01-06T14:46:13.302700Z

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.#

Mno 2021-01-06T14:47:18.302900Z

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

FHE 2021-01-06T14:47:59.303100Z

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.

FHE 2021-01-06T14:48:44.303300Z

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

FHE 2021-01-06T14:50:06.303500Z

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.

FHE 2021-01-06T14:50:29.303700Z

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

Mno 2021-01-06T14:51:19.303900Z

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

pavlosmelissinos 2021-01-06T14:55:01.304200Z

@factorhengineering 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. @christiaaan 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.

popeye 2021-01-06T14:58:26.304500Z

will try 🙂

👍 2
roelof 2021-01-06T15:16:06.305600Z

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

Mno 2021-01-06T15:28:35.307600Z

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.

Mno 2021-01-06T15:32:47.310Z

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.

Mno 2021-01-06T15:33:36.310900Z

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

Audrius 2021-01-06T15:46:12.311300Z

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

Malik Kennedy 2021-01-06T15:50:26.312200Z

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

FHE 2021-01-06T15:56:12.312400Z

@pavlos 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.

FHE 2021-01-06T15:57:20.312600Z

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 @christiaaan might want to know too. 😉

2021-01-06T15:58:58.312800Z

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

👀 1
2021-01-06T16:00:14.313Z

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

2021-01-06T16:03:35.313200Z

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

2021-01-06T16:04:28.313400Z

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

dgb23 2021-01-06T16:07:35.313600Z

@noisesmith 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.

dgb23 2021-01-06T16:08:31.313800Z

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

pavlosmelissinos 2021-01-06T16:11:10.314Z

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!

roelof 2021-01-06T16:14:24.315Z

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

roelof 2021-01-06T16:15:46.315900Z

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

euccastro 2021-01-06T16:22:13.316100Z

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

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

✅ 1
Harley Waagmeester 2021-01-06T17:05:05.317100Z

@denis.baudinot thanks, that's a great read

👍 1
Harley Waagmeester 2021-01-06T17:07:35.317400Z

anyways, i'm considering transactions now

2021-01-06T17:09:32.317600Z

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

2021-01-06T17:09:54.317800Z

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

2021-01-06T17:10:19.318Z

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

llsouder 2021-01-06T17:23:34.319100Z

Why doesn't this work?

llsouder 2021-01-06T17:23:36.319300Z

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

Harley Waagmeester 2021-01-06T17:23:43.319500Z

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

llsouder 2021-01-06T17:23:46.319700Z

I know the right way is

llsouder 2021-01-06T17:23:58.320100Z

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

llsouder 2021-01-06T17:24:14.320500Z

but (take 2) evaluates to a function

2021-01-06T17:26:08.321100Z

it returns a transducer, not a partial application of take

✔️ 1
llsouder 2021-01-06T17:27:58.321400Z

thank you!

2021-01-06T17:28:03.321500Z

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

2021-01-06T17:29:26.321700Z

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 Waagmeester 2021-01-06T17:29:32.321900Z

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

popeye 2021-01-06T17:29:36.322100Z

in my example index-of helped , Thanks 🙂

2021-01-06T17:29:56.322300Z

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

2021-01-06T17:30:09.322500Z

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

Harley Waagmeester 2021-01-06T17:32:32.322800Z

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

2021-01-06T17:33:56.323Z

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

2021-01-06T17:34:07.323200Z

(it's definitely clumsy without them)

popeye 2021-01-06T17:41:45.325Z

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
 
    }
  ]
#

Harley Waagmeester 2021-01-06T17:41:58.325300Z

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 🙂

popeye 2021-01-06T17:42:02.325500Z

output is json structure 3

2021-01-06T17:42:46.326200Z

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

2021-01-06T17:42:50.326500Z

clojure or cljs?

popeye 2021-01-06T17:43:24.327Z

clojure, i want to use clojure regex, i referred http://makble.com/clojure-regular-expression-extract-text-between-two-strings

popeye 2021-01-06T17:43:44.327600Z

but how can give prefix and suffix to { and }

2021-01-06T17:43:52.327800Z

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

clyfe 2021-01-06T17:44:35.327900Z

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

2021-01-06T17:45:41.329300Z

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

2021-01-06T17:46:54.329900Z

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

2021-01-06T17:47:26.330300Z

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

popeye 2021-01-06T17:52:22.331500Z

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

Harley Waagmeester 2021-01-06T17:58:15.331600Z

@noisesmith thank you, your insight is really impressive

dpsutton 2021-01-06T17:59:25.332200Z

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

2021-01-06T18:06:52.332300Z

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

seancorfield 2021-01-06T18:41:11.332900Z

@factorhengineering 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".

seancorfield 2021-01-06T18:42:19.333200Z

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.

seancorfield 2021-01-06T18:43:06.333400Z

(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!)

👍 2
roelof 2021-01-06T18:58:36.334900Z

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

clyfe 2021-01-06T19:05:30.335200Z

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

seancorfield 2021-01-06T19:11:36.335400Z

@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.

roelof 2021-01-06T19:15:09.335700Z

thanks

2021-01-06T19:23:32.336Z

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.

popeye 2021-01-06T19:43:52.339500Z

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

seancorfield 2021-01-06T19:48:52.339600Z

☝️: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.

seancorfield 2021-01-06T19:49:22.339800Z

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

seancorfield 2021-01-06T19:50:34.340400Z

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

clyfe 2021-01-06T20:10:42.340600Z

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

roelof 2021-01-06T20:10:53.340800Z

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

roelof 2021-01-06T20:11:25.341Z

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

roelof 2021-01-06T20:11:43.341200Z

and im willing to start very simple if needed

clyfe 2021-01-06T20:22:06.341400Z

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/

2021-01-06T20:23:01.341800Z

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.

2021-01-06T20:24:40.342Z

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

clyfe 2021-01-06T20:24:45.342200Z

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

2021-01-06T20:31:10.342900Z

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

roelof 2021-01-06T20:32:28.343100Z

no, luminus or another framework ?

roelof 2021-01-06T20:34:09.343300Z

I will begin with the ring readme

👍 1
roelof 2021-01-06T20:34:18.343500Z

and play with that

roelof 2021-01-06T20:36:23.343700Z

for now GN

sova-soars-the-sora 2021-01-06T20:41:22.344300Z

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

roelof 2021-01-06T20:53:03.344400Z

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

roelof 2021-01-06T20:53:27.344600Z

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

popeye 2021-01-06T20:57:56.345400Z

Yeah I used some other way to find out my issue

popeye 2021-01-06T20:57:58.345600Z

🙂

popeye 2021-01-06T21:12:46.346500Z

(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..?

jaihindhreddy 2021-01-07T10:10:27.001900Z

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".

dpsutton 2021-01-06T21:15:13.347200Z

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

popeye 2021-01-06T21:17:06.347900Z

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

dpsutton 2021-01-06T21:25:07.349100Z

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"

dgb23 2021-01-06T23:43:25.361800Z

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.

dgb23 2021-01-06T23:47:01.363100Z

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?