This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-09
Channels
- # beginners (20)
- # boot (4)
- # cider (2)
- # cljs-dev (25)
- # clojure (45)
- # clojure-dev (1)
- # clojure-greece (5)
- # clojure-italy (20)
- # clojure-nl (12)
- # clojure-russia (11)
- # clojure-uk (256)
- # clojurescript (176)
- # data-science (33)
- # datomic (47)
- # docs (1)
- # duct (13)
- # fulcro (54)
- # graphql (24)
- # hoplon (3)
- # jobs (1)
- # leiningen (32)
- # luminus (3)
- # midje (1)
- # mount (2)
- # off-topic (3)
- # onyx (5)
- # overtone (1)
- # parinfer (12)
- # pedestal (4)
- # re-frame (60)
- # reagent (11)
- # reitit (3)
- # ring-swagger (21)
- # rum (1)
- # shadow-cljs (16)
- # spacemacs (23)
- # tools-deps (19)
- # vim (79)
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 0
s anyone?) and building a string representation for it again.
@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.
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 🙂
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"
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
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
MyProtocol
(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.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 ?
Clojure source is hosted on GitHub - https://github.com/clojure/clojure
Leiningen works on windows - https://leiningen.org
@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
@bobjohnson11 I have a port but am still working on the fit and finish of it
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.
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 https://gist.github.com/spacemanaki/1093917#file-ants-clj-L119
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.
Here's another link https://gist.github.com/michiakig/1093917
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
This answer says the same it seems https://stackoverflow.com/a/2842270/410712
Still I'm not sure I understand your answer
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?
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