Fork me on GitHub

hello wonderful people, I'm looking for direction on how best to use a set of popup for data presentation (not ads, this is an internal tool, clojure/clojurescript/om)


@U7AHRRSS2 sure, what is it you don't know how to do?


@U06GS6P1N I just don't know where to start I think I am googling for the wrong terms.


@U7AHRRSS2 it's difficult to help without knowing what you already know how to do. Do you already have an Om app to add this functionality to? Do you know web development (in CLJS)? Are you wondering how to layout a poput in terms of HTML / CSS?


In case that's the last one, I would have a look at bootstrap modal:

Javier Pérez15:10:28

Hi everyone! I was trying to convert some strings into numeric literals and got some unexpected behaviour. Can someone explain this?

(read-string "07")
=> 7
(read-string "08")
NumberFormatException Invalid number: 08  clojure.lang.LispReader.readNumber (
(read-string "09")
NumberFormatException Invalid number: 09  clojure.lang.LispReader.readNumber (
(read-string "10")
=> 10


@javipeg try 010 - that might be a clue

Javier Pérez15:10:55

That one works too


right, but look at what it returns

Javier Pérez15:10:49

(read-string "010")
=> 8


it's octal - leading 0 tells it the number is base 8


+user=> (read-string "36rclojureiscool")


that tells it to use base 36 😄 - pretty useless but funny


I'm still looking for assistance in getting a data popup sorted out. Basically, in om I need to have a button that launches a popup modal with close button with scroll that pretty prints a PersistentMap.


What I currently have but it isn't quite working

(dom/button #js{:onClick #(js/alert (with-out-str (cljs.pprint (-> data))))} "Model")


Possibly your lambda isn’t correct. Since it takes no arguments, it might be getting passed and argument, and the execution would fail.


Maybe (fn [_] (js/alert ...)) instead of #(js/alert ...)


I rebooted and it started working


(dom/button #js{:onClick #(js/alert (with-out-str (pprint/pprint (-> data))))} "Model") Will be a quick fix until I can get a more permanent modal up


isn't cljs.pprint a namespace? do you mean cljs.pprint/pprint ?


or, really, you should require cljs.pprint and give it a shorter name in any ns that uses it


okay changed the call to pprint/pprint ...


but it still isn't launching the alert. But I'm not even sure that this is the correct way to do it as the PersistentMap is quite large.


I'm a bit stuck here. I need to take a default value a sequence of keys and return a map with the default value set to each key.


*a default value and a sequence of keys


changing the value if the key is already there, or only updating with thedefault if not present?


only updating with the default


(merge defaults m)


where defaults is a map from key to default value


oh wait maybe I misunderstood


you want the defaults to clobber?


(zipmap keylist (repeat default))


The output I need is {:a 1 :b 1 :c 1}. I must pass it 1 and [:a :b :c].


anatpaatra, can you write out a small example of input and output and what the defaults are?


oh damn, wait haah


so you need to make a map out of a vector of keys and a single value, where each key in the vector has the single value you give it?


clojurebot takes a while to wake up, haha


@dpsutton a map out of a sequence of keys and a single value


his second example is what you are looking for


yeah, zipmap / repeat is the ticket there


the great news is that you don't have to even write a function


hey @noisesmith, past few days you helped me a lot with the tip of using component to startup my system and stateful resources. one thing that I’m struggling to accomplish is that sentence > the idea is most of your functions stay pure, based only on arguments … how usually you accomplish that ? for instance, I have one endpoint ( using your idea of middleware to inject the database and other components I need ) that will validate against database and call one external service ( aws cognito ) . how you divide/organize your function to keep most pure as possible ?

Lucas Barbosa20:10:17

@oliv I’ve been trying to answer that question for the past couple of weeks

Lucas Barbosa20:10:31

I am reading SICP right now, to get a better understanding of functional design

Lucas Barbosa20:10:59

But I am still unsure of how to structure a large application

Lucas Barbosa20:10:23

in order to separate pure functions from dirty outside interactions

Lucas Barbosa20:10:12

btw, SICP is freaking awesome. I regret not reading it before! 😬


@oliv the big picture answer is that the component/start function runs all your initializers (connecting to dbs, opening ports, opening files, all that) and the function that does that is the impure one - it takes a map with other components plus config and returns a "started component"


the other components, plus your main app code, use the hash-map of started components returned by the component/start call to do all the things that need those resources


of course you need pure and impure elements in real code - the trick is to make sure that you aren't pretending something is pure that leaks impurity underneath - the component architecture helps you do that by explicitly segregating startup from functionality


yeah, I see ! my “service” layer is a mixed of pure + impure ( database + service calls … )


feeling that I’m doing OO but with a different syntax


@oliv right, it's less about purity at that point, and more about making sure all the inputs to your function are given via arguments. That also makes it easier to test, want a temp DB? Just pass in a different arg.


yeah @tbaldridge exactly . my compromise right now is to receive everything that I need from arguments ( using component help me a lot )


want a hash-map in memory instead of a document store when testing? if you wrote your component right, you can do that by providing a different arg on system startup


yeah, sounds like you are doing it right so far then


so my functions ending with (defn whatever [hash-components args1 arg 2 .. ] )


Make sure though that each function takes only the components it needs. If you hand everything to every function there's a temptation to introduce tight coupling where everything needs everything in order to do anything.


so, my function should be (defn whatever [ db congito-client arg1 arg2 ] )


or I could destructuring (defn whatever [ {:keys [db cognito] } arg1 arg2 ])


you don't have to split out the parts of the component, just write the components so you don't pass in things it doesn't need


(and write the functions integrating with the components accordingly of course)


yeah - the tight coupling around the component can be a problem for sure - it seems like someone is always trying to grab the global component reference and use that instead of using what's passed in, or write things that expect every single component to be available and visible


Component helps with this though


the system has all the components, but under each component's entry are the components it needs. so it's as simple as not passing the system to each function, but the component


yeah, better receive as arguments the components than use the system inside the function

Lucas Barbosa20:10:55

Is a function that receives another function as an argument and invokes it considered pure if the function given to it is impure?

Lucas Barbosa20:10:42

for instance: `

Lucas Barbosa20:10:07

(defn foo

Lucas Barbosa20:10:25

if bar can be impure, is foo pure?


@lvbarbosa for the purpose I care about foo is pure - I can test it without mocking what bar does or creating an environment where it's safe to run bar in a test


I can just provide a stub


if foo isn't pure, map isn't pure, filter isn't pure, etc. - which most of us would find an odd definition of purity

Lucas Barbosa20:10:40

So I am not spreading impureness throughout my system if I start up some components (e.g. connection pools) and pass them around?

Lucas Barbosa20:10:03

hidden in functions or other abstractions


it's containing impurity, because the other choice is to write code that directly accesses the impure capabilities via global references


I wish "impurity" had a different name, because my desire for it as a software developer isn't about some sort of puritanical rejection of side effects, it is that if I contain impure things and use them as parameterizations of my code rather than building blocks, I can easily test and reason about the logic


so, the rule of thumbs is: avoid global references, always only use what you receive as arguments, right ?


right - for things with side effects at least


constant global references are safe


if we did that with everything our code would get very silly


and in a good clojure codebase almost everything should be constant (modulo repl mechanics)


the rest can be handled by your state management / initialization setup hopefully


i wonder, are dynamic vars considered bad in clojure, since technically they break referential transparency?


they seem used exactly how you would in common lisp, which is incredibly useful, yet it's clearly against the hard-line haskell position


nothing is ever outright bad, it's a matter of using features only when they are the best alternative and/or make sense. pragmatism in other words


referential transparency is a very good property to be strived for, but not at any cost


That's good news. I've found a few dynamic vars in libraries exactly where I wanted them too, which has been really refreshing in a JVM setting 🙂


good to hear!


[insert 'acceptable lisp' comment here]


Are there any easy ways to consume free-floating jar files from Leiningen?


hi, is it normal the clojure community use lowercase headers for http server?


From RFC 2616 - "Hypertext Transfer Protocol -- HTTP/1.1", Section 4.2, "Message Headers": > Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.


I thought that standard Ring middleware for headers converted them to Sentence-Case before returning them, but I may be wrong that is not the case. I know that the middleware converts them all to lowercase to make them, essentially, case insensitive (and it specifically uses .equalsIgnoreCase to ensure case insensitivity).


^ @rcustodio So, yes, it's normal to use lowercase -- because the Ring Spec says headers should be downcased prior to passing the Ring Request to a handler -- and they are not case sensitive so it doesn't matter whether you use lower-case or Sentence-Case.


I wonder why ring needs to lower case.


I suppose to merge in the multiple header case