beginners

Getting started with Clojure/ClojureScript? Welcome! Also try: https://ask.clojure.org. Check out resources at https://gist.github.com/yogthos/be323be0361c589570a6da4ccc85f58f.
teodorlu 2020-10-10T11:18:13.098900Z

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?

teodorlu 2020-10-10T11:22:54.099Z

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)]))

zilti 2020-10-10T11:27:28.099400Z

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

2👍
teodorlu 2020-10-10T11:30:50.099800Z

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

2020-10-10T12:06:32.109200Z

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

2020-10-11T10:26:35.138900Z

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.

1👍
dharrigan 2020-10-11T17:49:24.171400Z

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

2020-10-10T12:10:02.111500Z

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

zilti 2020-10-10T12:27:58.112Z

Fulcro is great for writing React SPAs

schmee 2020-10-10T13:28:50.113300Z

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

schmee 2020-10-10T13:29:15.113500Z

also there’s https://github.com/walmartlabs/lacinia for GraphQL

2020-10-10T14:23:00.114300Z

Fantastic, thanks 👍

2020-10-10T14:24:16.116100Z

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 🙂

dharrigan 2020-10-10T14:31:13.116300Z

next.jdbc and honeysql are winners

1👌
dharrigan 2020-10-10T14:31:32.116500Z

I use both extensively in my applications

JoshLemer 2020-10-10T16:19:21.118Z

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

littleli 2020-10-12T09:46:02.192300Z

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

JoshLemer 2020-10-10T16:20:00.118800Z

(running this in calva vscode)

alexmiller 2020-10-10T16:20:27.119600Z

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

alexmiller 2020-10-10T16:21:00.120500Z

For multi arity, declare the method twice with different arities

JoshLemer 2020-10-10T16:21:58.120800Z

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

alexmiller 2020-10-10T16:23:20.121300Z

Well maybe I’m misremembering then!

alexmiller 2020-10-10T16:23:43.121900Z

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

JoshLemer 2020-10-10T16:23:52.122100Z

thank you, definitely a tooling thing, cheers!

alexmiller 2020-10-10T16:24:39.123100Z

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

alexmiller 2020-10-10T16:25:04.123700Z

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

pez 2020-10-10T16:43:37.123900Z

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

pez 2020-10-10T16:49:39.124100Z

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

2020-10-10T16:59:23.124300Z

The symbol.name in the error is nonsense

2020-10-10T16:59:53.124500Z

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

2020-10-10T17:01:14.124700Z

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

2020-10-10T17:06:40.127200Z

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

JoshLemer 2020-10-10T17:13:19.127300Z

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

JoshLemer 2020-10-10T17:15:20.127500Z

@pez Answered you in the other thread

2020-10-10T17:24:01.129400Z

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 ☺️

seancorfield 2020-10-10T17:37:16.129600Z

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

sova-soars-the-sora 2020-10-10T17:53:58.130Z

that's a cool idea.

1❤️
2020-10-10T17:54:38.130300Z

Doh. Thanks!

pez 2020-10-10T18:51:46.131700Z

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

pez 2020-10-10T19:18:02.132Z

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.

practicalli-john 2020-10-10T19:50:16.132300Z

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/

1❤️
uosl 2020-10-10T20:04:19.132700Z

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/

1❤️
Markus Agwin 2020-10-10T22:57:48.133400Z

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.