Fork me on GitHub
#clojure
<
2016-03-05
>
arrdem00:03:00

@smw: @cch1: binding will work.

lumengxi00:03:34

newbie question, when i do (sort {:b 2 :a 1}) it returned ([:a 1] [:b 2]) in REPL, what is the data structure? why it didnt return {:a 1 :b 2}, if sort doesnt work in this way, why it sort the map but return a diff data structure?

dbacar00:03:39

@lumengxi: i am not sure but a map and a list are different things, map is not guaranteed to be in order

dbacar00:03:32

i guess you can not sort a map, that is IMHO sort converts the map to a list and gives you an ordered representation

lumengxi00:03:12

@dbacar: thanks! it does look like that sort converts the map to a list, interesting

dbacar00:03:53

please i am also a 4 year clojure newbie

dbacar00:03:19

dont take that info for granted simple_smile

bostonaholic01:03:18

@lumengxi: check out clojure.core/sorted-map

lumengxi01:03:14

@bostonaholic: thanks! yea i found that func, was just curious why (sort {:a 1 :b 2}) would return something like that

arrdem01:03:48

@lumengxi: maps are seqs on their kv pairs, sort converts the input to a seq and then sorts.

arrdem01:03:35

hence you get a (sorted!) seq of kv pairs back

lumengxi01:03:35

@arrdem: sorry, another newbie q: if map is already a seq, what do you mean by sort converts it into a seq again?

arrdem01:03:22

@lumengxi: sorry I was being imprecise. map is not a seq, but it can be converted to one. In this instance it is.

lumengxi01:03:48

ha got it, thanks!

hiredman01:03:22

a seq is sort of similar to an iterator. so in order to sort the map '{:a 1 😛 2}' you need to traverse the elements

hiredman01:03:49

you'll see seq refered to as a "functional iteration protocol"

urbanslug02:03:58

Good morning.

echristopherson02:03:21

can you actually use 😛 in Clojure to mean :b? 😉

mike_ananev03:03:11

hello all. i'm interested in hugsql. http://www.hugsql.org . Is there any example how to do JOIN using hugsql?

mike_ananev03:03:09

@yogthos: Hello, Dmitry! I've read your article about hugsql? Can you tell where i can find example how to make JOIN using HugSQL?

yogthos03:03:42

@mike1452: hi, I guess you mean how to use table qualified keys?

yogthos03:03:01

@curtis.summers would probably have the answer for this one simple_smile

mike_ananev04:03:20

@yogthos: thanx! (brief search by word JOIN did not return any useful results from docs) well, now i have a search direction

yogthos04:03:21

@mike1452: do you have an example of the query you’re trying to write?

curtis.summers12:03:25

@mike1452 A JOIN in HugSQL is just a JOIN in SQL. I guess I'm not exactly clear on the question, but I'm happy to help work through it.

rauh12:03:14

How would I approach debugging c.t.namespace.repl/refresh? refresh wants to reload a CLJS namespace (in my CLJ code) even though the ns is never references, not on classpath. I also tried to set ctnr/set-refresh-dirs manually but the cljs macro file still gets picked up (and then "not found exception"). EDIT: Got it, inspected the #'refresh-tracker var and found out that it got picked up in resources (where cljs also compiles to). So I filtered resources|target directories from the classpath and did set-refresh-dirs and it works simple_smile.

fxposter12:03:11

@stuartsierra: hey, in http://thinkrelevance.com/blog/2013/06/04/clojure-workflow-reloaded you’ve mentioned that “ring-devel is incompatible with tools.namespace”. As I understand - it currently is, and if I add wrap-reload to my ring stack - it would still work fine until: 1. dev.clj file (where the system is located) is changed. I guess the system will still work, as it would reference the objects, but I won’t be able to stop the currently running system. 2. components structure is changed and so the old components could miss some data? Am I right? And are those the only problems? Thanks in advance!

george.w.singer14:03:32

How can one take a string like "file.extension" and return ".extension"?

george.w.singer14:03:48

I.E.: How does one get the extension of a filename in clojure

curtis.summers14:03:01

See the extension function from this lib: https://github.com/Raynes/fs

george.w.singer14:03:24

bleh -- unfortunately I'm working in clojurescript

george.w.singer14:03:29

So can't use that

george.w.singer14:03:37

Perhaps I should ask in #C03S1L9DN

curtis.summers14:03:19

May need to write a regex for it.

mmeix14:03:59

improvising: (apply str (last (partition-by #{"."} "my.pdf")))

mmeix14:03:22

just tried in a REPL

mmeix14:03:10

but I'm sure it could be even simpler...

george.w.singer14:03:42

Even works for names like "double.dot.jpg"

mmeix14:03:00

yes, takes only the last portion after the "."

hugesandwich17:03:49

Is there any good way of working around having a protocol that does a conversion split across multiple namespaces when extended? I saw something like this argued in the past here: http://programming-puzzler.blogspot.com/2013/12/frustrations-with-namespaces-in-clojure.html While I disagree with a lot of what is written here and certainly don't support circular dependencies, in the case of protocols it makes sense to have a "merged" version. For example if I define in a "core" namespace conversions to/from various collection types, then in a more specific namespace I extend the same protocol to add in more specific conversions. As far as I know/have seen when the protocol is called and hits the "core" extend-protocol, it won't see the specific definitions. Thus it's not really possible to nest your conversions like that unless you put it all in 1 namespace.

arkh17:03:15

@george.w.singer (let [[_ x] (re-find #"(\.[^\.]+)$" "file.extension")] x)

jan19:03:15

Is there a way to do a conditional assoc, which only associates the key, if the given value is truthy?

mmeix19:03:05

wouldn't this just be something like (defn assoc-when [c k v] (if v (assoc c k v) c))?

mmeix19:03:06

seems to work for me

mmeix19:03:50

(how do I format code her in Slack?)

solicode19:03:20

With backticks: code

mmeix19:03:36

ah.. let me try

solicode19:03:44

Okay, we’ll I can’t show it, but you get the idea 😛

mmeix19:03:26

(defn assoc-when [c k v] (if v (assoc c k v) c)``

solicode19:03:40

One backtick

mmeix19:03:55

(defn assoc-when [c k v] (if v (assoc c k v) c)

solicode19:03:58

I was trying to escaping it

mmeix19:03:02

great - thanks!

mmeix19:03:24

I think my function is a correct solution simple_smile

mmeix19:03:56

(it doesn't check for c being a mp though)

mmeix19:03:24

forgot a parens, so:

mmeix19:03:44

(defn assoc-when [c k v] (if v (assoc c k v) c))

jan19:03:48

cool. looks good.

jstokes19:03:06

anyone using environ know if there is a way to “reload” configuration in a running repl session?

jstokes19:03:31

ive tried setting system properties (System/setProperty … …) but it doesnt seem pick it up

jstokes19:03:30

i had some luck with ns-unmap and redefining the env var, but that seems like a roundabout way

jack_liang22:03:32

hi, whats the correct way to use the logger? Like what kind of information do i log? do i log the result of my application?the arguments entered? my application is a text summariser

jack_liang22:03:27

or if anybody could point me to a decent source regarding the conventions for what or when to log something, thank you

weavejester22:03:11

jstokes: Environ provides access to the process environment. You shouldn’t use it directly as a configuration.