writing an "idiomatic" wrapper but that can be more taxing than using the lib directly
Yes. I would say this applies to all languages that deal mainly in references instead of values.
Pragmatic techniques: Isolate the scope of those mutable references to one corner of the program and don’t pass them around. If you need to pass them around: convert them to Clojure data first.
That’s right, after you serialized it, it can’t hurt you anymore!
ty for the tip
Hi Everyone,
i'm really newbie in clojure (i don't have any code exp, except vba & ms. Excel). I'd like to asked several questions
1. lein new app asdf
, i do this in my cmd, but how can i do this in atom? is it possible? if not, that's okay.
2. then i create suspects.csv and want to slurp it. but it gives an error. below is the screenshot. I've put this csv in resources, or in src/asdf along with the core.clj, but give same error.
PS : I placed my lein.bat & atom repl run in this directory
C:\Users\Adrian Imanuel\.atom\packages\proto-repl\proto-no-proj\src
thanks a lot for the help
If you do this in your program, or a REPL, it will tell you what the JVM thinks is the current directory (or what it thought was the current directory when your REPL started at least -- it can be changed later): (println (System/getProperty "user.dir"))
That is the directory it is probably trying to read the file from, unless you direct it differently somehow.
If you want to get it from your resources
directory, you can do (require '[<http://clojure.java.io|clojure.java.io> :as io])
in the REPL, or add a similar thing into your ns
form of your program's namespace that looks like (:require [<http://clojure.java.io|clojure.java.io> :as io])
, then do (slurp (io/resource "suspects.csv"))
Someone else might know the answer to your question about creating new Leiningen projects from within Atom -- I do not. You could also ask in the #atom-editor channel, if no one here knows.
@adrianimanuel With Atom, are you using ProtoREPL or Chlorine?
@seancorfield i'm using ProtoREPL
Hmm, ProtoREPL is unmaintained. I'm a bit surprised it still works with Atom.
@seancorfield whoops, i really didn't know that, should i change IDE? is there any recommendations?
It hasn't been updated in nearly three years now. I was an Atom/ProtoREPL user and I switched to Atom/Chlorine, but that expects you to start the REPL separately, via a terminal (or cmd.exe window in your case).
https://atom.io/packages/chlorine is solid. There's a #chlorine channel.
I will caution that Windows is very much a second-class citizen in the Clojure world. If you're on Windows 10 and willing to use WSL2 you'll fare much better.
My primary dev env is macOS but my secondary env is Windows with WSL2 (and Ubuntu). I've recently switched from Atom (after several years) to VS Code.
That gives you the option of Calva which is very feature-rich and well-maintained or Clover -- which is essentially Chlorine (for Atom, but ported to VS Code). So that's allowed me to port my exact workflow from Atom to VS Code.
@andy.fingerhut it works... (println (System/getProperty "user.dir"))
after locate the REPL
I'll try the (require '[<http://clojure.java.io|clojure.java.io> :as io])
now.
why is windows10 isn't suitable env for clojure?
All of the tools and libraries are designed for macOS/Linux because that's what most Clojure developers use.
The Clojure CLI (the official offering from Cognitect, rather than Leiningen) has an alpha approach to Windows: https://github.com/clojure/tools.deps.alpha/wiki/clj-on-Windows via Powershell, but it's just so much easier to give up on Windows and use WSL2/Ubuntu (which is what Microsoft increasingly expect developers to do).
And VS Code has a Remote-WSL2 mode that lets you run "everything" on Ubuntu while VS Code runs on Windows so it's super-slick.
I use VS Code on both Windows and macOS (and it auto-synchronizes the entire setup between the two systems), and on both systems I run everything on the *nix side (Ubuntu on WSL2 on Windows 10 and macOS Terminal).
I'll try to digest this... since i really had no idea, I'm still on progress learning https://www.braveclojure.com/core-functions-in-depth/ 😅, once i got more deeper knowledge then I'll try to move on to macOS. Thanks a lot for the suggestion
cool. The http://clojure.java.io/resource function is useful if you want to get a file handle to a file in your resources
directory, but it isn't really needed if you prefer to put the file in the current directory (the one that "user.dir" property shows)
thanks a lot for the enlightment! 😆
Happy to answer any Qs since I work on both Windows 10 (WSL2) and macOS 🙂
Hello, I'm looking for a way to seperate strings without a specific term and store them. The separation works, but it seems nothing is stored...
(let [mapsx (remove nil? (map #(if-not (clojure.string/includes? % "jpg") ( println % ) ) prae))]
(println mapsx mapsx))
result:
(
whats
the
problem
here
)()
Any suggestions?
Solved it by my own 😊
(let [mapsx (remove nil? (map #(if-not (clojure.string/includes? % "jpg") (conj % ) ) prae))]
(println mapsx mapsx))
Nice, you solved it, but you might want to look into filter
and group-by
, as it might make sense for this use case.
this would get you all of the ones that dont include jpg
(filter #(not (clojure.string/includes? % "jpg")) prae)
while group-by would give you a map with those who do and don’t include jpg.See remove
I mean remove was used in the original, so I assumed knowledge of it was present. Although, It is good to point out that remove is very much useable as well (since it’s basically the same as filter with the predicate reversed).
hi, what's the terminology for this dot notation and is it conventional or intrinsic? ex:
(use (. express (logger))
^
I believe it’s called the Dot special form, for more reading: https://clojure.org/reference/java_interop#_the_dot_special_form
Hey! I remember seeing a list of OSS clojure/clojurescript repos with issues good for beginners. Could somebody please point me to it?
Ah, found it. http://braveclojure.com linked to it, nvm 🙂
When I use clojure.string/replace, is it possible to get the times something was found? Maybe this example helps:
(def teststring "AAABBC")
(str/replace testcode #"\D+" "$1")
I would like to know how many times A was found in a row and use it. Is this possible in regex? I have to code with lots of take-while, count and drop. But this would be a lot more compact@christiaaan You can pass a function as the last arg:
$ bb -e '(str/replace "foo" #"(o)+" (fn [& args] (prn args) "x"))'
(["oo" "o"])
"fx"
$ bb -e '(str/replace "foo" #"o" (fn [match] (prn match) match))'
"o"
"o"
"foo"
What? That looks like some bash thing. Ah, it's the babashka dude!
for "oo" i would like to have something like "2o" so I know it has found 2 o
but how do I get the 2?
you mean, you would like to get the amount of replacements?
I think you might want to use re-seq
which gives you all the matches
$ bb -e '(re-seq #"\D" "AAABBC")'
("A" "A" "A" "B" "B" "C")
Also see keep
instead of mapping then removing nils.
Then I'd still have to count them manually. I was hoping that the regex would somehow offer the amount of replacements, like I can access the groups
I would say the most typical thing in Clojure is to simply (count …) the sequence that (re-seq …) returns
@christiaaan A little hacky, but you could have a side-effect in the replacement function that increments a counter
This way you would have replacement + counting in one go
With spec, can I have the same namespace qualified keyword speced differently in two different contexts? For example in one map I’d want :foo/bar
to be string?
and in another I’d want :foo/bar
to be int?
. Ideally they’d be different keywords if they were different types, but curious if something like this is possible.
No, spec encourages you to register a single, well namespaced spec that applies globally
When I understand correctly, this doesn’t just apply to spec, but is a more general issue about namespaces and namespaced keywords and what they mean right?
Not necessarily
Names need sufficient context
“Sufficient” is highly context dependent
Shouldn’t we provide context with metadata generally speaking? I don’t think this is possible with keywords as they are interned. But conceptually this would seem useful.
there are many kinds of context
context is contextual 😄
But yeah, thinking about this it makes more sense to put metadata on a symbol (that points to something) rather than a keyword, which is just a value.
context can just be where/how it's used
it can be implicit
hi, anyone using spacemacs? been stuck in here forever, why it didn't download? can anyone help?
@jordan.andrew.garriso just installed DOOM, and tried to run repl for clojure, SPC-o-r there's 2 options : Clojure (default), when run said - symbol's function definition is void: cider-current-repl Clojure (cljs)
enable clojure module, repl is SPC m '
also have a clj file opened so you're in clojure mode
the lein executable isn't in you exec-path
where should i put lein.bat?
in .emacs.d/bin or ~/.emacs.d/bin?
gotcha, in ~/.emacs.d/bin
@claudius.nicolae i've tried SPC m '
it showed like this, i didn't see any REPL windows... thanks a lot for the help
You have to be in a project (folder with project.clj or deps.edn).
Also I see some fonts be missing, check doom doctor
ah allrite, will do
thanks a lot for the guidance
i've tried to create projects, run the core.clj, but still the repl doesn't show up.
okay, found the solutions https://stackoverflow.com/questions/65566706/error-in-process-sentinel-could-not-start-nrepl-server-java-lang-numberformate 1. start git cmd 2. type >> lein repl >> it'll start repl in git cmd 3. goto doom emacs type [SPC m c] >> cider-connect-clj 4. choose local host 5. type port local host as shown in step 2
Use this in the meantime: https://github.com/thanhvg/spacemacs/tree/feature/evil-collection
This ate 1 day of my life with %^#&*?!?
alrite, i'll try
thanksss a lotttt for the information
maybe i'll use emacs instead spacemacs... idk what to do (totally clueless), i'll learn it on the go
If you are a previous vim user/like vim’s modal editing then Doom Emacs is another distribution of emacs which might meet what you need. It predownloads/compiles (if you want) packages for you so you get a quick startup (< 1s). It has a prebuilt clojure configuration as well which has worked really well for me out of the box. Repo: https://github.com/hlissner/doom-emacs YouTube series on use/setup: https://www.youtube.com/playlist?list=PLhXZp00uXBk4np17N39WvB80zgxlZfVwj
Hey guys, has anyone successfully used miner.ftp library with ftps? I can't find out where to use the function encrypt-channel on the client.... if local data transfer is not forced to SSL, just using the ftps protocol works, but when data should be encrypted it seems compulsory to use this encrypt-channel function.
Is no one interacting using ftp or is my lack of profile picture detrimental to getting any feedback 🙂 ?
-_-'....
alrite, i'll look into it as well.. I never use any of this before hahhaa.. total newbie... my previous experience is Ms. Excel & VBA.... I'll learn slowly
Starting from scratch in non-VBA programing and Clojure and Emacs is a lot to chew in a single bite!
@adrianimanuel https://calva.io/ may be more suitable for you, it's quite beginner friendly (occasional bugs aside).
If you are a (neo)vim user, I can't rate highly enough the #conjure plugin for Vim that really is amazing for developing Clojure with Vim.