Fork me on GitHub
Jorge Tovar00:01:57

Hello, another question:

(def dark-roast-coffee-desc "Dark Roast Coffee")
(def dark-roast-coffee-cost 0.90)

(defn make-dark-roast-coffee
      ([] (beverage dark-roast-coffee-cost dark-roast-coffee-desc))
      ([size] (beverage dark-roast-coffee-cost dark-roast-coffee-desc size))
is there a way to re-use the values of dark-roast-coffee-desc and dark-roast-coffee-cost inner the function with multy-arity?


re-use in what way?

Jorge Tovar01:01:25

be inner the scope of the function :thinking_face:


What does that mean? They are def’ed in the namespace. They are visible in all scopes below their definition

Jorge Tovar01:01:32

yes, but what If I wanna make this values private. like (let [cost 0])


Only forms inside of that let block can see cost. Seems pretty private to me

Jorge Tovar01:01:36

Its an example


What’s an example where you’d actually like them private then?


you are already doing it


the values are bound to names, the names are in scope and usable from both arity bodies

Jorge Tovar01:01:36

yes I like the current solution, but def values are visible in (:require [my.namespaces]). no?


Yes, make everything visible

Jorge Tovar02:01:55

OK no problem


(let [dark-roast-coffee-desc "Dark Roast Coffee"
      dark-roast-coffee-cost 0.90]
  (defn make-dark-roast-coffee
    ([] (beverage dark-roast-coffee-cost dark-roast-coffee-desc))
    ([size] (beverage dark-roast-coffee-cost dark-roast-coffee-desc size))))
@jorgetovar621 That will make those names local to the function, but it's somewhat unusual to have let-over-`defn`

Jorge Tovar01:01:20

Thank you so much. Thats exactly what im looking for


Having default positional arguments is what is causing you problems here really. You might want to rethink that...

Jorge Tovar01:01:46

yes. The test failed. Im gonna leave as def values, I think is good enough by the moment, thank you


Default positional arguments do not compose very well -- as you can see, having beverage take an optional positional argument forces make-dark-roast-coffee to also take an optional positional argument. I'd consider it a "code smell".

Jorge Tovar01:01:29

thats a good point


Hi guys. I want to learn clojure + redis and I need to choose a cloud provider. Would you go for Heroku or AWS, and why?


I know my way around AWS reasonably well but I just noticed Heroku supports Clojure.

Ovidiu Stoica07:01:23

Hei guys, so I have this next.jdbc function:

Ovidiu Stoica07:01:55

If I use the actual db for both commands this works

Ovidiu Stoica07:01:26

But if I use conn I get

Ovidiu Stoica07:01:47

None of the tables have a id column, and I would love to use the same db connection for both queries

Ovidiu Stoica07:01:26

nevermind, I found the issue. conn is not passed the kebab-snake-case options of the db . Fixed 👍


I have made this layout in hiccup


Can someone help me to make this in react so I can show a global window to show data of a painting


I mean more think in what are the components to make this work ?

Piotr Brzeziński11:01:08

Global window you mean like a modal?


yep, a overlay with a modal screen


but first I have to make this in react or reframe

Piotr Brzeziński11:01:09

It uses classes but shouldn’t be hard to move it to hooks


Thanks, I will look at it


just following a course on re-frame


@roelof are you using bootstrap or something like this?


fotr that one no bootstrap is used


only css and html


see here for the html and css I used :


how you could do this in reagent / re-frame: have one component which paints the modal, but only when some state is set, e.g. (subscribe [::show-modal]) and set the re-frame db :show-modal value to true, if a user has clicked on one of these paintings


the same is true for reagent-only but you can do it with atoms


oke, but I mean a step before the modal


can I make the layout with re-frame and if so , are all the paintings a componennt and all the shelves


or can it be one big component. That is really my question


you can make one component for the modal:

(defn modal []
  (let [show? (subscribe [::show?])
     painting-id (subscribe [::painting-id])]
  (fn [] 
(if @show?  
[:div [:img src="..."]])
(sorry for the layout, typing code in Slack is...)


you can split up things in as many components as you would like, just as when writing functions


oke, I can image that because of the subscribing I can better can make every painting a component. So a different text can be displayed


yeah, you can do that


pff, now hiccup is messing with my layout code so far :


the last image is totally at a wrong place


Hi, is there a lib in Clojure for the SMPP protocol? To enable SMS messaging between applications and mobiles?


I haven't tried using SMPP, but I have used Twilio's clojure library to successfully send text messages


my app method looks like this : |

(defroutes app
  (GET "/" [] (-> (memo-display-data)
  (route/resources "/")
  (GET "/favicon.ico" [] ""))


and this is the beginning of my templte

(defn convert-to-hiccup [data]
    [:meta {:charset "utf-8"}]
    [:title " Most popular paintings from the Rijksmuseum "]
    [:link {:href "/css/styles.css", :rel "stylesheet"}]]
   (display-body data)])


Re: "Clean Code" -- if you can come back to it in 6 months and [swiftly] reason about what the code does and the intended results, that's clean. If not, time travel back six months and tell yourself to add more documentation and stop using Java 😛


sorry to ask so many but can I make this work without the fn

(defn flatten-a-sequence [s]
  (reduce (fn myflatten [collection element]
            (if (sequential? element)
              (reduce myflatten collection element)
              (conj collection element))) [] s))


why not just use flatten?


that is forbidden. I think we have to re-implement flatten


Given a sequence of hash-maps, is there a predicate function I can use to determine if any of the hash-maps contain a specific key with specific value? So far I have a function mapped over the vector of hash maps which returns a sequence of true false. I'd like a boolean true or false answer returned, rather than a sequence of bolean values. The key is always a top level key. I'd rather not use a library other than clojure.core

(map #(= (:key %) "fish") [{:key "fish"} {:key "chips"} {:key "peas"}]) 


you could use some rather than map

👍 1

(some (comp #{value} :key) coll)


sometimes my brain only lets me type map - I think I am map obsessed :)


then you're never lost 🙂


you asked for something that returns true or false and technically, the some version will return true or nil. that probably doesn't matter, but wanted to point it out, just in case

👍 1

I think I am okay with a falsey nil 🙂

👍 1
Bret Horne23:01:47

I saw a similar example of this kind of destructuring on a blog post but im not finding this in my google searches.

(defn hello [{:keys [] :as rest}] 
Is it that the :keys [] bit merely takes the entire map you give it vs say more selective destructuring with {:keys [a b]} a-map?

Lennart Buit23:01:43

That said, I don’t understand what you are asking, could you elaborate ^^

Bret Horne23:01:50

I’ve scoured it…Am I mistakenly missing it? I dont see an instance of having an empty vector.

Lennart Buit23:01:23

I don’t think an empty vector does much

Bret Horne23:01:43

For instance if I were to use that style with

(defn hello [{:keys [] :as rest}]
  (println (str rest)))

(hello {:hello "hello"})
{:world "world"}

(hello {:hello "hello" :world "world"})
{:hello "hello", :world "world"}


an empty vector for :keys doesn't do anything

Bret Horne23:01:08

ah is it merely needed for using :as blah?


you can just have :as blah without the :keys

Lennart Buit23:01:42

no, not even that (defn hello [{:as rest}] …) or (defn hello [rest] …) would also both work

👍 1
Bret Horne23:01:09

oh! duh 😛


"from the map, please bind no keys and call the whole thing rest"

👍 2
Bret Horne23:01:00

(this was the first place I saw it: so it struck me as curious.

Bret Horne23:01:24

(defn main [args {:keys [] :as opts}] ...)

Lennart Buit23:01:00

Yeah, maybe to visually show that opts is a map, maybe its the authors preference to always define :keys […] for future extension, or maybe its just an oversight 🙂

Bret Horne23:01:20

(thanks for the help!)


or if it's a template, it could be a placeholder for adding the options you expect

👍 1
Bret Horne23:01:33

yeah fair (Even mentions in the article that the following could be used as a template. I misunderstood.)