joinr

u/joinr


r/Kotlin•

I am translating some code from the lets-plot Kotlin API from here. From the docs, I have a grasp of the class constructor invocation, but I have not found anything about the implicit passing of a closure after the constructor is called. The authors use this idiom a lot for plot configuration:

geomDensity(color = "dark-green",
            fill = "green",
            alpha = .3,
            size = 2.0) { x = "x" }

The example uses it for defining geom instances (of which there is a final argument that is a function of a mapping type to unity, what from inspecting so

18

r/Clojure•

Somewhere over the years, I picked up the idiom of using the cached hasheq value as a shortcut in the equiv implementation for user defined collections. Here's an example from some custom type (in retrospect, the nil return should probably be false):

(equiv [this o]
       (cond (identical? this o) true
             (instance? clojure.lang.IHashEq o) (== (hash this) (hash o))
             (or (instance? clojure.lang.Sequential o)
                 (instance? java.util.List o))  (clojure.lang.Util/equiv (seq this) (seq o))
             :else nil)) 

This excerpt leverages the IHashEq contract to assert that if both can be structurally hashed, then that comparison

29

r/Clojure•

https://www.gnu.org/software/guile/manual/html_node/VLists.html

https://github.com/skangas/guile/blob/master/module/ice-9/vlist.scm

https://hg.sr.ht/~bjoli/guile-fector

discussion from lisp reddit

They're another Bagwell structure for persistent array like things. The Guile folks have what looks like a consistent port of persistent vectors, and they (u/bjoli) seem to observe about a 2x estimated random access difference between the pvector (fector) and the vlist implementation. I found that curious, since it could indicate another persistent data structure with some tradeoffs that could b

115

r/Clojure•

I recently ran into an issue when trying to extend print-method toward custom types. After chasing my tail, looking at a variety of reasons for this inscrutable behavior (on a toy example):

user> (defrecord blah [x] 
          Object (toString [this] (str "blah-containing: " x)))
user.blah
user> (->blah 2)
{:x 2}
user> (defmethod print-method blah 
          [^blah b ^java.io.Writer w] 
          (.write w (.toString b)))
#multifn[print-method 0x416e4445]
user> (->blah 2)
{:x 2} ;;Wat?

It finally emerged that Cider (unbeknownst to me, since I fail to read the manual) is helpfully using the pretty printed representation instea

120

r/Clojure•

I have an entity component store implementation, which provides access to component data per AEV (attribute [component], Entity [entity id], and Value [component data for the entity]) indexes by way of a nested map of {attribute {entity val}}. There's more to it for performance sake and other goodies, but that's the relevant storage model (plain clojure maps in this case).

I've got a little SQL-like query language that works with this fine for many things, but it's obvious for a current application that having some of the expressiveness from datalog and/or core.logic might be nice; that is define queries as rules instead of relational algebra (or compositions of clojure functions that filt

134

r/Clojure•

I have an embarrassingly parallel workload (a bunch of replications of a simulation). I'm currently working on scaling the work out to additional cores and getting surprising speedups, which I've replicated below with a small example.

The naive thought, is that if I can assign one replication (should be an identical workload and runtime) to one core, I should be able to farm out n runs to n cores and get close to a direct speedup (n runs in 1 replication's runtime). That is, if I have N runs, and N cores, and N isolated threads (one for each core), the total batch of runs should take as much time as a single run. In practice, I realize there's still a little coordination overhead and th

739

r/babeljs•

Hello,

I am brand new to using babel, and not too far into JS development. I've got enough background to follow tutorials and docs, use npm, hack on JS scripts, etc. I've recently started a foray into trying to leverage the Vega plotting library from the Nashorn engine under Java 8 (due to legacy requirements and restrictions). Nashorn's support for modern javascript is lagging, so I reached for babel to try to build some source that Nashorn could parse and evaluate. The repository here contains my current (failing) attempt.

Draft attempt to transpile vega 5 to ES2015 (or whatever will work)

Problem - Server Side Rendering of Vega Plots on

10

r/Nightcode•

Should/does nightcode 2.7.0 to pick up the ~/.lein/profiles.clj ? I'm under the impression it does (since that's what the bundled lein should be doing).

10

r/Clojure•

Case: well-meaning library author decides to go the public/private route (rather than separating said private functions into namespaces while retaining opt-in visibility for future consumers), and consumer (me) needs to get the value of a declared private var (not function).

The typical work-around for functions is to use sharp-quote, #'the-private-function which is fine for functions but not so hot for vars with non-function values.

enter var-get:

(var-get #'the-private-var)
:some-hidden-value

I haven't run into this too often in practice (e.g. actually needing to scrape some data that's been privatized), but there's always a fi

53

r/Clojure•

Recent discussions have kicked up some old sediment regarding the bifurcan library.

Cursory evaluation, combined with a glance at related benchmarks seem to indicate that the implementation for maps, vectors, and sets seem to be dominant across the performance frontier (in "general" and for a variable definition of dominant - e.g. for small collections map construction is significantly better on paper, but may be meaningless in practice; there are also cases where the clojure.core structures win out albeit mildly).

I'm uncertain about the unmeasured trade-offs (such as space, or non-

3316