This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-07-29
Channels
- # aleph (3)
- # announcements (16)
- # beginners (85)
- # calva (2)
- # cider (13)
- # clj-kondo (84)
- # cljdoc (3)
- # clojure (109)
- # clojure-belgium (1)
- # clojure-china (39)
- # clojure-europe (4)
- # clojure-france (1)
- # clojure-italy (70)
- # clojure-nl (8)
- # clojure-spec (8)
- # clojure-uk (53)
- # clojuredesign-podcast (14)
- # clojurescript (43)
- # cursive (25)
- # data-science (1)
- # datomic (4)
- # emacs (10)
- # figwheel (4)
- # garden (4)
- # graphql (5)
- # jackdaw (10)
- # jobs (5)
- # jobs-discuss (5)
- # lambdaisland (2)
- # leiningen (3)
- # luminus (7)
- # off-topic (32)
- # pathom (11)
- # pedestal (2)
- # planck (15)
- # re-frame (12)
- # reagent (4)
- # remote-jobs (2)
- # shadow-cljs (51)
- # sql (29)
- # tools-deps (47)
Is there a term people use to describe the different "maps of expected shape" in their code? Ie, something which would be described by s/keys
in spec. Clearly "type" isn't a great word to use, though this is how I think of them in my head. "keyspec"? hijack the word "struct"? As in "Here are the various <type-things> my app uses, and the possible keys in each of them: ..."
Sorry, I misunderstood your question - so yes, entities would work better here (and they have to comply with a schema ;-))
no you were right I meant the way to describe the classification of the instance not the instance itself
schema might be good. Just trying to work out if i have precisely a spec.alpha2 schema here. And also if myapp.schema.person
and myapp.schema.company
sounds right
The word "type" is the one I have encountered the most so it would make sense to me. But I find more helpful to think in terms of "set of keys" that entities can use or not, rather than type. So entities are not limited to one type.
because also i have things in my app that would be described by a spec.alpha2 schema but are not one of these things
I think "entity" has more to do with the idea of identity than schema or type: "a thing with distinct and independent existence."
Yeah that was my initial thought. "I am an entity. I am a person. Person is my <type/class/category>"
Yes, <type/class/category> are the most common terms for this idea so any of those would work. But you're not just a person, you can have many roles, so that's why it is more useful to think in terms of roles (or sets of keys) rather than types.
I think a schema or spec that describes an entity is quite different than a type or class that describes some implementation detail, i think is where I get hung up
"type" is used a lot in data modeling to represent exactly this "class" is used in RDF schema and ontologies (OWL)
Hi, is there a non-blocking io (and specifically reading from file) in Clojure?
i see that slurp
is definitely blocking
Java has a variety of blocking and nonblocking io apis, which are all usable from Clojure
i would expect that Clojure will have a fn that reads from a file in a non-blocking way and return a channel. I can write one my self (in about 5 lines of code) but isnt there one?
Clojure in general does not provide wrappers around things that can be used directly via java interop in the jdk (so, no there isn't one)
so why slurp is part of clojure ?
slurp is a helper function that does a frequently used combination of actions
I presume java.nio.channels.Channel
you can get a channel with something like (.getChannel (java.io.RandomAccessFile. "afile.txt" "r"))
this is fine, but I would like a more idiomatic Clojure solution for this - i.e., something that returns a core.async Channel. why not have something like async-slurp in core.async ? sounds like a common use case for io intensive apps.
interop is idiomatic
Hi... I think I'm compiling clojure with :direct-linking true
in *compiler-options*
; but looking at my byte code (disassembled in IntelliJ), I still seem to have a lot of Var
s and indirection. Would that be expected?
Depends where you are seeing them
I would expect the following would be obviously âdirectâ for the compiler:
(ns net.timb.timmeh.tim
(:gen-class
:methods [[woo [] int]]
))
(defn- -woo [] 42)
Oh, this is just how gen-class always works. It always uses vars as a point of indirection. Since these arenât static methods on the generated class, thereâs not really any choice
Direct linking really affects normal function invocation call sites
Itâs the woo
, Iâm really concerned about. Is there any way to get the declaration here closer to public int woo(){return (Integer)42;}
Is there some reason youâre doing gen-class?
Iâm experimenting with code generation macros⌠a bunch of classes generated of the back of a yaml file.
Currently Iâm doing the code generation with scripts to produce .java source (mostly using jq
).
Clojureâll produce byte code⌠so I was hoping to do: ({k: v} map in yaml) -> {:k v} map in clojure -> macro with classes (named by :k, with v implementation) and gen-class -> .class byte code
kinda, so that woo
here is generated from something along the lines of:
---
woo: 42
creating byte code for the public static int woo() {return 42}
above(although thereâll be more than one method per class, and itâs not just returning an int!)
a more direct path would be to actually use asm to generate bytecode (like Clojure does)
Iâm going to need quite a bit of language support in the macros⌠itâll involve pattern matching and all sorts of other stuff I need a proper language for.
oh, the v's are code, not data
int the yaml, theyâre data (as literal values v)⌠once itâs in the generated class theyâll be some transformed value f(v) â but being spliced into a macro, theyâre actually code. IYSWIM
I don't think you're going to get what you want out of gen-class, probably better off with making normal vars and running compile on the namespace
The woo
thing is an experiment⌠Iâm keen not to be calling something that in principle is dereferenced through a Var
â even though the promise of JIT magic might make that not a thing.
(Iâm actually pretty newâ to Clojure, but not to this kind of cross-language meta-programming)
direct linking through compilation will remove the var indirection (but not with gen-class)
thanks⌠I think I have a direction now. Probably means dumping my generated code into a new source file to be compile
d â Iâm guessing thereâs no
(compile '(namespace-contents...))
no, compile rides on top of load, which is coming from a source file
Iâll see what mileage I get from this. Iâm happy with this as a solution if it works; the intermediate source is a small price. Again
If I understand correctly what that is, Criterium is probably a Clojure equivalent: https://github.com/hugoduncan/criterium It has code that explicitly tries to first run some code enough times that the Java JIT compiler will likely kick in and create a native machine code version of your code before starting its measuerements.
question: I have a function that performs "transducing" over single element, how should I name it? code:
(defn ??? [xf f v]
(let [rf (xf (completing #(f %2)))]
(rf (rf nil v))))
usage:
(??? (map-indexed vector) str :a)
=> [0 :a]
(??? (map-indexed vector) println :a)
;; prints [0 :a]
=> nil
(??? (comp (filter int?) (map-indexed vector)) println :a)
;; does not print anything because :a is not an int
=> nil
meta question: is this question a good fit for https://ask.clojure.org/ ?
it's a question, and it's about Clojure, so yes!
That sort of feels like it violates expectations around reduction/transduction to me... It's almost the same as transduce
with the last arg wrapped in [
]
...
yeah, I now realized that it's not really a good ???duction, because it completely disregards accumulator
...in a way that (transduce xf f [v])
is not? Presumably in the (f)
case to create the accumulator?
f
will receive 2 args: accumulator and item, and in my case I don't care about accumulator, just performing side effects on each item
is this the same as run!
?
so whatâs the better way of doing something like this: (comp not zero? (fnil identity 0) util/parse-int)
? parse-int return nil if canât parse
#({nil 0 false 0} % %)
- returns arg if not nil or false, otherwise 0
edn file trying to add sonatype and some dependencies that should be on there
when i use clj to run my project with these dependencies, it complains that it can't find them on Maven Central. how can i force a specific dependencey to be fetched from sonatype (which i am adding in that file) ?
I'm not sure what sonatype is but you can add external repos under the mvn/repos
key. For example:
:mvn/repos {"Sonatype" {:url "
are you sure it's org.bitcoin-s and not org.bitcoins
@ysangkok based on browsing that repo, it looks like you are specifying the version string incorrectly - eg https://oss.sonatype.org/content/repositories/snapshots/org/bitcoin-s/bitcoin-s-secp256k1jni/0.1.0+45-91633375-SNAPSHOT/bitcoin-s-secp256k1jni-0.1.0+45-91633375-SNAPSHOT.pom
that pom suggests the version string 0.1.0+45-91633375-SNAPSHOT
which matches the date you specified, but doesn't include it in the version
aaah thanks! @noisesmith... i couldn't figure out how to browse sonatype, how did you do that? just manually adapt an URL from a different package? and remove elements from the end?
I started at https://oss.sonatype.org/content/repositories/snapshots/ and browsed from there
is there some reason you're using a snapshot?
there is a released 0.1.0
the release should be newer than the snapshot
oh, i didn't realize. i wanted to use the snapshot because this is a one-off anyway and i don't know how stable that project is, and i would wanna report bugs based on master
I'd just use {:mvn/version "0.1.0"}
then you don't need the special repo either, central is included automatically
@alexmiller how can the release be newer than the snapshot? https://github.com/bitcoin-s/bitcoin-s/tree/v0.1.0 says the last commit is from may but the full version string of the snapshot says 201906, which should be june
yeah, I was just looking at that. that's very weird.
my guess would be a ci process continuing to build something off the snapshot version
like the snapshot base version didn't get updated after the release build
what I'm saying is, someone on the internet is wrong
aaaah yeah ok, i didn't even consider that a problem. i always thought if a version contains SNAPSHOT, you basically cannot trust its version number?
but even if you were using a snapshot, you shouldn't pull in a specific timestamp version like that. The snapshot version is a "virtual" release and maven will map to the latest timestamp. So, you'd just want to use {:mvn/version "0.1.0-SNAPSHOT"}