Fork me on GitHub
#clojure
<
2018-09-15
>
pbaille05:09:23

hello, i've just realised (= '(1 2 3) [1 2 3]) ;;=> true. if for some reason i don't want this behavior, what can I do?

alexmiller11:09:45

You can add an additional check on type, but I would really suggest that you try relaxing your expectations

alexmiller11:09:45

The reasons for this are subtle and important and in many ways essential for Clojure to be what it is

porkostomus05:09:06

(identical? '(1 2 3) [1 2 3]) ;;=> false

sundarj05:09:01

@pbaille depending on the reason you don't want it, you can do things like (and (seq? x) (seq? y) (= x y)), (and (= (type x) (type y)) (= x y))

pbaille05:09:19

yes that's what i'm doing, but i was hoping for a builtin

pbaille05:09:25

what i'm reluctant to do is wrap this kind of check around core/= (for performance reason, but maybe i should not care)

pbaille05:09:11

@porkostomus does identical? compare things by value or by reference?

porkostomus05:09:03

I just realized that's not what you want because (identical? [1] [1]) ;;=> false

porkostomus05:09:14

it has to be the same object

pbaille05:09:26

yes that's what i was suspecting

porkostomus05:09:28

A word of warning from https://clojure.org/guides/comparators - "Do not write a boolean comparator that returns true if the values are equal. Such a comparator is inconsistent. It will cause sorted collections to behave incorrectly, and sorting to give unpredictable orders."

seancorfield05:09:41

To be clear, boolean comparators are not = by definition. Boolean comparators are < -- a total ordering.

seancorfield05:09:10

(so, really, that has nothing to do with what @pbaille is asking about)

porkostomus05:09:11

I did realize that eventually.. I probably shouldn't be trying to give advice

andy.fingerhut06:09:35

@pbaille If you want (= '(1 2 3) [1 2 3]) => false, then my recommendation would be to modify the relevant Clojure implementation parts, written in Java for Clojure on the JVM, that make it true. I would expect that if you change that behavior of clojure.core/=, then some other parts of Clojure's implementation that expect the current behavior may break and need changing.

alexmiller11:09:42

This is bad advice

alexmiller11:09:49

I think it would be much more fruitful to work to understand this aspect of Clojure

andy.fingerhut15:09:23

Agreed that it would be an arduous task that might not end up where they want, hence my "If". Also agreed that trying to change someone's mind about the goal is a better idea.

andy.fingerhut07:09:29

Note: I am not saying that I have tried making such a change and I know from experience that something else will break as a result. But such a design decision is pretty fundamental in Clojure, so it would surprise me if nothing else in Clojure's implementation relied upon that. A lot of Clojure is written in Clojure.

pbaille07:09:47

@andy.fingerhut modifying clojure implementation is not something that I consider for such things 🙂 but maybe one day to hack the reader or some other things. thank you for your help

pbaille07:09:40

@porkostomus 🙂 i think one should always try, i appreciate your advices.

alexyakushev08:09:03

Can anyone explain to me the purpose of vector-of? It stores primitives unboxed, but I can't find the way to retrieve those primitives from it without boxing.

alexmiller11:09:04

Better memory use, but you’re correct re boxing. You really need Java arrays to avoid that.

alexyakushev12:09:00

Thanks, Alex. Is it correct to say that this is an unfinished experiment rather than something complete? I don't think I ever saw it used anywhere. Are there any hypothetical plans to pursue this direction further?

alexmiller13:09:08

It accomplishes the goal of much more efficiently storing a vector of primitives

alexmiller13:09:11

We have talked about ways to extend the standard IFn to support primitive longs and doubles. If we did so, then it would actually be possible to extract primitive longs and doubles from vectors of those.

alexyakushev13:09:42

Thanks for clarification.

andrea.crotti08:09:25

I think unless it's a personal project and it's just for fun @pbaille none of your colleagues will probable appreciate a change like that

andrea.crotti08:09:43

Assuming there is a way (which probably is just forking clojure anyway)

pbaille08:09:08

@andrea.crotti yes i agree, for better or worse i have no colleagues currently, neither production targeted project 😉

pbaille08:09:38

does cognitect works on 2.0? (with breaking changes) just curious... (i'm aware of rich's spec-ulation, so maybe i should not ask but... (ps: this is not related to my last question)).

alexmiller10:09:41

No plans for a 2.0 right now. Next release will be 1.10

triss09:09:00

So I think I’m gonna need to give my maps a :type keyword even though they have namespaced keys to make writing a multimethod easy…

triss09:09:34

Is that an antipattern in Clojure these days?

triss09:09:17

Part of me feels like I could s/conform and choose to dispatch off the result of that.

triss09:09:23

but that feels expensive…

misha10:09:29

(->> my-maps
  (mapcat :x)
  (apply concat)
  (apply hash-map))
feels like abusing apply when things might get long

misha10:09:24

(into {}
    (comp
      (mapcat :x)
      (map vec))
    my-maps)
harold

kulminaator11:09:06

triss i'm afraid there is lack of background information to give you good advice

kulminaator11:09:32

i would not worry about the cpu overhead too much

kulminaator11:09:57

it's more a question of context .... i have seen code where conform can be a nice clean readable solution but i have also seen ruby monoliths aged 10 years which are a mess due to using similar approach as a hammer, and over there these things have 9 legs and 3 eyes and you don't want to be there 😞

roti12:09:02

has anyone experience with a JavaFX wrapper in clojure?

sb15:09:56

Maybe the fn-fx? Slack/ fn-fx channel. @roti

kwladyka18:09:27

deps.edn form-validator {:local/root "../form-validator-cljs"} How to configure deps.edn to make reload ns after change in form-validator module?

kwladyka18:09:54

I need it during developing module

seancorfield18:09:57

@kwladyka That's out of scope for clj and deps.edn -- you can (require ... :reload) in the REPL tho'...

kwladyka18:09:58

Is it best practice nowadays?

kwladyka18:09:39

Alternative way to develop module? This one is actually about cljs.

seancorfield18:09:43

Best practice is probably building something based on Component (or something similar) and baking the whole start/stop/reload thing into your REPL workflow...

kwladyka18:09:25

hmm but on the other hand it will make “fake complex” example how to use this module. My intention is to have: repo form-validator and form-validator-demo, which I will use for demo and manual tests in web browser during developing.

kwladyka18:09:40

Am I have bad assumptions?

seancorfield18:09:44

I'm not really understanding what you're asking at this point if my answers aren't helping 😞

kwladyka18:09:39

it helps, but while I can’t make this reloading simple I am thinking if my assumption about how to develop this module are right

kwladyka18:09:21

1) repo form-validator with code and tests in REPL 2) repo from-validator-demo which depends on form-validator and it is about use in web browser

kwladyka19:09:12

Can I do my assumptions about how to develop module and example code better?

kwladyka19:09:06

Asking in different words: Like I am doing it now is ok? Would you do it in the same way?

kwladyka19:09:42

hmm actually how to reload ns from the code? I could maybe use this:

(defn ^:before-load before-reload []
  (require 'form-validator.core :reload))
But Calls to 'require' must appear at the top-level.

kwladyka19:09:55

ok I guess it is not possible

seancorfield19:09:48

That must be a ClojureScript limitation. You can call require programmatically like that in Clojure.

seancorfield19:09:58

Try asking in #clojurescript and see what folks recommend there.

seancorfield19:09:24

I can't help with cljs -- I only do Clojure. Sorry.

mfikes19:09:19

Right, you can't put a require inside of a function like that in ClojureScript.

mfikes19:09:55

TL;DR reason: in ClojureScript functions are runtime, while require is compile time