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?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)]))
The Encore library has multi-assign when-let and if-let
@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."
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.)
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.
juxt clip is another alternative to component and integrant. works really well
(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.)
Fulcro is great for writing React SPAs
I use Reagent for frontend and Pedestal for backend, both are well-established libraries that are being used in production by lots of companies
also there’s https://github.com/walmartlabs/lacinia for GraphQL
Fantastic, thanks 👍
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 🙂
next.jdbc and honeysql are winners
I use both extensively in my applications
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]}
....
...
I believe the issue with incomprehensible error was fixed in the release yesterday.
(running this in calva vscode)
Multi arity is not supported in protocols with that syntax, but that seems like a weird error, maybe due to tooling
For multi arity, declare the method twice with different arities
Is the protocols page out of date? I took this sample from https://clojure.org/reference/protocols Thanks again!
Well maybe I’m misremembering then!
I always have to look it up because it’s different
thank you, definitely a tooling thing, cheers!
I think I’m confusing it with impl in defrecord/deftype sorry
But I still think the error is weird and looks like tooling
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.)
I don't get that error when evaluating the form, btw. It defines P
, foo
and bar-me
.
The symbol.name in the error is nonsense
So my guess is alex is suggesting that some tool is mangling it
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
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
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
@pez Answered you in the other thread
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 ☺️
There are #honeysql and #sql channels if you have questions about HoneySQL or about SQL in general (and next.jdbc
in particular).
that's a cool idea.
Doh. Thanks!
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
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.
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/
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/
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.