This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-03-31
Channels
- # announcements (16)
- # beginners (52)
- # calva (44)
- # cider (82)
- # clojure (21)
- # clojure-greece (1)
- # clojure-losangeles (1)
- # clojure-spec (8)
- # clojure-uk (3)
- # clojurescript (55)
- # community-development (26)
- # cursive (18)
- # datomic (7)
- # editors (6)
- # events (1)
- # fulcro (19)
- # kaocha (1)
- # klipse (1)
- # off-topic (13)
- # re-frame (1)
- # ring-swagger (2)
- # spacemacs (2)
- # vim (15)
Many Linux/Unix variants have mktemp
commands with guarantees of safety if many processes are trying to do so at once. I wouldn't be surprised if there are other related system calls and/or even utility commands that apply for creating and removing lock files.
This may have some pointers to such commands that are on at least some Linux systems: https://stackoverflow.com/questions/185451/quick-and-dirty-way-to-ensure-only-one-instance-of-a-shell-script-is-running-at
There's FileLock class which you can use on top of "lock file" ("exclusive lock" I guess): https://docs.oracle.com/javase/7/docs/api/java/nio/channels/FileLock.html
Why doesn’t this Java interop work?
(String/format "Hello, %s!" "Larry")
I get this error message:
Execution error (ClassCastException) at bg-clj.core/eval2010 (form-init14869047494885852816.clj:1).
class java.lang.String cannot be cast to class [Ljava.lang.Object; (java.lang.String and [Ljava.lang.Object; are in module java.base of loader 'bootstrap')
The Classname...
syntax in Java means “varargs”, but it actually unpacks to an array in the compiler. So Object...
means “Object array”
So if you want to use String#format
, you must do something like: (String/format "Hello, %s!" (object-array ["Larry"]))
OR (and this is the preferred route), use clojure.core/format
(https://clojuredocs.org/clojure.core/format)
@potetm Ah ok, thanks for the explanation! I’m trying to do a bit of interop right now just learn how to do it properly. I’d use the Clojure format function otherwise.
What are the best options for parsing BNFs?
(:name person)
and (person :name)
where person
is a map seem to do the same thing. Is one preferable over the other stylistically? They both seem a little bit magic over using (get person :name)
.
not magic they just implement IFn. Also extremely common. There is a difference: a literal won't be null, the person
binding might be. A null in the first position will throw whereas a lookup in null will return null
generally I don't see maps used as functions unless it's being leveraged in a higher-order function, like (map person list-of-keys-i-want-to-lookup)
.