Fork me on GitHub
#beginners
<
2020-10-10
>
teodorlu11:10:13

Hey! I naïvely tried this:

(when-let [current (:current-page @state)
             title (get-in model [current :title])]
    [:p (str "Current page is: " title)])
but when-let doen't allow multiple values. Is there another xxx-let I can use?

teodorlu11:10:54

I can use a double when-let to get the behavior I want:

(when-let [current (:current-page @state)]
  (when-let [title (get-in model [current :title])]
    [:p (str "Current page is: " title)]))

zilti11:10:28

The Encore library has multi-assign when-let and if-let

👍 6
teodorlu11:10:50

@U2APCNHCN the behavior in the Encore library seems to be exactly what I'm asking for. Thanks! Since it's been reimplemented this way in an external library, I assume that there's not a clojure.core alternative. taoensso.encore/if-let documentation if anyone else are interested:

"Like `core/if-let` but can bind multiple values for `then` iff all tests
  are truthy, supports internal unconditional `:let`s."

Mattias12:10:32

Hey, happy for input on suggested Clojure ”stacks”. I’ll be doing some prototypes for solutions with backend/DB/API and in some cases web GUI (likely plain React). I want to move quickly as it’s not my main task, but with a serious enough approach that I can use to “sell” the solution to developer colleagues. I’d like to implement both regular rest endpoints and GraphQL in parallel unless it’s very wasteful. Suggestions on libraries or tools? Projects to have a look at? What’s an easy way forward with the DB that’s quick but looks serious from a distance? (If things live on it will very likely be SQL dbs.)

schmee13:10:50

I use Reagent for frontend and Pedestal for backend, both are well-established libraries that are being used in production by lots of companies

Mattias14:10:00

Fantastic, thanks 👍

Mattias14:10:16

On the same topic, what’s the quickest way to get going with a (preferably SQL) db? I need some way to resolve relations and stuff, even it it’s small scale 🙂

dharrigan14:10:13

next.jdbc and honeysql are winners

👌 3
dharrigan14:10:32

I use both extensively in my applications

Mattias17:10:01

Cool, thanks. Any suggestions or pointers on the workflow when in dev/prototyping mode? I’ll read up on the libraries, guess it might be self evident ☺️

seancorfield17:10:16

There are #honeysql and #sql channels if you have questions about HoneySQL or about SQL in general (and next.jdbc in particular).

Mattias17:10:38

Doh. Thanks!

Zor10:10:35

https://www.hugsql.org/ is another option. It is not, however, the quickest way. So far you collected lists of interesting dependencies to your mix. I suggest adding some component-system to your stack - https://github.com/stuartsierra/component seems to be an established, popular one. I've been having lots of success with https://github.com/weavejester/integrant. Last note - if you're looking for the fastest possible way, you might be looking for a framework rather than a collection of libraries. Check out the Web Frameworks section of https://www.clojure-toolbox.com for all the links you need.

👍 3
dharrigan17:10:24

juxt clip is another alternative to component and integrant. works really well

Mattias12:10:02

(Oh, and I’m learning Clojure as I go. Have some a simple thing with Ring/Compojure/Hiccup, with an ArangoDB using (the somewhat clunky) interop to Java.)

zilti12:10:58

Fulcro is great for writing React SPAs

JoshLemer16:10:21

Sorry for the basic question but I’m trying to run the introductory examples of how to use Protocols in Clojure and I get really incomprehensible errors, any idea what’s going on?

(defprotocol P
  (foo [x])
  (bar-me [x] [x y]))
error:
; Syntax error compiling at (core.clj:46:1).
; Unable to resolve symbol: .replace.P in this context
[{:file "Compiler.java" :line 6808 :method "analyze" :flags [:tooling :java]}
 {:file "Compiler.java" :line 6745 :method "analyze" :flags [:dup :tooling :java]}
 {:file "Compiler.java" :line 3104 :method "parse" :flags [:tooling :java]}
....
...

littleli09:10:02

I believe the issue with incomprehensible error was fixed in the release yesterday.

JoshLemer16:10:00

(running this in calva vscode)

Alex Miller (Clojure team)16:10:27

Multi arity is not supported in protocols with that syntax, but that seems like a weird error, maybe due to tooling

JoshLemer16:10:52

thank you, definitely a tooling thing, cheers!

pez16:10:37

We currently are working on producing better stack traces for Calva. Which part of the error is weird? (Not sure we can fix it, but would be nice with some elaboration.)

hiredman16:10:23

The symbol.name in the error is nonsense

hiredman16:10:53

So my guess is alex is suggesting that some tool is mangling it

hiredman17:10:14

But the alternative is it isn't an error from defining the protocol, but somewhere else in the file, which is the sort of thing question askers in #beginners have trouble with

JoshLemer17:10:20

@U0ETXRFEW Answered you in the other thread

pez19:10:02

It's quite strange with that symbol name in the message. Doesn't seem to be nrepl or cider-nrepl though, so maybe something else in your project.

Alex Miller (Clojure team)16:10:00

For multi arity, declare the method twice with different arities

JoshLemer16:10:58

Is the protocols page out of date? I took this sample from https://clojure.org/reference/protocols Thanks again!

Alex Miller (Clojure team)16:10:20

Well maybe I’m misremembering then!

Alex Miller (Clojure team)16:10:43

I always have to look it up because it’s different

Alex Miller (Clojure team)16:10:39

I think I’m confusing it with impl in defrecord/deftype sorry

Alex Miller (Clojure team)16:10:04

But I still think the error is weird and looks like tooling

pez16:10:39

I don't get that error when evaluating the form, btw. It defines P, foo and bar-me.

JoshLemer17:10:19

The issue has something to do with the cursor location when I run the expression in the REPL If I put the cursor at location A it works, at B it gives the error

(     defprotocol Foo ...)
^ A   ^ B

pez18:10:46

I recommend Evaluate top-level (`alt+enter`) for all def things. Evaluating current form is for evaluating things inside those. Get a feeling for what Calva thinks is the current form by moving the cursor around and issue the Select current form command. All that said, I get this message evaluating current form from B:

Can't take value of a macro: #'clojure.core/defprotocol

stopa17:10:40

Hey team, what are your favorite project-based tutorials in clojure? (Something cool someone can build, ideally without having to expose a server / install too many dependencies.) — Want to create a list I can share with friends who want to learn / potentially turn it into an essay

practicalli-johnny19:10:16

The project based approach is taken in much of the Practicallli books I'm writing. For example https://practicalli.github.io/clojure/simple-projects/ https://practicalli.github.io/clojure-webapps/

❤️ 3
herald20:10:19

I think screencasts where you can "code along" making games are great. I really enjoyed ZombieCLJ, which is sadly only in Norwegian http://www.zombieclj.no/

❤️ 3
Markus Agwin22:10:48

Look at https://kloimhardt.github.io/guestbook_0.html plus look at the page source, it is mostly Clojure. I made the according repository https://github.com/kloimhardt/bb-web exactly for your purpose. I put some effort into the Readme, feedback form actual beginners would be very welcome.

nate01:10:22

Parens of the dead was a really fun one to watch: http://www.parens-of-the-dead.com/

sova-soars-the-sora17:10:58

that's a cool idea.

❤️ 3