Fork me on GitHub
#clojure
<
2016-10-26
>
Alex Miller (Clojure team)00:10:06

@grant right (but maybe you should really be splitting things out more)

Alex Miller (Clojure team)00:10:18

@sophiago don’t understand the question

sophiago00:10:37

i'm not actually entirely sure i was right in my assumption actually

sophiago00:10:50

i have a library as a dependency with gen-class in the ns and assumed it wasn't being required with everything else since i had a sort of similar issue with classes defined with defrecord that had to be explained to me

bfabry00:10:54

fwiw @sophiago from your gist yesterday I would ditch the gen-class and just make Number another defrecord

sophiago00:10:27

@bfabry i can't do that. it extends a java abstract class

bfabry00:10:58

ahh.. well I would at least move it to its own ns. in my experience gen-class is pretty hard to get doing what you want (there's a lot to get your head around)

sophiago00:10:13

at this point i'm not sure it's responsible for my bug tho. i pasted over the gen-class code as well as the constructor into the ns of the main project and tested it in the repl and am still getting the bug related to its behavior in protocols when i run the code

bfabry00:10:01

for instance one thing I see you're doing is referring to the gen-class'd class directly, ie Number, in that ns. which last I checked you can't do, you need to :import it

sophiago00:10:45

again, having trouble understanding that

sophiago00:10:03

how would i refer to a gen-class?

bfabry00:10:33

uhhh I'll try and explain in code

bfabry00:10:07

mmmm gen-class can't be used at the repl by the looks

sophiago00:10:24

that makes sense

sophiago00:10:27

let's step back

sophiago00:10:43

you're saying i'm referring to Number in the new project's ns directly?

sophiago00:10:55

i don't refer to it at all...

bfabry00:10:05

the line (extend-type Number

sophiago00:10:28

that's in the original project...

bfabry00:10:41

I think is probably referencing java.lang.Number, not symbolic_algebra.core.Number

sophiago00:10:19

i think you're confusing which ns is my checkout and which is the project i'm working on

sophiago00:10:32

the one you seem to be looking at is the checkout

sophiago00:10:39

so of course i'd refer to it directly

sophiago00:10:23

you were looking at that gist because you were helping me with print-method

sophiago00:10:39

not to qualify defrecords when required into another ns

sophiago00:10:44

that's the original ns

sophiago00:10:55

so i don't need to qualify anything

sophiago00:10:24

nothing else in that file is qualifed is it?

sophiago00:10:21

atho this could be the issue

bfabry00:10:34

nothing else is generated with gen-class. gen-class is very different to defrecord =/

sophiago00:10:22

you forgot the question i asked about

sophiago00:10:36

i asked about requiring one ns into another

sophiago00:10:45

at this point you're just looking at one ns

sophiago00:10:09

anyway, i still have my problem

sophiago00:10:24

gen-class works fine in the original ns

sophiago00:10:37

you're welcome to clone that library on github if you'd like

sophiago00:10:47

but i need to work on the other one i asked about here

sophiago00:10:06

i do think it's possible my issue could be solved by overriding the constructor with one that uses a qualified name Number

sophiago00:10:18

does that make sense?

bfabry00:10:36

what's the issue you're seeing? as far as I can tell the Number defined in the gen-class in that namespace is not being used anywhere or doing anything. I could be wrong, because gen-class always confuses me, but that's what it looks like

sophiago00:10:57

it's meant to be a base type so that when rationals reduce they'll dispatch to appropriately rather than having to choose one java type

bfabry00:10:12

also, you're specifying a :constructors key without an :init key, which is counter to the gen-class documentation

sophiago00:10:15

the error i'm seeing is "symbolic_algebra.core.Rational cannot be cast to java.lang.Number"

sophiago00:10:42

the gen-class documentation is not very good tbh

sophiago00:10:50

and it works fine in the library

bfabry00:10:54

hahaha, no, it is not

sophiago00:10:06

it's one of those functions no one knows how to use

bfabry00:10:13

but it is correct in that it doesn't make sense to specify :constructors without :init

sophiago00:10:16

it took me a whole night to figure it out

sophiago00:10:26

well, it works

sophiago00:10:40

anyway, i'm not totally sure it's even the problem here

sophiago00:10:23

i'm seeing stack traces into my overriden gcd and mod functions

sophiago00:10:52

or rather, overriden mod

sophiago00:10:08

i think the problem is i did not override rem

sophiago00:10:36

doing so requires using Java math and gets a bit hairy in edge cases

sophiago00:10:57

this is all the problem that comes with not having operator overriding

seylerius05:10:56

Okay, how would you filter a sequence based on a subsequent item?

seylerius05:10:22

I need to filter hiccup notation to remove any [:br] or series of them that immediately follows another tag, or that is immediately followed by another tag.

seylerius05:10:26

["foo" [:br] [:br] "bar" [:br] [:br] [:foo "foo]] becomes ["foo" [:br] [:br] "bar" [:foo "foo"]]

seylerius05:10:37

If the [:br]s are bounded on either side by a tag, rather than a string, they go.

bfabry05:10:57

@seylerius I'd probably filter with keep-indexed and just index back into the original collection to check was previous and next are. seeing as with hiccup the structure is probably a vector

bfabry05:10:51

oh actually it sounds like what you're doing is more complicated than what I thought, my bad

jrheard05:10:39

kinda sounds like a job for clojure.spec’s sequence regex capabilities

bfabry05:10:14

mmmm spec doesn't have lookahead or lookbehind

bfabry05:10:01

I think the answer is probably (partition-by identity

bfabry05:10:51

and then a reducing function with partition 3 1 nil

seylerius06:10:35

Essentially, if a [:br] is bounded on either side by something that isn't a [:br] or a string, it's tossed.

seylerius06:10:58

And this is repeated until there is no change.

rafaelzlisboa12:10:18

is there a best practice on how to create a stoppable and restartable core.async go-loop? i was thinking about close! ing the channel (3), then re-executing the go-loop part to restart it (2) - is that correct?

(comment
  ;; 1
  (def clockworker (let [time-channel (chan (async/sliding-buffer 1))]
                     (go-loop []
                       (let [_ (<! (timeout 2000))]
                         (>! time-channel (time/now))
                         (recur)))
                     time-channel))
  
  ;; 2
  (go-loop [] (when-let [time (<! clockworker)]
                (println "got time: " time)
                (recur)))
  
  ;; 3
  (close! clockworker))

dpsutton12:10:51

Has anyone reported that the clojure syntax highlighting doesn't seem to work with :: on http://clojure.org?

dpsutton12:10:09

not huge issue just making sure its been seen

Alex Miller (Clojure team)13:10:54

I’m aware of it, but haven’t spent any time looking at it

dpsutton13:10:29

cool cool. figured it wasn't high on any priority list if it was known

dpsutton13:10:48

by the way, has speaker list been announced for Austin conj?

Alex Miller (Clojure team)13:10:20

Lynn has been delayed as EuroClojure is under way atm

dpsutton13:10:47

fair enough. i'm just excited to see

Alex Miller (Clojure team)13:10:50

http://clojure.org uses highlight.js - looks like maybe the regexes there probably need to be tweaked

dpsutton13:10:04

yall are ridiculously proactive and thoughtful either way

Alex Miller (Clojure team)13:10:01

actually, looks like highlight.js fixed this in April and we’re using an older version, so I should be able to just include the latest

Alex Miller (Clojure team)13:10:14

I’ve pushed the update for that, should be live in about 15-20 m

slipset14:10:06

curious, why does ((fnil :key 0) {:key nil}) return nil, I would’ve thought it returned 0?

rauh14:10:17

@slipset fnil would never "kick in" with that argument

ghosss14:10:33

fnil is about what to do when the function is given a nil, not when it would return nil

rauh14:10:37

and then still, (:key 0) will result in nil

slipset14:10:04

@ghosss: thanks! not thinking today

rauh14:10:04

you could do ((fnil :key {:key 0}) nil) but why not just do (:key nil 0)

zalky15:10:54

Would anyone have any idea why extend-type and extend-protocol are so much more prevalent than just extend? My first impression would be that extend leads to more composable code. Are there any drawbacks to using extend over the other two? Thanks!

trptcolin15:10:53

@zalky they're convenience macros that just expand to extend in the end anyway

lxsameer15:10:00

hey folks, is there any lib that helps me reset my system ( system containing components ) when any file on my classpath changes ?

zalky15:10:20

@trptcolin : thanks, I thought so. I was worried there was some obscure reason they were preferred other than convenience (like how it's more performant to implement protocols directly in records and types, rather than extending them). But I've never been able to find anything.

Alex Miller (Clojure team)16:10:11

no reason that I’m aware of other than convenience

sophiago17:10:17

hi all, two questions (i believe i asked one less clearly last night):

sophiago17:10:07

1. when requiring a library with gen-class and a constructor in it, what extra must one do to make that work?

sophiago17:10:13

2. i had assumed all along that clojure did not support operator overloading, but looking through the core source it seems it may be possible. could someone please clarify this? it would mean worlds of difference for me

Alex Miller (Clojure team)17:10:19

1. require the library (to cause it to be loaded and the compiled class to be created). instantiate the class using the constructor via java interop.

sophiago17:10:46

i'm using checkouts to require the library and then aliasing it

sophiago17:10:12

but seems i also need to have the constructor pasted in separately

Alex Miller (Clojure team)17:10:52

2. from a general perspective, there are no operators, just functions and Clojure allows functions to be modified. Protocols and multimethods both support type-based dispatch. That said, things around math are a bit more complicated, especially due to a) inlining, b) Clojure’s approach to numerics and c) direct linking of core

Alex Miller (Clojure team)17:10:30

I don’t get what that means re “pasted in separately"

sophiago17:10:03

ok, handling the first issue first...

sophiago17:10:43

if i don't copy the constructor directly into the ns i'm working in then it's not required with everything else

Alex Miller (Clojure team)17:10:06

I think it would be helpful to be more precise with terms

sophiago17:10:10

or rather it just doesn't work when tested in the repl

Alex Miller (Clojure team)17:10:18

“require” means “load the namespace"

Alex Miller (Clojure team)17:10:44

and in particular create and load the Java classes that implement the functions

sophiago17:10:07

i'm sorry, very new to maven/lein/build stuff

sophiago17:10:12

back to square one

sophiago17:10:15

i'm using checkouts

Alex Miller (Clojure team)17:10:17

no worries, I’m not criticizing

Alex Miller (Clojure team)17:10:33

just trying to be precise so these words mean good things in relation to other docs

sophiago17:10:36

requiring the library ns and aliasing it with :as

Alex Miller (Clojure team)17:10:02

so that’s really two parts - the require and the alias

Alex Miller (Clojure team)17:10:13

require ultimately results in a call to load to load the code

sophiago17:10:18

but then i realized (separate issue, just pointing it out as part of my learning curve) i had to use a different syntax) for the defrecords

Alex Miller (Clojure team)17:10:36

alias modifies a mapping of aliases to namespaces in your current namespace

Alex Miller (Clojure team)17:10:19

when you say “constructor” what do you mean exactly?

sophiago17:10:11

ok, well for starters i was suspicious because of the defrecords needing a special syntax since they create java classes

Alex Miller (Clojure team)17:10:40

they are really independent things, so let’s stick with gen-class

sophiago17:10:20

and then i have a class extended from an abstract java class using gen-class (this is actually what led to that patch i proposed on the dev list you responded to, if you remember)

sophiago17:10:38

so the constructor i'm referring to is the constructor for that gen-class

sophiago17:10:06

i realized yesterday that without copying the constructor into the ns i'm working in i couldn't use it in the repl

sophiago17:10:20

(or perhaps the issue is i needed a special syntax?)

Alex Miller (Clojure team)17:10:33

do you mean a function named in the gen-class :init ?

Alex Miller (Clojure team)17:10:58

and you are trying to instantiate the class created by gen-class?

Alex Miller (Clojure team)17:10:17

if so, you should not use the function named by :init

Alex Miller (Clojure team)17:10:31

you should use Java interop to instantiate the class (it’s just a Java class)

sophiago17:10:33

well, i don't actually need an init function

sophiago17:10:43

i have :constuctors

sophiago17:10:07

and then a function that takes that form

sophiago17:10:23

so it's like :name Foo

sophiago17:10:30

and then (defn -foo

Alex Miller (Clojure team)17:10:34

you should instantiate the class using (Foo. …)

sophiago17:10:41

or (defn -Foo

sophiago17:10:46

actually in the repl new instances are created like (-Foo ...)

Alex Miller (Clojure team)17:10:52

to do this, you will either need to import that class, or to use the fully-qualified class name when you invoke the constructor

sophiago17:10:14

but the thing is it's only for dispatch so i don't actually need to do that anywhere in the code

Alex Miller (Clojure team)17:10:14

you should not invoke (-Foo …) directly

sophiago17:10:34

i was just testing that in the repl to see if it could be the source of a bug

sophiago17:10:49

oh wait, no sorry i was wrong about that (a month off of looking at code and i can forget things)

sophiago17:10:03

i do have a coercion function where i call that constructor

sophiago17:10:21

but to be on the same page, this is all inside the original ns

sophiago17:10:33

not sure if that's what you were thinking

sophiago17:10:50

and it was seemingly working fine

sophiago17:10:36

i'm having problems now that i'm requiring (hope correct terminology) it in another ns

Alex Miller (Clojure team)17:10:08

you need to require the namespace to cause the class to be created

sophiago17:10:18

i am doing that

Alex Miller (Clojure team)17:10:41

you need to import the generated class if you want to be able to invoke it via an unqualified class name in Java interop

sophiago17:10:41

in addition to having it as a dependency

Alex Miller (Clojure team)17:10:56

you probably do NOT want to invoke functions in that namespace directly

hiredman17:10:02

you also need to compile the namespace, gen-class doesn't do anything unless you are aot compiling

Alex Miller (Clojure team)17:10:20

well, I’m not sure that’s actually true anymore

sophiago17:10:37

there should be no point where i call this particular function we're discussing in the new ns

hiredman17:10:10

@alexmiller the doc string for gen-class still says it 🙂

Alex Miller (Clojure team)17:10:11

it would be tremendously helpful to see a) the code, b) what you are trying to do, c) what you are getting and d) what you are expecting

sophiago17:10:23

the other classes (created with defrecord) i used alias/->Class syntax

Alex Miller (Clojure team)17:10:40

records are totally different (and that is correct for records)

Alex Miller (Clojure team)17:10:51

the fact that they generate Java classes is an implementation detail

Alex Miller (Clojure team)17:10:49

whereas that is the explicit intended effect of gen-class

Alex Miller (Clojure team)17:10:04

and on another tangent, it’s perfectly ok to write your Java concrete class extension in Java rather than in Clojure (and depending what you’re doing, this can be way easier)

sophiago17:10:47

well, mainly i'm experiencing type casting error and not certain whether it's due to the class created by gen-class since the point of it (as i describe in that post on the dev list) is to use as a base type for dispatch, not to call directly. so i tried instantiating it in the repl and it wasn't working. now, as stated above...this could be a syntax issue (but we already determined i'm using an odd syntax in my original ns compared to how you would do it: the gen-class docs are notoriously sparse) OR it could be that it's just not be required with everything else. so in response to that i just copied the function i use to instantiate it into my new ns and lo and behold it works in the repl. however, i still get an error when running the new code....just a different error

sophiago17:10:11

(also to be noted, i'm not at all a Java programmer)

sophiago17:10:51

@alexmiller since you seem to be one of the few people who understand gen-class perhaps the best way to go about this is to see if you can correct my syntax with that? and then i can see if that allows me to instantiate that class in the repl using the ns i'm currently working in? that would rule out many issues i think

hiredman17:10:55

@sophiago if you are not a java programmer, I would strongly suggest not using gen-class. It exists pretty much entirely to interoperate with java where java requires a concrete class

hiredman17:10:12

but I don't know what you are trying to do

sophiago17:10:40

@hiredman it's a little late for that... it was a long night of frustration, but i did get it working, if oddly working

sophiago17:10:24

anyway, the code is here and the gen-class and function and question is conveniently right at the top: https://github.com/Sophia-Gold/Symbolic-Algebra.clj/blob/master/src/symbolic_algebra/core.clj

sophiago17:10:26

...sorry, though i set slack up so it would share that inline as a paste

hiredman17:10:21

what is that gen-class supposed to do?

hiredman17:10:13

as is, I am pretty sure that code won't compile, 'num' isn't defined

sophiago17:10:22

it does compile

sophiago17:10:25

that code is fine

sophiago17:10:43

the problem is requiring it as a library

hiredman17:10:54

what makes you think it does compile?

Alex Miller (Clojure team)17:10:14

line 2 - should be :gen-class, not gen-class (this won’t even compile in 1.9)

sophiago17:10:38

i'm abusing terminology again

Alex Miller (Clojure team)17:10:41

line 3 - should probably be a fully-qualified class name including the package you want

sophiago17:10:50

it runs fine

Alex Miller (Clojure team)17:10:00

it is possible (but frowned upon) to create a class in the no-segment “default” package

Alex Miller (Clojure team)17:10:26

I don’t think there’s any need for :constructors at all if you’re doing what you have there

hiredman17:10:33

oh, no kidding, 'num' is in core

sophiago17:10:11

stepping back, i don't understand your comment about line3

Alex Miller (Clojure team)17:10:28

Java classes exist in a hierarchical tree of packages

Alex Miller (Clojure team)17:10:56

similar to Clojure namespaces (although the hierarchy is purely name-based in Clojure, not meaningful to Clojure)

sophiago18:10:06

i thought the name field was for the class name i gave it in clojure?

sophiago18:10:22

oh you mean the fully qualified name in clojure?

Alex Miller (Clojure team)18:10:23

by saying :name is Number you are literally creating a Java class whose fully-qualified name is “Number"

sophiago18:10:42

symbolic-algebra.core/Number ?

Alex Miller (Clojure team)18:10:43

generally you want to give it a package like symbolic-algebra.Number

Alex Miller (Clojure team)18:10:01

or symbolic-algebra.core.Number

Alex Miller (Clojure team)18:10:09

that’s a fully-qualified Java class name

Alex Miller (Clojure team)18:10:17

the / syntax is for Clojure vars

Alex Miller (Clojure team)18:10:35

the -Number function is not doing anything useful in your gen-class afaik

sophiago18:10:51

well i do need a way to instantiate it

Alex Miller (Clojure team)18:10:01

yeah, but that’s not how it works

sophiago18:10:12

you're going to say i should use init and state instead?

Alex Miller (Clojure team)18:10:13

it looks like you are trying to create a subclass whose constructor returns something of a type other than itself

Alex Miller (Clojure team)18:10:18

which is not possible in Java

hiredman18:10:18

at least as an example of how other people have approached a similar problem

Alex Miller (Clojure team)18:10:30

gen-class does not allow you to explicitly define a constructor method

Alex Miller (Clojure team)18:10:01

rather you define an init method which acts as a bridge between subclass constructors and superclass constructors

Alex Miller (Clojure team)18:10:36

the init method should respond to any constructor type signatures you define (in :constructors) and should return arguments that are used to invoke the super class

sophiago18:10:51

i looked at math.numeric-tower and that was specifically what i was trying to avoid in implementing it this way

Alex Miller (Clojure team)18:10:54

in Java, the super class constructor is always called last (if not explicitly, than implicitly)

Alex Miller (Clojure team)18:10:55

and the concrete type returned by a Java constructor is always the type of the class whose constructor you invoked (that’s not necessarily true in other langs like Ruby afaik)

hiredman18:10:06

what about it are you trying to avoid?

sophiago18:10:45

@hiredman i'd like to please just focus on the implementation details because my brain can't absorb that and have two conversations at once

sophiago18:10:07

but maybe return to that later

hiredman18:10:19

the problem is thehy tie together

Alex Miller (Clojure team)18:10:31

afaict, you’re not using your Number subclass at all

sophiago18:10:49

in one of my coercion functions

Alex Miller (Clojure team)18:10:50

you’re just invoking the function -Number which calls num

sophiago18:10:05

ok so if you want to have that discussion first

Alex Miller (Clojure team)18:10:07

but that’s just a function that happens to be named -Number - it has no link to your class

hiredman18:10:40

basically your gen-class stuff compiles, but is meaningless in the context of whatever you are trying to do

Alex Miller (Clojure team)18:10:43

that is, you could remove the gen-class and replace the calls to -Number with num and it would be identical

Alex Miller (Clojure team)18:10:12

which maybe is totally ok?

sophiago18:10:16

rationals are at the bottom of my numerica tower and i'd like them to dynamically dispatch to java's numeric types using clojure's builtin methods to do so rather than handrolling all that myself as the other example did

sophiago18:10:22

@alexmiller hmm if that would work i'm going to feel very stupid about this whole endeavor

sophiago18:10:53

and then you're saying eliminate the protocol for it as well?

sophiago18:10:08

since it's just core math?

sophiago18:10:53

(sorry not protocol: extend-type)

sophiago18:10:12

without that there would be no calls to coerce them upwards when the classes don't match

sophiago18:10:31

seeing as protocols dispatch only based on the first argument

sophiago18:10:39

and i really do not want to switch to multimethods

Alex Miller (Clojure team)18:10:40

wait, I guess that’s not actually doing anything

Alex Miller (Clojure team)18:10:40

I retract that, was reading it as extend-protocol

sophiago18:10:58

well i did screw up terminology again

sophiago18:10:26

it's not all fine because i can't leave that extend-type without having the gen-class

Alex Miller (Clojure team)18:10:43

it’s not using your Number - it’s using java.lang.Number

sophiago18:10:10

java.lang.Number is an abstract class though?

Alex Miller (Clojure team)18:10:28

it’s ok to extend a protocol (Algebra) to an abstract class (Number)

Alex Miller (Clojure team)18:10:37

protocols do Java hierarchy type matching

sophiago18:10:11

so i would replace Number with java.lang.Number?

Alex Miller (Clojure team)18:10:19

you don’t need to - it’s already doing that

Alex Miller (Clojure team)18:10:34

all classes in java.lang are automatically imported

sophiago18:10:43

well that makes sense

sophiago18:10:50

when you say it like that

Alex Miller (Clojure team)18:10:04

(which is another reason that using bare classes in gen-class like Number can cause confusion)

sophiago18:10:31

yeah it was totally unnecessary all along

sophiago18:10:40

i wonder what people thought when i proposed that patch to the list?

sophiago18:10:47

someone actually chimed in thinking it was a good idea

sophiago18:10:07

guess he's not a java coder either

Alex Miller (Clojure team)18:10:09

I had a hard time wrapping my head around what it was actually doing and really replied to the intent :)

sophiago18:10:49

it was this, except replace java.lang.Number with clojure.lang.Numbers

sophiago18:10:58

i.e. how you implement core math

sophiago18:10:33

and tbh the real impetus for thinking it was a good idea for a patch rather than just my own code was that just weeks prior David Nolen (no offence, he's solely the reason i'm using clojure today) was giving a speech talking about how eventually there would be clojure in clojure for the jvm

sophiago18:10:50

which i now understand to not be the case as well as the reasons why

Alex Miller (Clojure team)18:10:03

well I wouldn’t say that will never happen

Alex Miller (Clojure team)18:10:08

as never is a long time :)

sophiago18:10:14

well likely not entirely, right?

dpsutton18:10:28

clojure in clojure for the jvm?

sophiago18:10:30

given the issues with math brought up by mike of core.matrix?

sophiago18:10:45

the protocol speed hit?

hiredman18:10:47

even if it was the case, the dispatch in clojure.lang.Numbers being closed or open is a separate issue from clojure in clojure

sophiago18:10:04

@hiredman i understand that now

Alex Miller (Clojure team)18:10:20

there are a lot of reasons why clojure in clojure may not be something that anyone would actually want to use

sophiago18:10:05

yeah, it's an a rock and hard place for me given i frankly am not only not a java coder but really don't like java as a language yet i understand all the reasons for needing some parts to be low level like that even though it impacts writing libraries to some degree

sophiago18:10:21

(pardon my typing please)

sophiago18:10:50

anyway, before i take up too much time... @alexmiller can i clarify overriding core math functions as it would pertain to this library you just looked at?

Alex Miller (Clojure team)18:10:45

well, that’s challenging :)

Alex Miller (Clojure team)18:10:24

Clojure is not currently open for extension in that way - that was the intent of the other thread I pointed at in my response on the list

Alex Miller (Clojure team)18:10:46

you could theoretically override the vars for things like +

Alex Miller (Clojure team)18:10:21

however, those functions are inlined (which means that existing compiled code wouldn’t see it)

Alex Miller (Clojure team)18:10:38

and Clojure core is AOT direct linked, which means other calls from within core to those functions would not see the changes

sophiago18:10:41

yes, i've noticed two implementations

sophiago18:10:50

well, i do already have to rewrite some core math functions like mod and rem obviously

Alex Miller (Clojure team)18:10:58

so you either need to define your own functions or fork Clojure

sophiago18:10:02

but this goes far beyond that when you're talking compilation

hiredman18:10:05

I have this abandoned (and unfinished( project that used rules about numeric types (written in core.logic) to generate a replacement for Numbers.java, the idea being that even though that is not runtime extendable it would be clearer than Numbers.java, and would be easier to generate your own custom Numbers.java that took in to account whatever types

sophiago18:10:57

@alexmiller when you say "define your own functions" you must mean far beyond what i've already had to do, correct?

Alex Miller (Clojure team)18:10:11

no, that’s what I was referring to

sophiago18:10:44

so....maybe at this point the only downside is other people's code?

Alex Miller (Clojure team)18:10:13

where “other people’s code” includes core

sophiago18:10:59

core math functions are quite slim tho. that was a calculated choice i believe

Alex Miller (Clojure team)18:10:13

yeah, maybe it wouldn’t affect much

sophiago18:10:49

well, i'm saying regardless of whether i override + or use add i need to redefine mod and rem anyway

sophiago18:10:07

because i use a gcd function that needs them

sophiago18:10:29

and it is challenging, don't get me wrong

sophiago18:10:34

the edge cases...

sophiago18:10:04

but not a huge deal

dpsutton18:10:43

will you redefine empty?

sophiago18:10:10

isn't that just for sequences?

sophiago18:10:16

i'm only talking math

dpsutton18:10:23

well, there was a fun day where someone wanted to redefine it for integers as well

Alex Miller (Clojure team)18:10:24

yeah, I found that question confusing too

sophiago18:10:39

there's equal

dpsutton18:10:53

i'm totally not serious. I've been enjoying reading along

dpsutton18:10:14

but this person wanted (empty? 5) => false and (empty? 0) true

sophiago18:10:16

thanks for reminding me

Alex Miller (Clojure team)18:10:28

yeah, that person is just wrong :)

dpsutton18:10:47

it conforms with the Peano axioms though ...

hiredman18:10:19

0 is empty for addition but not multiplication

dpsutton18:10:33

in peano axioms zero is the empty set

tbaldridge18:10:55

@sophiago What I've done in cases like this is implement my logic in one namespace, then in another import clojure excluding +, -, etc. Then define those functions. So you can do (:require [my.math as m]) and write (m/+ (m/- x y) 4) to call your special logic

dpsutton18:10:57

and 1 is the set containing zero, 2 the set containing 1, etc

dpsutton18:10:04

but i didn't mean to derail

dpsutton18:10:06

i'm sorry yall

hiredman18:10:21

I saw that discussion the other day

hiredman18:10:55

+ and 0 are a monoid, with 0 being the identity or the empty element

sophiago18:10:04

@tbaldridge thanks! that's helpful. i'm already doing this in it's own ns anyway

dpsutton18:10:06

yeah there are several ways to define structures

dpsutton18:10:16

i meant that you could define the integers themselves

dpsutton18:10:23

and not just a group or ring structure

dpsutton18:10:49

but that zero is literally the empty set, kinda like how Church defined the integers to be certain functions

Alex Miller (Clojure team)18:10:17

to be fair, Church’s language wasn’t winning in the Alioth perf rankings

hiredman18:10:24

sure, the monoid thing was just the objection that I thought of to defining (empty? 0) => true

dpsutton18:10:29

yeah i got a copy a few weeks ago and gave up quickly

dpsutton18:10:33

that is some tough reading

hiredman18:10:09

(when I saw the original discussion here)

sophiago18:10:52

or actually, wait @tbaldridge let me make sure i'm clear about how you're doing this...

dpsutton18:10:59

i'm not sure. I'm just saying that since the empty set is empty, if 0 is the empty set (empty? 0) could be argued to return true. but it would be a very bad way to set up a programming language environment

sophiago18:10:20

just whenever you import the ns where you override those functions you also import clojure excluding them?

Alex Miller (Clojure team)18:10:05

@sophiago not sure if hiredman is replying to you or the other discussion, but I would say yes

hiredman18:10:16

only if you are refering them

sophiago18:10:42

@alexmiller p sure other discussion...

hiredman18:10:02

but yes, you have to do something one way or another to disambiguate

hiredman18:10:16

I can do both 😛

sophiago18:10:18

and in this case i'm unlikely to just refer them since they're used in protocols

tbaldridge18:10:24

@sophiago no, any namespace that used your math namespace you'd assign it a name (like 'm') then call the functions via (m/+). In other words, don't try to replace Clojure math, make it clear when you're using your math instead of Clojure's

Alex Miller (Clojure team)18:10:50

One choice:

(ns other
  (:refer-clojure :exclude [- +])
  (:require [my.algebra :refer [- +]]))

amacdougall18:10:23

I like that one. If you really need to have local plain operation symbols, at least the top of the file makes it clear what's going on.

sophiago18:10:23

@tbaldridge ah ok, that's essentially what i'm doing right now except with + instead of add, etc.

Alex Miller (Clojure team)18:10:35

Another choice:

(ns other
  (:require [my.algebra :as m]))

… m/+ …

sophiago18:10:00

i suppose if i need to actually rewrite core math the advantage is only legibility

sophiago18:10:00

so do i want users to be clear they can't use all of core math functions with them since i won't rewrite all of them?

sophiago18:10:21

and sacrifice the legibility of a language with true operator overloading like haskell?

Alex Miller (Clojure team)18:10:41

in actuality, the choice is not yours - it’s up to the user’s namespace that is pulling yours in

sophiago18:10:24

well, most likely the user here is me so yes it is my choice

sophiago18:10:32

well...i have to require is as something unless i want to use the full ns

arrdem18:10:53

Yes. By default require won't give you a nice alias.

sophiago18:10:00

or in the first choice i'm actually replacing them and reminding the user (again, me) not to use functions that haven't been redefined?

dpsutton18:10:03

that's holding a lot of info in your head

hiredman18:10:28

well, the compiler will helpfully fail to compile code that references something that is undefined

sophiago18:10:28

no because, once again, there are very very few core math functions

hiredman18:10:43

so you don't actually need to keep that in your head

sophiago18:10:44

and how many do you actually use?

sophiago18:10:46

at this point my math is all high level and i just need to replace the lower level functions

hiredman18:10:52

only inc, dec, and (def empty? zero?)

sophiago19:10:18

lol still on how empty? is math huh

dpsutton19:10:15

if its applied to integers ...

sophiago19:10:55

i stayed out of that one

sophiago19:10:53

ok so i need to actually code all of this but i think the only thing i'm left unclear on is this:

sophiago19:10:11

does that mean i don't need to qualify them?

tbaldridge19:10:31

Yes you wouldn't have to qualify them

sophiago19:10:39

so just "user beware"

sophiago19:10:04

in that case...very clearly my choice

tbaldridge19:10:14

Yeah, as a programmer I really don't like it when someone re-defines something that looks like a core function into something that's not

hiredman19:10:50

how about languages that use '+' for math and string concatenation

sophiago19:10:04

@tbaldridge did you mean to say "as a java programmer" 😉

sophiago19:10:22

because that's the norm in C++ and Haskell

sophiago19:10:32

among others

tbaldridge19:10:34

Nah, if did x = 1 + 2 in C++ and got back a string I'd be just as unhappy.

tbaldridge19:10:54

And let's not forget that operator overloading abuse is also a thing in many languages.

sophiago19:10:16

but that's on the programmers, not on the language designers

sophiago19:10:39

i'm doing it this way because the jvm doesn't allow me any other

sophiago19:10:47

and i perfer legibility

tbaldridge19:10:09

Use a different namespace, and refer it as "m/" that's kindof what namespaces are for.

sophiago19:10:35

in fairnewss legibility can mean different things

tbaldridge19:10:03

I'm just saying that if I saw that "refer-clojure...require" combination, quoted above, in a code review I'd probably say "let's find a better way to do this...".

sophiago19:10:40

fair enough

sophiago19:10:22

from my point of view out of necessity i'm 7/12 of the way from having overwritten all of core math hence negating your issues with it

sophiago19:10:04

oops didn't count correctly

sophiago19:10:23

eh, arithmetic at least

noprompt19:10:10

is it possible to define new clauses for the conditional reader macro? e.g. :node, :phanatomjs, etc.

noprompt19:10:38

#?(:phantomjs x,,,)

noprompt19:10:22

if not, are there plans to extend the conditional reader macro in the future with this sort of feature?

tbaldridge19:10:06

@noprompt take a look at tools.reader, from what I can see it might offer that as a parameter

noprompt19:10:36

@tbaldridge thanks tim. will have a look.

hiredman19:10:40

but I doubt it will do what you want

hiredman19:10:56

clojurescript is read and compiled to javascript a head of time

noprompt19:10:59

@hiredman dashing my hopes so soon?

hiredman19:10:11

so by the type you are executing phantomjs the reader is done and gone, no?

tbaldridge19:10:29

yeah, he didn't define what he was trying to do here

noprompt19:10:12

@hiredman supposing that you could configure that you're compiling against that environment ahead of time, no.

noprompt19:10:17

or, rather, no?

hiredman19:10:39

sure, I guess

hiredman19:10:54

or just add some kind of runtime sniffing and do whatever at runtime

noprompt19:10:25

what i'd like to be able to say is that whenever i build this set of files i want the reader to honor, say, the :phantomjs clause.

noprompt19:10:06

in addition to the :cljs clause.

noprompt19:10:04

i'll give this a shot.

noprompt19:10:15

(what tim suggested.)

hiredman19:10:04

http://dev.clojure.org/display/design/Reader+Conditionals does list "Open feature set" as a future extension

hiredman19:10:32

I still think they are kind of gross

sophiago19:10:53

ugh, all of that earlier and i'm still getting that error. qualified or not you do need to override core math functions and i ended up having a bug in rem that i just reverted to the built-in in the original version...not good enough anymore apparently according to the stack trace and i'm really not sure what it could be other than some type of rounding error with java math 😕

sophiago20:10:44

phew... think i fixed that. it was a mistake to look at the cljs code. too convoluted in attempting faithfulness to horrible js math

sophiago20:10:10

i really don't hate js like other people do, but the math is truly some shit

sophiago20:10:16

yikes...still type cast exception though

sasha21:10:32

hi, someone use http-kit server?

tbaldridge22:10:15

@sasha I have, do you have a question?

sasha22:10:00

@tbaldridge: yep, i configurate number of threads, but result is constant.

sasha22:10:14

@tbaldridge: and worker-name-prefix not working too

tbaldridge22:10:01

@sasha have some example code?

sasha22:10:09

@tbaldridge: i have (run-server app {:thread 9 :worked-name-prefix "project"})

tbaldridge22:10:41

check your spelling...

sasha22:10:12

@tbaldridge: sorry i don't understand

tbaldridge22:10:11

:worked-name-prefix vs :worker-name-prefix

tbaldridge22:10:20

and I think the docs are wrong

tbaldridge22:10:28

:thread is probably :threads

tbaldridge22:10:33

doesn't make any sense as :thread

sasha22:10:16

@tbaldridge: yep, sorry, worker offcorse

sasha22:10:25

@tbaldridge maybe we have bug in docs has :thread

tbaldridge22:10:44

yeah :thread is correct (looked at the source). IDK then, how do you know it's not working?

sasha22:10:39

@tbaldridge: ps -efT | grep java and htop, and i don't see name of thread

tbaldridge22:10:32

@sasha sorry, that's all I got. I haven't dug this deep into http-kit before. I stopped using it when I encountered some other things I didn't find acceptable.

sasha22:10:13

@tbaldridge: Thanks, which server you are using?

tbaldridge22:10:15

I recommend Pedestal http://pedestal.io/ , but that depends a bit on what you are trying to build.

sasha22:10:53

@tbaldridge: i have ring, compojure and need only http-server

tbaldridge22:10:38

@sasha have you considered ring-jetty then? That's probably the standard approach