Fork me on GitHub

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


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


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


(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


(map-but-last inc dec (range 5))
=> (1 2 3 4 3)
(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)


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


  (constantly :a)
  (constantly :b)
  [false false false])
;; => (:b :b :b)


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


should that inner map-but-last be recur?


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


@seancorfield ah, of course. thanks!


Thanks a lot guys!


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


has anyone here used the automata library? ( 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?


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 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 🙏


@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.


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.


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?


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


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


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


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


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


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


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


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 🙂


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


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).


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


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


I edited the message to say GPG/GPGTools 😛


haha, i unnerstand.


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!).


well, how else to maintain a priesthood???


GNU is definitely not for everybody.


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.


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.


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.


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...


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 😐


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


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.


I think you can do it in go.


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 🙂


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.


@gonewest818 yeah I think you got it just right!


still I finally managed to do it!!!