Fork me on GitHub
#clojure
<
2018-07-26
>
vigilancetech06:07:09

why does this result in false? (reduce 'or '(false false true false false))

fmn06:07:28

@vigilancetech because you are using Symbol as a function (in this case it's 'or)

fmn06:07:24

@vigilancetech and it behaves like a keyword. It roughly translates to (:some-keyword {} "default value if not found")

vigilancetech06:07:59

so how do I do it?

fmn06:07:18

(reduce 'or '(false false true false false))

;; similar to 

(reduce #('or %1 %2) '(false false true false false))

;; Notice that the `Symbol` behave like a keyword:

('or {'or 2} 3) => 2

('or {'foobar 2} 3) => 3

;; So step by step:

('or false false) => false ;; feed this to the next iteration
('or false true) => true
('or true false) => false
('or false false) => false

fmn06:07:44

Since or is a macro, you should wrap it an anonymous function

fmn06:07:30

(reduce #(or %1 %2) '(false false true false false))

vigilancetech06:07:26

ah, ok thanks! I'll try it

fabrao10:07:42

Hello all, is there a way to generate the predicate for filter

(filter
   #(or
     (clojure.string/includes? (clojure.string/upper-case (:codigo %)) (clojure.string/upper-case filtro))
     (clojure.string/includes? (clojure.string/upper-case (:nome %)) (clojure.string/upper-case filtro))) dados)
dynamicaly?

sundarj13:07:48

i would split that out into its own function

octahedrion10:07:44

why oh why are Clojure REPLs not Clojure data structures themselves ? I want to be able to 'branch' a REPL session and explore a tangent without affecting where I was before, and I want to be able to persist and restore sessions

fenoloftaleina10:07:59

https://clojure.org/guides/repl/enhancing_your_repl_workflow - don’t type into a repl, connect your editor to your repl, and use files, @octo221.

pvillegas1211:07:25

What is the current status of om-next?

nha11:07:49

I think most new projects use #fulcro @pvillegas12

dominicm11:07:57

@pvillegas12 they forked om.next, and have done a great job documenting and improving it.

👍 20
borkdude11:07:55

Is there something like require + in-ns? I don’t want to create a new ns

octahedrion11:07:00

@fenoloftaleina I mean REPL-as-immutable-data-structure; files and namespaces are mutable

bronsa11:07:06

but (doto 'my-ns require in-ns) works

borkdude11:07:51

indeed, thanks

fmn11:07:15

@fabrao why not just factor it out to a function?

fabrao11:07:38

@funyako.funyao156 I could not follow your idea, can you give me an example?

fabrao11:07:40

the #(or <predicates-list>) -> predicates will be dynamic

fmn11:07:15

@fabrao I think if you have a pretty similar predicate like this (clojure.string/includes? (clojure.string/upper-case (:codigo %)) (clojure.string/upper-case filtro)) (taken from your example)

fabrao11:07:17

yes, the (:codigo %) will change depends on list of key fields

fabrao11:07:45

if I have [:codigo :nome] I want to generate #(or (clojure.string/includes? (clojure.string/upper-case (:codigo %)) (clojure.string/upper-case filtro))) (clojure.string/includes? (clojure.string/upper-case (:nome %)) (clojure.string/upper-case filtro)))

fmn11:07:53

You could just create something like:

(defn my-pred 
  [filtro k v]
  (clojure.string/includes? (clojure.string/upper-case (k %)) (clojure.string/uppercase filtro)))

;; use it like 

(filter #(or (my-pred filtro :codigo %) (my-pred filtro :my-key %) ) dados)

fmn11:07:48

Then I think you could create a function that check whether the map has the key you're looking for

fabrao11:07:45

Humm, I thougth it easier make dynamic predicate

fmn11:07:14

It is pretty easy, you can do it with cond

fabrao11:07:54

I think it will not work besides variable conditions for or operations

fmn12:07:49

@fabrao If the key is generated based on the map, it'll become shorter: (filter #(my-new-pred filtro %) dados)

mariuene12:07:38

Hi, just out of curiosity. I just found out about prefix-paths when requiring namespaces. So I'm wondering if there is any "catch all" way to require every namespace in a given prefix path?

fmn12:07:09

I don't think it exists, but even if it does I don't think it's a good way to require namespaces like that

mariuene12:07:28

yes, I fully agree, it's seams like a really bad practice to do that. I just wanted to know if it existed. 🙂

eraserhd14:07:44

Is there a library that can be used from the REPL to asynchronously reload code, and perhaps run tests (or call a hook), when files are saved to disk?

eraserhd14:07:28

I see that clojure.tools.namespace.repl/refresh has a hook, but it doesn't auto-load. Also, the hook doesn't receive loaded namespaces.

arrdem15:07:25

@eraserhd you could probably monkey something up from lein-auto's file watching machinery

arrdem15:07:12

I've used CIDER and emacs hooks to compile/load on save, never tried to integrate file watches into a bare repl.

eraserhd15:07:16

There's a Clojure file-watching library that seems nice enough... I'm just kinda surprised it hasn't been done. I mean, midje has it in it's test-runner, but midje has a large bundle of dependencies.

arrdem15:07:54

Ring's wrap-reload is probably the closest thing to a nod in this direction...

dpsutton16:07:40

i think zach wrote a java file watching library too

noisesmith17:07:34

I think in the clojure world, an unqualified "zach" means ztellman

noisesmith17:07:18

(we should have a "clojure community first name basis" FAQ)

dominicm17:07:23

I thought so too, but couldn't find his library, which is why I decided to check

dominicm18:07:16

ah, not a file watcher, but a java file reloader

dpsutton18:07:02

oh i thought it was triggered on java file changes

dominicm18:07:33

maybe it does automagically 🙂

dominicm18:07:24

it's interesting. In boot the watcher is disabled, so that's really a patch for the fact lein doesn't have one.

dominicm18:07:40

I think it sucks that lein doesn't have a file watcher, because it affects things like this.

dominicm18:07:54

Everything has it's own file watcher, e.g. virgil, figwheel, etc.

dominicm18:07:01

boot got this very right

arrdem19:07:14

Virgil is my single favorite Clojure tool besides CIDER+nREPL

arrdem19:07:27

Makes such a huge difference when developing anything with Java interop.

noisesmith16:07:52

iirc the ring wrap-reload works by comparing timestamps on files when requests come in, and reloading code before handline the request if there are recent changes

Ethan18:07:57

Hello, I was wondering which channel would be the best channel to talk about spec in

noisesmith18:07:34

for basic questions this channel or #beginners work, there's also #clojure-spec

Ethan18:07:45

thank you

jakemcc18:07:53

@eraserhd if you’re just trying to run clojure.test or expectations on change, there is https://github.com/jakemcc/lein-test-refresh . It has a few other features to get feedback faster as well. It isn’t in your repl though

eraserhd18:07:43

Unfortunately, the REPL thing is a requirement.

eraserhd19:07:48

Though the lein plugin appears to just run code in the project, except that it does (System/exit) when finished.

jakemcc20:07:50

Mind elaborating on why in a REPL? I’ve always preferred having things that autoreload on code change outside of a repl, since if you’re reloading properly (in my opinion) you’re losing any state that has built up.

bja18:07:54

is @alexmiller the right person to thank for clj providing a way of specifying a one-liner with dependencies? asking because this feature is awesome

Alex Miller (Clojure team)18:07:42

I implemented it, but it was someone else’s idea :)

bananadance 4
bja18:07:57

thank you then

bja18:07:13

makes sending quick code to others much more sane