Fork me on GitHub

is there an existing clojure/java function for “incrementing” a string ala Ruby#succ? > "some_label_1".succ => "some_label_2"


I don’t think one should do these things


@pithyless If your broader need is to generate unique symbols for use in code, gensym is a builtin for this purpose, often used to generate unique symbols in macro code. For example (gensym "some_label_")


Thanks, I’m aware of gensym, but here I’m iterating over a domain which established ordering of arbitrary strings via foo_1, foo_2, etc.


I solved this via regexp, but I would not be so bold as @U054UD60U to say there are no uses for a sensible autoincrementing string operation (the ruby one does things like map a to b and Z to AA.). [shrug]


If you need to generate ids like that, I’d go with a function to parts existing ids, one to increment the parts according to your needs (leading 0s anyone?) and building a string representation for it again.

⬆️ 4

@pithyless sorry I didn't want to sound to harsh, but such function does not make any sense as a core function to a language, imho.


No, there's nothing like that in base Clojure.


I figured as much; I just thought maybe one of the string extensions (`expez/superstring`, funcool/cuerdas, others?) may have covered the use-case. Either way, thanks for the confirmation 🙂


Sure there is:


(map (partial str "some_label_") (range))


I don't know Ruby, but from quick Googling it seems that it's much more complicated than that. E.g., abcd => abce


@pithyless that use case can be handled cleanly by Specter

(def str<->long (parser #(Long/parseLong %) str))

(transform [#"\d+" str<->long] inc "a99bc123")
;; => "a100bc124"

(transform [#"\d+\z" str<->long] inc "a99bc123")
;; => "a99bc124"

metal 16

Decomposing the problem with a composable abstraction lets you handle not just that use case, but related use cases like:

(setval #"\d+" "" "a99bc123")
;; => "abc"

(transform [#"\d+" str<->long] #(* 10 %) "a99bc123")
;; => "a990bc1230"

(transform (subselect #"\d+") reverse "a99bc123")
;; => "a123bc99"


thanks @nathanmarz - I hadn’t even considered Specter for this kind of problem

Graham Seyffert16:07:12

This may be a silly question, but is there a supported way to typehint arguments of a function in defprotcol? Basically, is it possible to do something like - In one namespace:

(defprotocol MyProtocol
  (a-function [this ^SomeJavaType argument]))
In another namespace:
(defrecord MyRecord
  (a-function [this ^SomeJavaType argument] ...))
? Currently I'm having to re-bind argument in the both of a-function w/ the type-hint in order to avoid reflection, which is ugly. Trying to typehint the args results in a compiler exception that the protocol can't be resolved.

Graham Seyffert16:07:23

Or should something like this be done with definterface instead? (I haven't had to use definterface yet)


Does anyone know if 1. Anyone is working on porting the CLJ/Clojure cli to windows 2. If I wanted to view the code for the CLJ where would I look ?


@bobjohnson11 Likely someone on the #tools-deps channel knows the latest status of getting those things working on Windows. Last I recall hearing it mentioned, it wasn't implemented yet.


thanks @gseyffert and @andy.fingerhut I appreciate your help

Alex Miller (Clojure team)17:07:37

@bobjohnson11 I have a port but am still working on the fit and finish of it

Alex Miller (Clojure team)17:07:57

working state (possibly not fully pushed) is in a branch of brew-install


thanks @alexmiller I will take a look at the repo tonight. I appreciate the help.

Alex Miller (Clojure team)18:07:13

fyi, the scripts are not directly usable out of the repo as there are some bits and pieces that get modified during the build process


Thanks for the tip. I'm interested in how the power shell script will work and how the CLJ and Clojure wrapper scripts work will work.


I have a question about Rich's Ant colony code I've found on Github. Why is turn using dosync while move isn't, but "Must be called in a transaction". See


does that gist exist? I get github's 404 page


dosync has dynamic extent


meaning if you (dosync (foo)) the body of foo executes in the transaction


Wow, I guess I've had it opened in my browser for so long that I didn't even realize it's not available anymore. Let me try to find it.


if I recall, the stm's transactions also merge, (dosync (foo)) and then foo is (defn foo [] (dosync ...)) the transaction merge and execute as a single transaction


Still I'm not sure I understand your answer


it is very rare in practice to use the stm ever


I'm just playing with it actually, trying to learn a few things


random thought from the old memory banks: has anyone built/used something like the CL *features* variable in clj?


not necessarily thinking reader macros per set


just “here’s a place to see what features I have enabled in this [dynamic] build”


dosync having dynamic extent means that once dosync is on the call stack, everything after that executes inside the transaction (and so can do things that only work inside a transaction) until dosync is popped off the call stack


So is there any reason to use dosync in turn and not using it in move? Since both will be merged?


Since turn is only ever used from inside the "main" (defn behave [] (dosync ...)), just like move