Fork me on GitHub
#clojure
<
2016-04-07
>
krchia00:04:04

my emacs keeps hanging up

krchia00:04:16

i think it’s because it’s looking for documentation when i’m halfway writing code

krchia00:04:19

any way to turn this off?

tcrawley01:04:55

@lvh: can you recommend a clojure client for working with Rackspace cloud files?

tcrawley01:04:44

apodini is one, but I'm curious if Rackspace recommends one in particular: https://github.com/sonian/apodini

slipset09:04:44

looking at data.csv, I see that it is pretty much bound to clojure

slipset09:04:02

and not usable in clojurescript

slipset09:04:28

It would be really nice to be able to use data.csv in eg planck or other selfhosted clojurescript environments.

slipset09:04:45

Would @jonase be interested discussing something like that?

urbanslug12:04:55

Clojure would win if it had typeclasses. Like apply looks a lot like fmap.

bronsa12:04:48

apply is nothing like fmap

bijoy13:04:44

apply works like a specialized form of map, and map is a specialized form of fmap for list kind, would that be fair

bronsa13:04:45

I don't agree with "apply works like a specialized form of map" at all -- that would imply you can implement apply on top of map, which you cannot

bijoy13:04:49

what I tried to say, by the special form is (apply str '("hello" " " "world!”)) the similarity to (reduce + ‘(1 2 3 4)), just used reduce since the other one is str, so you have a function and a type as input and get back another type, which I thought is fmap

bronsa14:04:54

what does reduce have to do with map?

hasskell14:04:57

Hey guys I am new in Clojure, any advise where to start learn???

fasiha14:04:10

@hasskell: what's your background?

manutter5114:04:07

I’ve heard good things about http://www.braveclojure.com/

hasskell15:04:59

@fasiha: more then two years Java mostly.

nkraft15:04:25

There's also Eric Normand's http://www.purelyfunctional.tv if you prefer entertaining videos to text.

urbanslug15:04:42

@bronsa: apply is nothing like fmap? Okay. It’s iterating over a sequence though. Sequence is (typeclass-ish). Yes map is not a specialised version of apply as map is fmap, what I meant is function application over a sequence.

urbanslug15:04:16

I’m kinda new to clojure though

bostonaholic15:04:13

apply doesn’t iterate over a sequence

bronsa15:04:04

@urbanslug: they're doing fundamentally different things though, so I really don't think even comparing them makes sense. apply takes all the items of a sequence and invokes a function over all of them, map iterates over those items applying f over each one of them

fasiha15:04:34

@urbanslug: apply transforms a sequence into arguments: (apply foo [a b c d])(foo a b c d), so no iteration right?

urbanslug16:04:49

I had it all wrong

urbanslug16:04:37

I skim through docs.

fasiha16:04:04

There are so many little magical functions in Clojure (I discovered juxt when it was being discussed here, and tentatively used it today) that it takes a lot of practice with them to remember what does what

fasiha16:04:29

Dear JVM people, discovering this was not cool: (format "0x%x" (bit-shift-right (byte -128) 1)) ; => "0xffffffffffffffc0" 😛 that is, when bit-shifting a byte, I did not expect my byte to be silently upcast to signed Long, shifted, and returned as a Long with a bunch of leading 1s. I wrote up a description of JVM/Clojure bitbanging semantics at https://clojuredocs.org/clojure.core/bit-shift-right#example-570683fae4b0fc95a97eab30 but still a shock.

Lambda/Sierra16:04:59

Java isn't a great language for bit-manipulation in general. No unsigned byte types.

Lambda/Sierra16:04:05

And Clojure's default coercion to Long makes it worse.

fasiha16:04:18

@stuartsierra: absolutely, it's my fault for coming in with assumptions. I vaguely knew that JVM didn't have some unsigned types but I didn't make the connection from that to my failing code 😛

fasiha16:04:58

But now it's all sorted and I'm getting some nice data on this Raspberry Pi (`lein repl` start time: 2 minutes!) from my sensor via RS-232 serial 😄

lvh16:04:20

tcrawley: I don’t think Rackspace officially recommends a Cloud Files client for Clojure. For Java, it recommends jclouds. There are Rackspace Cloud Files specific plugins, but the regular OpenStack one works just as well. There have been projects to port jclouds to Clojure but AFAIK all of them have pretty much stopped. We’re using RCF internally (well, as a private cloud user) so if you figure out which one works well, I’d love to know 😛

tcrawley17:04:14

@lvh: after my ? last night, I discovered the clojure that ships with jclouds, and have been using that to play with. I'm not yet sure if I like it

lvh17:04:23

tcrawley: It’s pretty Java.

lvh17:04:41

tcrawley: I have some code that might help you

lvh17:04:37

tcrawley: I wrote some stuff a long time ago to make it more pelsant to use, and I’m not really sure I succeeded

tcrawley17:04:31

@lvh: interesting, thanks!

ag18:04:22

guys, how can I “beautify” big chunk of edn? I have it in my clipboard, inserting that in Emacs buffer with clojure-mode on, hangs Emacs. I couldn’t find a way to do that in Atom or LightTable

arrdem19:04:05

@ag: cljfmt is a library 😄

arrdem19:04:23

@ag: also this is pretty much what fipp was designed for.

hiredman19:04:50

if you have huge chunks of edn, you might want to consider a binary format like fressian instead

hiredman19:04:00

there is a certain point (which may be subjective) where the scale of the data makes the fact that you encode it in a human friendly way (json, edn) irrelevant

ag19:04:23

@hiredman: I just need to inspect it, not to transfer, etc

lmergen19:04:39

binary formats only makes sense some very specific performance-sensitive situations

hiredman19:04:26

hindsight is 20/20 there though

lmergen19:04:31

i think one should be very, very conservative in introducing those

hiredman19:04:10

if you have a bunch of data, and suddenly you need to add new process of that data, which is bottlenecked on reading and writing edn, what are you going to do?

lmergen19:04:04

well yes that would be exactly one of those very specific situations one is unlikely to encounter in real life, and when you are, you usually know well in advance

hiredman19:04:16

that is not my experience

hiredman19:04:53

my experience is people choose an easy to inspect encoding like edn, and then pay for it later

lmergen19:04:40

it completely depends upon the use case, but i have yet to encounter a single case where that happens -- usually when things go so big that you need binary serialization, you have multiple very qualified engineers working on the project, and they know well in advance when to choose such an encoding type

hiredman19:04:40

fipp is amazing if pprint is all you have used in the past

lewix19:04:42

(defn contains-key [seek-key hashmap]
  (loop [[k, _] (first hashmap)]
      (if (= seek-key k)
        true
        (if (nil? k)
          false
          (recur (first (dissoc hashmap k)))
         )
      )
  )
)
; execution timeout; someone has better eyes than me ; this is a silly exercice as I'm getting familiar with clojure. I do know I can do it in one liner thanks

hiredman19:04:19

you don't change the hashmap in the recursive case

hiredman19:04:46

you are always dissoc one key from the same map, not an ever shrinking map

arrdem19:04:19

A clearer implementation perhaps would be

(defn contains-key [m k]
  (loop [[entry & rest :as coll] (seq m)]
    (if (empty? coll)
      false
      (or (= (first entry) k)
          (recur rest)))))

hiredman20:04:18

(which is filter)

hiredman20:04:06

(boolean (seq (filter #(= k (key %)) m)))

lewix20:04:35

@hiredman: i see thanks, ill think about a solution

lewix20:04:47

@arrdem: i have different implementation, trying new ones

cpmcdaniel20:04:43

ok, so let’s say you have a seq of key-value pairs, and you want to put them into an array-map (so they are in the order that you inserted them)...

cpmcdaniel20:04:39

so it converts to a hash-map on the 10th item

cpmcdaniel20:04:54

they only way I’ve found to get what I want is this...

hiredman20:04:58

the best thing to do is to not care about order for maps

bja20:04:19

there is an array-map that doesn't upconvert as a library

hiredman20:04:45

if you insist on doing that, the way to think about it is, maps are an index of a key to value, and you want a second index of numerical order to map entry

cpmcdaniel20:04:58

but I haven’t been able to get any incantation of conj, into, or assoc to keep it an array-map

hiredman20:04:22

two indices = two maps

cpmcdaniel20:04:33

yeah, but I need both lookups by key and ordering

hiredman20:04:34

but really, don't do that

bja20:04:45

but in general, I would go hidredman's route of avoiding the need to have an ordered map if at all possible

cpmcdaniel20:04:58

because the values in the map have a dependency order

hiredman20:04:22

so keep two maps, one dependency graph and one k/v

hiredman20:04:15

if you want to get really fancy use clojure.set/index to build little database like things

hiredman20:04:25

with arbitrary indices on your data

Lambda/Sierra20:04:39

If you want to preserve insertion order, the easiest thing is probably a map plus a vector of keys.

Alex Miller (Clojure team)20:04:54

if you want to make a deal with the devil, you can use LinkedHashMap too (the deal being mutability of course :)

Alex Miller (Clojure team)20:04:25

but really, don't do that :)

lewix20:04:52

(defn contains-key [seek-key hashmap]
  (loop [newhashmap hashmap]
    (let [[k, _] (first newhashmap)]    
      (if (= seek-key k)
        true
        (if (nil? k)
          false
          (recur (first (dissoc newhashmap k)))
         )
      )
    )
  )
)

lewix20:04:10

java.lang.UnsupportedOperationException: nth not supported on this type: Keyword

pmooser20:04:44

That's a common message when you try to destructure something incorrectly.

pmooser20:04:48

That code works fine for me with simple cases like:

pmooser20:04:56

(contains-key :a { :a 100 })

pmooser20:04:08

Ah, but it fails like this:

pmooser20:04:17

(contains-key :a { 😛 100 :a 200})

lewix20:04:45

I see my mistake thanks

lewix20:04:50

forgot to remove some code

lewix20:04:22

defn contains-key [seek-key hashmap]
  (loop [newhashmap hashmap]
    (let [[k, _] (first newhashmap)]    
      (if (= seek-key k)
        true
        (if (nil? k)
          false
          (recur (dissoc newhashmap k))
         )
      )
    )
  )
)
; here you go

pmooser20:04:26

Yup, it's the extra call to 'first'.

pmooser20:04:46

Also, you didn't ask for this, but you should group up all the trailing parens together, instead of trying to use them to 'see' the scopes like you would with curly braces.

lewix20:04:39

i prefer this style

futuro20:04:44

Does anyone know how to get clj-time to keep the timezone from the DateTime object when creating a TimeStamp?

lewix20:04:31

@pmooser: it alows me to not forget parens and fix it quickly ; im not sure im a fan of the parens. still getting used to it

pmooser20:04:49

6ewis, it's fine to prefer that style, but the likelihood is that there's not actually a benefit to it. You'll be better off if you stop doing it, but feel free to ignore my advice.

pmooser20:04:31

Alternatives that I have found are helpful are tools to have you - a syntax-aware editor, or things like paredit. Ok, enough unsolicited advice.

futuro20:04:32

@lewix: Does your editor support something like Paredit or Parinfer?

bronsa20:04:38

@lewix: you'll quickly get used to the conventional style, which helps immensely reading code, and with some editor tools like paredit/parinfer, you'll never have to deal with parens manually

lewix20:04:31

@bronsa: @futuro I used vim that supported some parens lib, i used light table and now im using cursor - and I still prefer this style (in your defense I use it all in the span of a week)

lewix20:04:00

I just find it cumbersome to follow when parens are grouped together

pmooser20:04:19

I find chinese cumbersome because I haven't learned to speak it yet.

base69820:04:31

how do I get the version specified in the project.clj from the command line? Hoping there is a command to do it for shell script?

lewix20:04:45

fine. can you write js like this now that you're used to it? @pmooser

lewix20:04:22

if(..) {..{..{}.}.}

pmooser20:04:36

@lewix I don't mean to be pushy about this - honestly I'm trying to help because I've seen this many times before. I work in a bunch of languages, and I try hard to adopt the common conventions in each language, because they're not the same. When I write js, I format it like people format js.

base69820:04:49

hah, you can do: lein pprint :version

lmergen20:04:23

i dont actually think the problem is that 6ewis should be able to "parse" the parens in his head -- i never count them myself -- i just let the editor do the work. @lewix my strong advice is to bite the bullet and learn how the editor can manage the parens for you, rather than resorting to esoteric ways of aligning them

lewix20:04:43

@pmooser: you're trying to help but you're not listening - as im learning it's not helping so i remove some mental load by arranging the parens in a fashion that does not add extra thinking time

pmooser20:04:40

I'm listening - I think you are overvaluing your immediate comfort level. I've literally been where you are now, 8 years ago.

pmooser20:04:57

It's a matter of short-term versus long-term investment.

lewix20:04:10

let's agree to disagree about my comfort level. I'd argue that you undervalue it

pmooser20:04:20

Look, nevermind. Unsolicited advice is obviously not useful to you in this case. Good luck.

lmergen20:04:26

similar like learning how to code with the REPL -- better learn that as quickly as possible

lewix20:04:04

@lmergen: im using an online live repl atm

lmergen20:04:13

well there you go!

lewix20:04:48

I admit that when i use the editor its a tad easier but still

lewix20:04:11

I tend to rearange it

futuro20:04:44

@pmooser: Yeah, thank you

sveri20:04:45

@pmooser: @lewix When I started learning clojure I was doing the same. But mainly because I was copying around a lot of stuff and keeping parens farer below is immensly helpful with that. Starting to take the parens below does not mean you will do it forever. I adapted the community style a bit later without problems.

pmooser20:04:14

@sveri It's really common among beginners coming from other languages everywhere.

futuro20:04:40

Huh, I wonder how you handle historic dateTime's when DST is in effect

futuro20:04:13

Does JodaTime just automatically understand that a -5 offset might mean something else for part of the year?

tomjack20:04:41

I had to double check that the "namespaced maps" email didn't go out April 1 simple_smile

tomjack20:04:57

I wonder if destructuring will ever get any love

futuro20:04:38

Let's abolish Daylight Savings Time

futuro20:04:49

Can that be in the 1.9 release?

bostonaholic20:04:07

@futuro: why stop there? UTC all the time!

bostonaholic20:04:36

the world would be a better place if everyone were on 24 hour UTC

futuro20:04:34

@bostonaholic: Are you sure about that? We'd still need to understand when people in other parts (parts other to our place of residence) are generally awake.

bostonaholic20:04:57

is that different than knowing who is awake right now?

bostonaholic20:04:54

or in 6 hours from now

futuro20:04:58

oh, sorry, I was misunderstanding UTC

futuro20:04:11

I thought you were advocating for the abolition of timezones

bostonaholic20:04:45

basically, if I say I’ll meet you at 13:30, everyone in the world knows when that is

bostonaholic20:04:51

it’s a PITA when I email with team members across the world and we have to use MST/MDT/EST, AM/PM etc.

futuro20:04:28

I can understand pushing for 24 hour UST, with timezone offsets, but I'm still working through the implications of complicating removing timezones as a notion

hiredman20:04:40

timezones are basically crude spacial locators, and the notion that you can observe a time independently of a location is generally absurd

bostonaholic21:04:06

well, when I email someone and say “I’ll call you at 3pm MDT” and they reply with “OK, 3pm MST it is!” I have a problem with that

mihaelkonjevic21:04:13

I just had this conversation today. If we removed timezones, we would have to find some other way to put context around time.

mihaelkonjevic21:04:51

otherwise 3pm doesn't mean anything because you don't know if 3pm is in the middle of the night somewhere across the world

futuro21:04:19

You'd still need to understand when "normal" hours are for the person you're communicating with

bostonaholic21:04:37

you need to know that either way

mihaelkonjevic21:04:37

and timezones carry that bit of information simple_smile

futuro21:04:40

I think MST/MDT/CST/etc are pretty terrible

futuro21:04:02

but saying "Let's get together 15:30 z-5"

futuro21:04:09

or however you want to denote timezone

bostonaholic21:04:11

I still need to know when (relative to me) my colleague in Turkey is working

futuro21:04:23

yeah, that's a timezone, right?

bostonaholic21:04:25

but if we both agree on 13:30

bostonaholic21:04:29

no other information is needed

bostonaholic21:04:51

he says “I’m available from 7 to 14"

mihaelkonjevic21:04:54

well you can agree to communicate in GMT time, that's basically it

futuro21:04:10

Instead of encoding a timezone, you'd encode a "daytime interval"

futuro21:04:08

I mean, you could offer up a time you like, say 7-14, and he could then counter with 12-23, but you could also just ask him his "daytime interval" and start with a suggestion when he'd be awake

futuro21:04:30

not encoding "daytime interval" just means you're doing more work, yeah?

bostonaholic21:04:31

I believe you’re over complicating it

bostonaholic21:04:57

1) forget everything you know about time

base69821:04:04

I'm trying to build a deploy job on jenkins and failing massively. I need to get the version/jar name from the project file, but am failing spectacuarly. lein pprint :version works locally but not on jenkins

futuro21:04:20

I think you might be over-simplifying it; why would you offer a time that your colleague would be asleep for?

futuro21:04:35

If you only ever offer times when you're awake, you're assuming that the people you're working with are geographically close to you, right?

mahinshaw21:04:38

@base698: is the lein pprint plugin in your user profile, or is it in your project. If it’s not in your project, then it wont be available on jenkins

base69821:04:48

adding to project

base69821:04:29

@mahinshaw kind of worked. do you know how to make pprint not print quotes around a string?

base69821:04:46

I was sed'ing it off locally but that's not translating to jenkins

mahinshaw21:04:31

@base698 I don’t think you are going to get that behavior out of lein pprint. you are likely going to have to do that cleaning yourself, or fork lein pprint to add that behavior. It sounds like you want the behavior of prn.

base69821:04:22

prn i think prints "" too

base69821:04:36

I guess both are supposed to be machine readable

mahinshaw21:04:00

pr and prn print so that the output is readable by the clojure reader

mahinshaw21:04:33

@base698: ohh right you need 0.1.0 not “0.1.0”. Yeah, you will have to do that in a post process step I guess

base69821:04:04

Anyone know who maintains the jenkins plugin?

zentrope22:04:41

Has anyone had trouble with the component lib in the repl such that when you start, then stop, then attempt to start again, the components don’t actually start?

zentrope22:04:13

It’s as if (component/stop system) permanently kills the system. Reset fixes it.

zentrope22:04:04

Same prob using weavejester’s reloaded lib, and must using my own rewrite, or using an atom (vs alter-var-root) to manage the system map, etc, etc.

hiredman22:04:44

do your stop implementations return the component?

zentrope22:04:08

Heh. (Sorry if this is in two places.) I’ll check. I might have missed one.

zentrope22:04:58

They all return this or (dissoc this :some-key), but I wonder if it’s possible something somehow swallows an exception?

zentrope22:04:16

Running in the repl, I don’t invoke the “uncaught exception handler” fallback, it seems.

zentrope22:04:01

Drat. That’s not catching anything.

zentrope23:04:08

Fix (thanks @hiredman): don’t (dissoc component :some-value) on lifecycle/stop. Converts component to map, thus making every component in the SystemMap no longer satisfy component/Lifecycle.