Fork me on GitHub
#clojure
<
2015-09-09
>
tel00:09:54

Is it the case generally that one has to mangle hyphens in import statements to underscores

tel00:09:59

or am I doing something wrong?

potetm00:09:09

@tel: I believe that’s correct. import clauses are for java interop, so you play by java rules.

potetm00:09:26

Unfortunate that records fall into that category though.

tel00:09:40

yep… that’s exactly where I was getting bitten

tel00:09:03

that’s pretty outrageous...

potetm00:09:40

Yeah I was less than pleased when I saw that. Makes some amount of sense (they get compiled to classes I believe), but still a little onerous for users.

tel00:09:19

Yeah, it’s understandable

tel00:09:19

just, a pretty sharp edge forcing one to come to terms with Clojure being a little less of a language and a little more of syntax sugar for Java 😕

ghadi01:09:14

tel: don't import records, require the ns that they're in, no problems

ghadi01:09:38

no need to mangle then

tel01:09:39

then refer to them with a fully qualified name?

ghadi01:09:06

si. whatever.ns/->MyRecord

ghadi01:09:50

->RecordName is the positional constructor, there's also a map-based constructor you get for free map->MyRecord that takes... drum roll, a map

tel01:09:53

ah, but I need the actual class, not just the constructors

tel01:09:26

maybe that’s what I should leverage, getting Schema to not require that

ghadi01:09:34

you'll only need the class for interop where java has to call in to you. if it's just protocol extension, no need for class

ghadi01:09:47

Oh, Schema. Not sure then, sorry.

tel01:09:00

protocol extension can be done without the class imported?

ghadi01:09:16

just namespace-qualified

tel01:09:17

(extend-protocol Foo whatever.ns.MyType …)?

tel01:09:28

interesting

ghadi01:09:30

no... like this:

ghadi01:09:30

(ns whatever-source 
  (:require [the-other-ns :as foo]))
then later...
(extend-protocol MyProtocol 
  foo/MyRecordOverThere ....)

ghadi01:09:02

the specified namespace has to be loaded prior to extension

ghadi01:09:08

hence the require

tel01:09:19

so it’s still considered a “var” for purposes of protocol extension?

tel01:09:36

or something along those lines, hm

tel01:09:50

I’m trying to play this game on hard mode, tbh

tel01:09:56

schema + protocols + cljc

ghadi01:09:42

ha, for sure

tel01:09:54

which currently looks a bit like this beauty

ghadi02:09:41

yeah don't use import on types if they were born clojure-side

ghadi02:09:54

just require is enough

potetm02:09:46

@ghadi: So you’re saying the following should work? In tester/core.clj:

(ns tester.core)

(defrecord MyRecord [])
In tester/other_ns.clj:
(ns tester.other-ns
  (:require [tester.core :as c]))

(defprotocol MyProto
  (-my-fn [this]))

(extend-protocol MyProto
  c/MyRecord
  (-my-fn [this]
    "HAHA"))

potetm03:09:30

For the record, that doesn’t work for me. My understanding was that you had to have something like:

(ns tester.other-ns
  (:require [tester.core :as c])
  (:import [tester.core MyRecord]))

potetm03:09:18

So if you’ve got something else figured out, I’d love to use it. That’s such a pain.

potetm03:09:26

“Doesn’t work” meaning I get the following:

CompilerException java.lang.RuntimeException: No such var: c/MyRecord, compiling:(/path/to/tester/other_ns.clj:7:1) 

bostonaholic03:09:07

and now @ghadi has got me wondering...

ghadi03:09:52

yeah that worked in my head, not on the compiler. Sorry for the confusion

ghadi03:09:36

the original question was attempting to avoid dealing with unfortunate name-munging

potetm04:09:56

Yeah, unfortunately that comes in when you're forced to use import.

Pablo Fernandez12:09:20

I wish Clojure was providing a private def- the same way it provides defn- (I know it’s easy to define, I just wish it was part of Clojure).

nikp12:09:07

You can use (def ^:private a-var a-value)

nikp12:09:35

Unless you meant that you wish the shortcut macro for that was there

xificurC12:09:19

the macro could indeed be part of the core

darwin13:09:51

I wish there was a way to specify implicit namespace(s), this way I could “extend” core with my helper library and it would feel like using core

darwin13:09:10

would love that for my development helpers: logging and similar

juhoteperi13:09:33

@darwin: Vinyasa inject could do that: https://github.com/zcaudate/vinyasa and another option is to use Potemkin import-vars to build one "sweet" ns with all the helpers so instead of e.g. five util namespaces you only need to require one

oliy13:09:29

can't you (intern 'clojure.core 'def- ...)

profil14:09:44

@jellea: About geom, is there any helper function to get the range and pos? They are kind of weird to get right myself

jellea14:09:51

profil: unfortunately never used geom myself!

a.agapov16:09:10

uh... is Slack really better than IRC....?

a.agapov16:09:15

seems messy

jaen16:09:31

It certainly works awesome for in-team communication, not sure how it works out on this scale since I'm here only for a few days, but some seem to prefer gitter.

emil0r17:09:18

Some things are better than IRC. Automatic history even when offline is one thing I certainly appreciate

jaen17:09:40

Unless it scrolls past 10k ; /

emil0r17:09:06

Yeah... that's the bad part simple_smile

gjnoonan17:09:06

@emil0r @jaen The community has logs set up to get past the 10k message limit, although yeah I would love to be able to not have to resort to such things. Unfortunately slack are not very receptive to having an option for F/OSS communities within their pricing structure. To “level up” at our current capacity it would cost me in excess of $60,000-$130,000 (depending on the plan) per year, money I don’t have 😕

gjnoonan17:09:08

I have been thinking about, and trailing other solutions, that will give us more functionality, without taking away the experience. However there is no concrete answer yet.

emil0r17:09:57

@gjnoonan: no worries simple_smile. Appreciated that it's up and running

emil0r17:09:15

was just a general observation

emil0r17:09:23

no critique intended

venantius18:09:38

yeah just in general I’m extremely happy that this slack network exists

venantius18:09:51

so firm ++ to @gjnoonan et al

akiva19:09:03

Seconded.

devn20:09:46

@gjnoonan: one hack could be to have a link pinned to each channel

devn20:09:09

which is a link to the log for the channel

clojuregeek20:09:34

I'm looking to generate some random data for an API proof of concept, sort of like test check generators.. I found http://clojure.github.io/data.generators/index.html but it wonder if there is something better or easier ?

nullptr20:09:24

prismatic schema recently added some data generation capabilities, worth a look

gtrak20:09:56

I'm frustrated with clojure.test. I have a bunch of tests that all follow the same structure, and I'm forced to use a monolithic macro to get meaningful line numbers. What's the easiest thing out there that will let me hook into reporting, and still give like junit xml output with clojure-maven-plugin? When I'm considering writing a dsl to test my dsl, something feels off simple_smile.

meow21:09:19

got a question about a stateful transducer

meow21:09:50

as I process items I'm looking for ones that are a list and if so I break the list into 2 pieces, the base data and some parameters, and then I'm putting those parameters into a map indexed by the position of the item in the new coll being produced.

meow21:09:29

then I need some way to get this map out of this stateful transducer so I simply pass it to the reducing function during the finalizing step

meow21:09:41

I'm wondering if that is the most sensible approach

meow21:09:52

here is the code:

(defn split-module-params-xf
  "Returns a stateful transducer that accumulates a map of module parameters,
   where the key is the index position of the module in the resulting word."
  []
  (fn [rf]
    (let [data (volatile! {})
          index (volatile! 0)]
      (fn
        ([] (rf))
        ([result] (rf result [@data]))
        ([result input]
         (let [v (vec (for [[n, module] (map-indexed vector input)]
                        (if (list? module)
                          (let [[module param] module]
                            (vswap! data assoc (+ @index n) param)
                            module)
                          module)))]
           (vswap! index + (count v))
           (rf result v)))))))

meow21:09:49

this is part of my L-system (parallel rewriting system) so the code reflects the names from that domain

meow21:09:10

a word is just any coll and a module is any item in that coll and using a list to signify optional parametric data is just a convention I settled upon.

meow21:09:52

since previous steps in the transducing process can return more items I need to track the index position that it will be in the new word

clojuregeek21:09:05

@nullptr: thanks generate from schema is perfect simple_smile

profil22:09:48

I am running some long running number crunching function, is it possible to change functions used by the function I am running right now without stopping execution?