Fork me on GitHub
#clojurescript
<
2019-01-01
>
hoopes02:01:22

is there a good library for http path substitution? Something like /some/:id/:thing or ["some" :id :thing] with args {:id 123 :thing "foo"} and results in /some/123/foo? Seems easy enough to do by hand, but though there might be a lib out there…all the routing libs seems to do it, couldn’t find a common underlying thing though… thanks!

lilactown16:01:26

a lot of routing libraries do this. e.g. reitit

mateusz.fiolka13:01:32

Hi, I'm doing:

(defn update-task [db id-to-find fn]
  (->> db 
       :tasks
       (map-indexed (fn [idx item]
                      [idx (= id-to-find (:id item))]))))   
and getting
Use of undeclared Var planning.core/idx

  75  
  76  (defn update-task [db id-to-find fn]
  77    (->> db 
  78         :tasks
  79         (map-indexed (fn [idx item]
  80                        [idx (= id-to-find (:id item))]))))   
Any idea what's wrong with that? (cljs 1.10.339) Seems I'm missing something obvious :thinking_face:

mfikes13:01:12

@mateusz.fiolka Your update-task function has fn as a parameter, and thus (fn ...) no longer has its usual meaning. A shorter repro is

(defn f [fn] (fn [a] a))

mfikes13:01:11

In that case you have the option to re-name the parameter, or instead, if you want the usual fn, use cljs.core/fn instead.

mateusz.fiolka14:01:26

Damn, that was tricky coincident. I'll rename it. Thanks @mfikes 🙂

dpsutton18:01:23

Wow I'm surprised that fn isn't a special form

dpsutton18:01:17

Although now thinking of all the destructuring there's no way it would be

dpsutton18:01:36

And multiple arities

absolutejam19:01:05

So, I'm pretty much brand new to Clojure as a whole but I'm super interested

absolutejam19:01:14

Coming from a Python background as a sysadmin who also occasionally writes utilities/apps, can ClojureScript provide the same utility?

absolutejam19:01:03

Obviously I could use Clojure itself but I'm thinking for script level stuff, pulling from npm would be great and id never have to touch js (thank god)

lilactown19:01:24

both Clojure and ClojureScript can be used for small scripts

absolutejam19:01:07

I've been writing a small utility in clojure just to whet my whistle / wear out my parens

absolutejam19:01:23

But wondered if clojurescript might have a better time for this kinda thing generally being based on node (right?). I also saw some complaints about JVM startup time but I have some flags to test that apparently speed that up. The whole JVM thing is something I'm aware of but I'm not java guy

lilactown19:01:38

Clojure is easier now IMO - all you need is a call to the clojure command, and to construct a deps map if you need some libraries. But some people don’t like the startup time, esp. when you start adding lots of deps

lilactown19:01:16

yeah, JS has capture quite a bit more of the ops mind share so you might find more libraries for more complex needs. but you never know

lilactown19:01:46

for CLJS scripting, lumo is probably better than creating a CLJS built app

lilactown19:01:27

but lumo (being self-hosted) comes with some of it’s own idiosyncracies

absolutejam19:01:36

It's a bit daunting with all the different options

absolutejam19:01:49

Lumo, planck, joker for clojure

lilactown19:01:39

if what you want is to leverage NPM and write CLI scripts, then lumo is the way to go

absolutejam19:01:11

I'll take a look, thanks

absolutejam19:01:33

Perhaps a dumb question - what is the current use case for clojurescript?

rutledgepaulv19:01:01

imo: most of the same reasons you’d choose clojure (immutability, powerful stdlib, selective use of state, syntactic abstraction, good libraries, low ceremony host interop) + clojurescript specific things like: a more data-driven take on react, great bundle optimization with closure advanced treeshaking, less impedance mismatch if using a clojure backend.

absolutejam20:01:52

I mean what kind of implementation is the most popular?

absolutejam20:01:05

Like server side js, front end, etc?

absolutejam20:01:15

I don't really do js :woman-shrugging:

rutledgepaulv20:01:32

oh. mostly browser stuff. some do clojurescript on mobile, a few server side with node but I think most people in the clojure community would just use clojure at that point

absolutejam20:01:14

On cool, makes sense

absolutejam20:01:33

And the end user would never know right? Because it compiles to pure js?

rutledgepaulv20:01:13

in the browser? yes compiles to js.

rutledgepaulv20:01:44

though they might notice how fast and well built it is troll

dnolen20:01:06

@james662 ClojureScript was created basically to run Clojure where you don't have access to the JVM for whatever reason

dnolen20:01:11

browser, mobile apps being the most popular for obvious reasons

absolutejam20:01:04

Right, makes sense

dnolen20:01:14

pretty much all the points in the original ClojureScript presentation are still true https://www.youtube.com/watch?v=tVooR-dF_Ag wrt. rationale

jstaab21:01:50

@james662 I'm in the midst of writing a clojurescript library for use in a js frontend, and which can also be run as a web service on its own (so I can use complex business logic in both places without re-writing it). For this, I've found shadow-cljs the best option (after trying lumo and cljsbuild), since it has really good support for various targets, including tests with hot reloading. This mostly takes care of the jvm startup time required to build a cljs project without lumo, while also providing libraries from both js and clj ecosystems. A (more traditional) alternative would be .cljc files included in a clojure project for the web service, and a cljs build for the javascript side, but I opted for pure cljs since I'm more familiar with js than java. To be perfectly honest, getting started has been a huge pain, so feel free to DM me if you'd like any pointers. Clojure is worth it though 🙂