Fork me on GitHub
#beginners
<
2017-07-20
>
seancorfield01:07:48

@genec (if (seq xx) ... would be more idiomatic (and faster) than (if (> (count xx) 0) ...

seancorfield01:07:52

(defn map-but-last
  [f1 f2 coll]
  (map #(%1 %2) (conj (into [] (repeat (dec (count coll)) f1)) f2) coll))

seancorfield01:07:04

(has the disadvantage that it isn't lazy because it counts the collection)

seancorfield01:07:08

(defn map-but-last
  [f1 f2 coll]
  (map (fn [[x y]] (if y (f1 x) (f2 x))) (partition-all 2 1 coll)))
That would be lazy

seancorfield01:07:35

(map-but-last inc dec (range 5))
=> (1 2 3 4 3)
and
(take 20 (map-but-last inc dec (range)))
=> (1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20)
(note that it never hits the "last" element so it only ever calls f1)

jstokes02:07:38

partition-all trick there won’t work if the list contains false or nil

jstokes02:07:20

(map-but-last
  (constantly :a)
  (constantly :b)
  [false false false])
;; => (:b :b :b)

jstokes03:07:29

(defn map-but-last
  [f1 f2 coll]
  (let [[h & t] coll]
    (if (seq t)
      (lazy-seq
        (cons (f1 h) (map-but-last f1 f2 t)))
      (list (f2 h)))))

sundarj04:07:04

should that inner map-but-last be recur?

seancorfield06:07:58

@U61HA86AG No, because the call is not in the tail position, so recur is not allowed there.

sundarj06:07:41

@seancorfield ah, of course. thanks!

pitalig03:07:30

Thanks a lot guys!

seancorfield06:07:35

@jstokes Good point, but changing the function to (fn [[x _ :as pair]] (if (= 2 (count pair)) (f1 x) (f2 x))) would solve that 🙂

femiagbabiaka14:07:09

has anyone here used the automata library? (https://github.com/ztellman/automata) I’m working on a project that could use a state machine, but I have some noob-ish questions about an implementation. to save time — how would I go about using functions to determine state changes?

jeremys21:07:50

Hey guys i don’t really know where else to ask this question even though it is not exactly clojure related. Anyways... I am trying to push a jar onto clojar but here is the problem. I am following the tutorial about gpg https://github.com/technomancy/leiningen/blob/stable/doc/GPG.md At some point I need to gpg --list-keys to get my KEY_ID so that I can publish it then use it to sign my jar and push to clojars. Unfortunately the output of gpg --list-keys isn’t the same on my machine as it it in the tutorial, the KEY_ID isn’t displayed and I can’t find how to make gpg display it. Going nuts... plz help 🙏

seancorfield21:07:17

@jeremys Two options you might want to consider: telling Leiningen not to sign the JAR and avoiding the whole GPG thing; switching to Boot which doesn't sign JARs by default and therefore side-steps GPG as well.

seancorfield21:07:51

I never managed to get GPG working on my Windows laptop and I've had GPG/GPGTools get corrupted twice on my Mac, so I finally gave up on it. The time it forgot my private key and wouldn't accept the correct passphrase so my GPG "identity" was basically broken -- and that's the second or third time that's happened to me and I've had to start over and create a new key and publish that... and it just doesn't feel like it's worth the effort for such flaky software.

mobileink22:07:26

seancorfield: gpg is flaky? that would be pretty shocking. i've used it for years on osx with no prob. how do you know gpg was the problem?

seancorfield22:07:08

I've had the GPGTools on Mac break repeatedly over the years. Very frustrating.

mobileink22:07:56

seancorfield: ok, won't argue with that. but gpgtools != gpg, no?

seancorfield22:07:37

I'm sure the underlying encryption stuff is solid -- but the tooling that interacts with Mail and interacts with Leiningen doesn't seem solid.

mobileink22:07:38

i use (i think, heh) the brew stuff.

seancorfield22:07:21

I only started using it because Phil was such a hard-ass about encouraging people to sign stuff 🙂

seancorfield22:07:06

He tried to encourage key-signing parties at Clojure conferences but I think he was fighting an uphill battle...

mobileink22:07:33

yeah, but you're painting with a pretty broad brush, imho. let's not blame gpg for the failings of tools that use it.

seancorfield22:07:10

Not being able to use it on Windows with Leiningen meant I could only ever update Clojars from my Mac and so I started to switch projects to Boot to get around that 🙂

mobileink22:07:53

ok, but still gpgtool is flaky != gpg is flaky.

seancorfield22:07:10

I don't know what specifically corrupted/forgot my keys on OS X but the fact that it's happened more than once makes me tired of dealing with the toolchain -- and I don't need it for anything except satisfying Leiningen (and I could just turn that off per repo if I could be bothered to figure it out... but I'm using Leiningen less and less anyway so it's just not worth the hassle).

seancorfield22:07:32

It's all "GPG" as far as I'm concerned.

mobileink22:07:21

that is very unfair imho. but i still luv you! ;)

seancorfield22:07:07

I edited the message to say GPG/GPGTools 😛

mobileink22:07:55

haha, i unnerstand.

seancorfield22:07:58

A lot of GNU stuff is very user-hostile and poorly documented (and I say that as someone who has contributed to GNU software, by the way!).

mobileink22:07:42

well, how else to maintain a priesthood???

mobileink22:07:21

GNU is definitely not for everybody.

jeremys23:07:27

not it is not, the tutorial from the leinigen docs on gpg is better than what I found on the actual website... I understand why Phil would encourage to sign though.

jeremys21:07:30

Thanks @seancorfield I didn’t know boot did that! though after close to an our on the internet I foudn the answer to my problem in a page not really related. You can actually use the command gpg --keyid-format (short/long) --list-keys to get the output as in the tutorial.

jeremys21:07:07

I guess gpg on windows might be hard and to frank and very opinionated the style of documentation of gnu projects of especially this one isn’t really helpfull.

jeremys21:07:22

Little digression, if you take a look at the discussion on the clojure channel apparently clojure might release it’s own dependency tools that isn’t dependent on maven. We might be able to pull our deps from github directly some day...

seancorfield21:07:04

Given that Clojars no longer support the whole "promotion" thing (which required signed JARs) and a lot of people don't bother signing JARs, I'm not sure how important it is. For a while I used to "sign" all my emails, as well as my JARs, but several friends complained their email client couldn't read signed emails so I gave up on that first 😐

seancorfield21:07:45

Yeah, pretty sure both Leiningen and Boot have a way to deal with dependencies as checked-out GitHub repos.

seancorfield21:07:39

There are a couple of tech stacks out there that let you declare a dependency as a GitHub coordinate username/rep@sha so there's a precedent.

jeremys21:07:40

I think you can do it in go.

jeremys21:07:32

In any case thanks for the help. I might try to sign this jar since I don’t really want to admit defeat yet. But I might consider giving it up later 🙂

gonewest81823:07:09

gpg has always been unforgiving and irritating except during short windows of time when I'm really concentrating on getting something done with it. Afterward all is quickly forgotten and usage needs to be relearned more or less from scratch the next time.

jeremys23:07:31

@gonewest818 yeah I think you got it just right!

jeremys23:07:39

still I finally managed to do it!!!