This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-20
Channels
- # aws-lambda (7)
- # beginners (113)
- # boot (17)
- # cider (4)
- # cljs-dev (4)
- # clojure (65)
- # clojure-greece (3)
- # clojure-italy (7)
- # clojure-russia (10)
- # clojure-spec (37)
- # clojure-uk (20)
- # clojurescript (76)
- # community-development (2)
- # cursive (24)
- # data-science (9)
- # datomic (9)
- # emacs (1)
- # fulcro (2)
- # graphql (11)
- # hoplon (13)
- # juxt (15)
- # leiningen (1)
- # off-topic (36)
- # om (1)
- # onyx (59)
- # parinfer (41)
- # pedestal (7)
- # portkey (60)
- # protorepl (4)
- # re-frame (345)
- # reagent (7)
- # ring-swagger (16)
- # shadow-cljs (121)
- # spacemacs (30)
- # sql (6)
- # uncomplicate (2)
- # unrepl (9)
- # vim (13)
- # yada (2)
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: http://getbootstrap.com/docs/4.0/components/modal/
thanks!
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 (LispReader.java:330)
(read-string "09")
NumberFormatException Invalid number: 09 clojure.lang.LispReader.readNumber (LispReader.java:330)
(read-string "10")
=> 10
@javipeg try 010 - that might be a clue
That one works too
right, but look at what it returns
(read-string "010")
=> 8
interesting
it's octal - leading 0 tells it the number is base 8
of course
+user=> (read-string "36rclojureiscool")
59714396063025843189N
that tells it to use base 36 😄 - pretty useless but funny
thanks!
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.
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
(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
yeah, zipmap / repeat is the ticket there
Thanks 🙂
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 ?
@oliv I’ve been trying to answer that question for the past couple of weeks
I am reading SICP right now, to get a better understanding of functional design
But I am still unsure of how to structure a large application
in order to separate pure functions from dirty outside interactions
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 … )
@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
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.
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
Is a function that receives another function as an argument and invokes it considered pure if the function given to it is impure?
for instance:
`
(defn foo
[bar]
(bar))
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
So I am not spreading impureness throughout my system if I start up some components (e.g. connection pools) and pass them around?
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
if we did that with everything our code would get very silly
@mseddon exactly
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 🙂
Are there any easy ways to consume free-floating jar files from Leiningen?
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).
Ah, per the Ring Spec: https://github.com/ring-clojure/ring/blob/7b1657128991e483232cd1ee3b87d2cc481e269c/SPEC#L98 they are deliberately downcased.
^ @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
.