Fork me on GitHub

(defn show-landing-pg [req]
 (let [ {params :params} req
        {username :username} params
        {password :password} params
        {session :session} req]
        (println req)
        (println ";sesh'''; " session)
  {:status  200
   :headers {"Content-Type" "text/html"}
   :session (assoc session :username "zzzzzzzz2222222255555555522222222ZZZzzz")
   :body    (slurp "resources/public/index.html")}))
does not update the session at all


You need to use some middleware to support sessions

Brandon Olivier05:09:24

Is s/fdef supposed to actually run any validation on a function during development time?


@brandon149 Only if you use instrument (argument checking) or check (generative testing of the function).

Brandon Olivier05:09:00

@seancorfield thanks It seems like it’d be helpful to use instrument on every function running (at least during some dev time work) is that a common thing, or is spec more designed to just run on one particular function at a time?


You can (st/instrument) will which instrument all functions for which s/fdef has been evaluated (so those namespaces have to be loaded).


But that might slow down your tests so just instrumenting the functions you're testing / developing is probably best.


Have a read of this and see if it gives you more insight on using Spec

👍 2
Lennart Buit06:09:16

Fair note: the default st/instrument only checks :args specs, no :ret/`:fn`. If you wish to instrument both, you can use orchestra:


hello, i'm playing around with gen-class and class inheritance. I have the following: (ns test.core (:gen-class :name test.core :prefix "t-" :extends javax.swing.JFrame :init init :constructors {[String] [String]} ) (:import (javax.swing JFrame))) (defn t-toString [this] (println "JFrame title: " (.getTitle this))) (defn t-init [x] [[x] (ref {})]) i'm slightly confused about the role of init..Is there any way to include some other action in there like for example (.setSize this 200 300) like i would do in java in the class constructor (after i called super()) ? or do i need to define a separate function and call that one once the object has been created, i.e. (def fr (test.core. "Testing frame")) (.setSize fr 200 300)

Andreas S.07:09:32

Hello I want to build a clojureScript applicatin, can you recommend a good project template that works with java 12 (windows)?


I believe that it's snake_case and kebab-case

❤️ 1

at least, that's how I've always seen it


or maybe it's kabob-case


to me camelCase feels more natural especially when playing around with java libraries


but it's just matter of taste


of course you have to use camel case when calling into libraries that use it, but I think it's pretty clear that the preferred Clojure style is kebab case. How many camel case names do you see on this page that aren't links to javadoc?

David Pham11:09:21

In ClojureScript, how does Java Nashorn fit into the picture?


I don't have great knowledge here, and asking in the #clojurescript channel is likely to find more people knowledgeable of this topic. My understanding is that Nashorn is deprecated, and perhaps might be removed from a future JDK version, although it still exists in the latest OpenJDK versions. I have used it to run JavaScript code that was the output of the ClojureScript compiler, just fine.


It is not getting any new active development, as far as I am aware, unlike other JavaScript runtime engines, which are still being actively developed.


hi, this is probably a very noob question but i'm not a very experienced java-guy either: is there an easy way to tell slurp not to cache read file contents?


afaik (and just tested in the repl) it's not caching?


lol maybe i got some issue with intellij actually saving the file with a different file handle or stuff like this - let me check


that's weird:


i'm doing it in a comment form and re-evaluating the slurp


start repl > slurp file > foo=bar > edit file foo=baaz > slurp again from same repl > foo=bar > cat the file foo=baaz > edit file using cat > slurp in same repl > foo=baaz


did that too and it's good for me.


well, just by editing thef ile that is.


didn't do it with cat


hm, what's your intellij setting for saves?


ah I'm not using intellij atm, I'm using vscode and atom


ha, this did the trick for me


safe writes does something weird with the file handles


probably moving files instead of actually editing theri contents


after deactivating this option it works as expected


So my server is run with http-kit at the moment..

(defn -main [ & args]
		(server/run-server all-routes {:port 8117})
		(println "server on @ localhost:8117"))


I want to turn it into

(def app
  (wrap-defaults all-routes site-defaults))


Soo... actually as straightforward as

(defn -main [ & args]
		(server/run-server (wrap-defaults all-routes site-defaults) {:port 8117})
		(println "server on @ localhost:8117"))


slash beginner's mind


Hi everyone, I'm trying to find my way into ClojureScript but have now hit a wall setting up a development workflow: I keep running into a Java ClassNotFoundException concerning javax.xml.bind.DatatypeConverter. I've found a way around this by specifying a particular version of ClojureScript (1.10.520) in my build.boot. I'm still encountering the problem though when trying to launch the ClojureScript REPL. I've put more details into a question on StackOverflow: I'd be super grateful if anyone of you could advise me on what I'm doing wrong… I'm really eager to finally get coding! Many thanks in advance and thanks to the devs for an amazing language! Oliver


In that question you say you did some Googling, and you found some answers relevant for when going from JDK 8 to JDK 9, but you did not think they were relevant because you are using JDK 11.


I think they are relevant, because the things you found relevant for going from JDK 8 to JDK 9 are relevant whenever going from JDK 8 to JDK later than 8


Hi Andy, many thanks for the quick reply. I totally see your point. Still I'm wondering why I'm running into a problem dating from 2017… I have revisited a couple of said Google results. It seems the problem can be solved from the side of Java or ClojureScript. On the Java side I tried setting my environment variable BOOT_JVM_OPTIONS to "--add-modules java.xml.bind". But that gives me "java.lang.module.FindException: Module java.xml.bind". Maybe I'm doing something wrong since I know very little Java. (see Some say to just wait for the next ClojureScript release (which has been around for quite some time now) … to my surprise I had to specify it manually and could thus make it compile. It's just that this doesn't affect the ClojureScript REPL where I still get the error… Also I think to have all my libs set to the latest versions… or is there still anything deprecated in my build.boot? Thanks again Oliver


I've also tried setting JAVA_TOOL_OPTIONS: to "-Djdk.launcher.addmods=java.xml.bind", which does get picked up by boot… but changes nothing as to my problem with the REPL…


Regarding your comment of why you are hitting a problem from 2017, if you have recently changed a project that was using JDK 8, to using JDK later than 8, then it shouldn't be surprising that you may hit issues that others noticed when JDK 9 came out.


As far as more details on the particular issue, I do not have any more knowledge to share there. I mainly wanted to comment that JDK 8 -> 11 has many issues in common with JDK 8 -> 9 transition (plus possibly more).


Also, for issues specific to clojurescript, you may find more people aware of the problem on the #clojurescript channel than this one.


Hey everyone! If you're learning Clojure recently and have web experience but want to check out the Clojure-way to build APIs, checkout my starter guide:


Hi, thanks… could have thought of this myself… I however managed to solve it now … indirectly thanks to your advice to revisit the 2017 stuff… I had to also specify a more recent version of http-kit in my build.boot. So for now things seem to be working… still I'm puzzled why my setup would default to these old versions of libraries… I am indeed following a tutorial written when Java 8 was standard but I have replaced all version strings contained in the tutorial snippets with newer ones…so I still don't understand why I have to add newer versions of libs not even mentioned in the tutorial and why they would default to older ones… but hey, this is sort of academic at this point at least. Many thanks for your input… sometimes one just needs to talk to someone!


This may be a long shot, but if the person who wrote the tutorial is willing to update it for more current versions of software, that might be helpful to others besides you. And it sounds like you have something working for them to refer to, if they have such interest.


I have not used boot, so do not know if it has a command to do this, but leiningen and clj command line tools have options that direct the tool to show you all of your project's dependencies, and their dependencies, recursively. Using such a command on your project before the fix you found, and after, might help determine why the older version of http-kit was being used.


thanks… I'll look into it! Still learning the basics and trying to stick to the tutorials, which tend to become outdated pretty quickly…


Well, when they involve libraries or aspects of the language runtimes that change across versions, then they tend to keep working for those same versions just fine. It just isn't very easy to find a machine to run JDK 6 on any more, if you find a tutorial that used that. Most stuff is backwards compatible, but those aren't the things that cause the issues you notice.


I'm trying to do something that I think is very simple and write a function that tells me true/false if it contains the number 2

(defn contains-2 [numbers]
    (mapv (fn [num] (= num 2)) numbers))
(contains-2 [1 3 4 5])
(contains-2 [1 2 3 4])
however when I run the two calls, it returns [false false false false] and [false true false false]. How can I make it return only true OR false?


It is also common to use a set (`#{}`) when testing for the existence of some elements. Using some (as suggested earlier) you could write the contains-2 function as:

user=> (boolean (some #{2} [1 2 3]))
user=> (boolean (some #{2} [1 1 3]))


use some instead of mapv


yay thank you @noisesmith!!


you can wrap it as (boolean (some ...)) if you strictly need true/false instead of true/nil


even better =]


i added session middleware to my application and my app doesn't like my cljs POSTs


cljs GETs work but don't let me pass :params...


do I need to provide session data in my cljs (ajax) POST to my server?


did you add a CSRF prevention middleware?


if so, you need to switch to a post method that uses the CSRF token


@sova one thing to look for is if when you post the client is trying to make an OPTIONS query


(in the network tab)


Yes I added CSRF


right on. thanks


do you know what to call it in the params?


just :anti-forgery-token perhaps?


oh i see thank you, it's been a few years since i played with CSRF intimately


I have a question, can I do subsequent POSTs with one token or will it require a new token for each POST?


like the first successful POST should probably return the new token?


(ad infinity)


@sova In general, CSRF works by using a unique token for every interaction (but I'm not sure how that works with async calls that could be in various different orders).


Right?! so yeah. lol. i wonder. can I just disable csrf for the specific urls?

Lennart Buit20:09:18

I don’t think you want to disable CSRF protection

Ewan Valentine21:09:25

Bit of a weird one:

user=> (/ 200 (* 1000 60 60))
^ Anyone know why that might happen?


because it's the correct answer?

😛 1
Ewan Valentine21:09:01

I was expecting a whole number, I'm trying to convert between hours and ms, and came across this


if you want floats, you can provide one floating point arg, or call double on the result

Ewan Valentine21:09:26

Full function:

(defn to-hours [ms]
  (mod (/ ms (* 1000 60 60)) 24))

Ewan Valentine21:09:21

So it's presenting a decimal as a fraction?


right, because floats lose accuracy, and the Ratio type used for fractions does not


> (type (/ 200 (* 1000 60 60)))


by providing a float or double arg, you opt into the loss of accuracy

Ewan Valentine21:09:09

Gotcha, that makes sense


there's also a BigDecimal type


Hey guys, someone knows the most idiomatic way to add an element to an array that is inside a map?


like someMap.list.push( item )


(update m :key conj x)


ooh, thanks! 😄


assuming you mean a Clojure vector, when you said array (which some people use more often to describe a mutable array in Java/JavaScript/etc.)

👍 1

yeah, we have access to actual arrays too, but on the JVM those are not resizable


CSRF works fine with ajax POSTs, doesn't need a new token