Fork me on GitHub
#beginners
<
2018-12-29
>
seancorfield00:12:26

@mss The splice operator might be what you're looking for here inside a macro definition: [email protected] see https://clojure.org/reference/reader#syntax-quote

mss00:12:09

thank you!

Mattias00:12:34

Forgive a somewhat confused question from the perspective of someone who has been interests in lisps for a long time but only recently realized Clojure was a thing... the “data as code thing”. I’m curious (honestly so) about in what sense/senses that is true, or maybe more correctly relevant. Especially as compared to other relatively main stream languages...

Mattias00:12:11

It occurred me to consider this, as I suspect but haven’t verified that I probably can’t access Clojure code as actual data at runtime? If I can actually insert an sexpr into a function in runtime the question pretty much falls 😅

seancorfield00:12:39

@mattias504 Code is just a series of lists and vectors etc. For example (list 'def 'foo 42) produces (def foo 42)

seancorfield00:12:44

Macros are functions that are run on the code forms before they are compiled and run. So they are just transformations of data structures, that accept code as input and produce code as output.

Mattias00:12:18

Hmm. So code is data to macros but not (you can kill me now 😛) to “real” code?

Mattias00:12:50

Oh, and thanks a lot for having the patience to answer! Appreciated 😄

seancorfield00:12:20

(defmacro make-foo [v] `(def ~'foo ~v))
for example, so
(make-foo 42)
will produce
(clojure.core/def foo 42)
which is then compiled and executed

seancorfield00:12:05

If you said

(make-foo (+ 40 2))
it will produce
(clojure.core/def foo (+ 40 2))
-- the arguments are "just code", not evaluated.

seancorfield00:12:01

There's a function eval that you can pass data to at runtime and it will attempt to compile and run it.

seancorfield00:12:20

user=> (eval (list '+ 40 2))
42

seancorfield00:12:18

In this case the argument is evaluated -- eval is a regular function -- and so it's the same as (eval '(+ 40 2))

seancorfield00:12:41

(hopefully that clarifies rather than confuses?)

Mattias00:12:51

Very cool. Will need to take some time to digest this, thanks. On my mobile now so will be back later, wiser 😀

Stevan03:12:18

This code as data thing looks confusing but promising

kari13:12:22

I need one gen-class for using a Java library from Clojure. I tried to find information where to call the compile function for that class in the application. Now using REPL is a bit problematic since when reloading all namespaces in REPL the gen-class is not found.

_rj_r_18:12:27

Can anyone recommend any content that provides a solid walkthrough of a web application using Clojure, deps.edn, scss, hiccup (or similar), that does not include anything to do with Luminus or Clojurescript? I'm looking for as basic as possible so I can get a grasp on the simple tooling things before stepping up into the more complex. It seems as though almost everything jumps straight into Clojurescript, Figwheel, Om, Re-frame, Luminus.... or it has a walkthrough but doesn't include things like scss, or even Garden for that matter. I've ran out of options in my google searching, I'm hoping something exists and I just missed it somehow. I can figure out the syntax of each library. My confusion lies in, for example, how to compile scss (or Garden, but would prefer scss) into a Clojure web app that doesn't use Clojurescript, Luminus or any of the other things I listed above that I'm not interested in at this time. Any suggestions to content would be appreciated... thank you.

athomasoriginal19:12:00

@UAW40E21F I might be able to show an example if I can better understand what you are looking for: It sounds like you are not interested in a SPA of any kind and you just want to see what it looks like to serve up a simple server side web app with Clojure, yes?

_rj_r_19:12:50

That is accurate. Including compiling and pulling in scss, using deps.edn to build, and any other handy things you might see fit.

athomasoriginal19:12:50

I found Edge to be helpful https://github.com/juxt/edge. It does an excellent job of showing a Clojure web app with all kinds of goodness using the latest and greatest. Be warned, there is a lot going on and knowing the bare minimum requirements is a little difficult if you are not familiar with Clojure. I found the basic tooling and project structure matched my own sensibilities so much so that I took some time to break down what I saw as the “core” components of Edge: https://github.com/tkjone/reveng-edge Its not done, and Edge has changed a bit since I did my first run through, but reveng-edge should provide some of the core things you are looking for. For example, if you want to see what at the most basic serving some text would look like, you would checkout https://github.com/tkjone/reveng-edge/tree/master/web-server. Once you see that, you might want to add the reloaded-workflow so you would check out the additions here: https://github.com/tkjone/reveng-edge/tree/master/web-server-reloaded. You may want to add server side rendered templates so checkout this https://github.com/tkjone/reveng-edge/tree/master/web-server-templates. If you do not want the reloaded workflow, just review web-server/reloaded-workflow and compare it to SSR-templates. The SSR Templates one might be more of what you want as it is clearer to see how you can 1. Add routes 2. serve HTML from the server and 3. add CSS to your html (I do not include CSS, but I can guide you through that in DM if you need)

athomasoriginal19:12:10

I know you were looking for more of a guide/blog post, but I have not come across any outside of luminous. Most of what is available are example projects like Edge or https://github.com/robert-stuttaford/bridge

Kelly Innes21:12:52

In case this is helpful: I've been trying out ClojureScript/Reagent by setting up a single page app with Leaflet, which is something I'd usually do with JS/React/Redux at work. The repo is here: https://github.com/kellyi/reagent-leaflet-sandbox

Kelly Innes21:12:20

So far I have 1. set up development and production builds 2. set up using a JS-library, Leaflet, 3. set up some app-state Reagent atoms with a minimal thing to persist the map zoom level in local storage, 4. added some linting stuff using cljfmt, kibit and bikeshed

Kelly Innes21:12:40

I skipped doing re-frame for now because although I like it conceptually it feels like a lot to take on when just starting out.

_rj_r_21:12:00

Thank you for all the resources. Apologies for not responding sooner, got caught up running errands. Very appreciated to everyone that has responded so far. I'll take a look at all the links

kari19:12:39

Gen-classes are pretty nice way to create simple Java classes that are needed e.g. when using some Java library via Clojure/Java interop. The only major issue I had was how to use REPL effectively with gen-classes. My standard procedure to refresh everything: (do (require '[clojure.tools.namespace.repl :refer [refresh-all]]) (refresh-all)) (compile 'my-gen-class) ... didn't work with REPL - REPL used the older version of gen-class and I had to restart REPL every now and then which was a bit of a nuisance.

JanisOlex19:12:49

hi, people. It seems I can't find what is session lenght of ring-session and how can I set it to something

Eccentric J21:12:31

Looking through the source there may be two parts to adjusting session length: https://github.com/ring-clojure/ring/blob/95e4ca25d5b98c45f927b32b5c3c85c21c999d96/ring-core/src/ring/middleware/session.clj The first being :cookie-attrs which can have an :expires date or :max-age https://github.com/ring-clojure/ring/wiki/Cookies the second being the store you use which by default is the mem store.