Fork me on GitHub
#clojure
<
2019-03-31
>
kenj01:03:14

A pid file should be reliable

andy.fingerhut02:03:29

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.

jumar08:03:18

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

aryyya19:03:28

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

potetm19:03:33

String#format takes a String and and array of Object

potetm19:03:57

The Classname... syntax in Java means “varargs”, but it actually unpacks to an array in the compiler. So Object...means “Object array”

potetm19:03:57

So if you want to use String#format, you must do something like: (String/format "Hello, %s!" (object-array ["Larry"]))

potetm19:03:42

OR (and this is the preferred route), use clojure.core/format (https://clojuredocs.org/clojure.core/format)

potetm19:03:20

which does the exact same for you

aryyya19:03:34

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

Average-user21:03:41

What are the best options for parsing BNFs?

dpsutton21:03:26

there's something right up your alley: https://github.com/Engelberg/instaparse

👍 4
aryyya21:03:36

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

dpsutton21:03:58

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

dpsutton21:03:53

contrast (:a nil) versus (nil :a) in your repl.

aengelberg22:03:26

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