Fork me on GitHub
#clojure
<
2019-06-17
>
pinkfrog05:06:44

i want to define a function that given an argument, it returns true when as long as one of the four functions f1-f4 returns true?

pinkfrog05:06:52

how to write it in a concise way?

aisamu05:06:22

You might want to check every-pred for inspiration (if you're only interested in the answer, check some-fn)

pinkfrog05:06:43

yes. what’ i need is some-pref

pinkfrog06:06:15

clojure can be so easily mis-written because if you don’t know that function.

theeternalpulse06:06:26

there's my personal favorite function juxt

theeternalpulse06:06:52

((juxt nil? empty?) '()) => [false true]

aisamu06:06:17

Yup, hard to find out about what you don't know yet. This is a very useful resource (given 4 fn-like args, what could I use to get another function back?): https://re-find.it/?args=fn%3F%20fn%3F%20fn%3F%20fn%3F&amp;ret=fn%3F&amp;more=true)

theeternalpulse06:06:27

it's very terse, to the point of not making sense but it takes a series of functions, and returns a function, that when applied to an argument(s) returns a vector of the results of those functions applied to the arg

pinkfrog07:06:54

@aisamu for example, i want to find all the agent related functions

pinkfrog07:06:59

how can i achieve that?

andy.fingerhut08:06:53

The Clojure cheatsheet does not include all Clojure functions, but definitely all of the most commonly used ones, and some of the not-so-commonly used ones. They have been separated into categories based upon their use and capabilities. https://clojure.org/api/cheatsheet If you click on the "Source repo" link near the top you can find other variants of the cheatsheet, e.g. some of them have what I consider nicer-looking tooltips when you hover the cursor over a function name, showing the doc string for the function. Also a name search box near the top.

ivana08:06:48

Coming from Haskell world, I often surprised, why there are so many unnecessary functions in core - i.e. remove as duplicate of filter (not), or keep, or above example ((juxt nil? empty?) '()) as duplicate of (mapv #(% '()) [nil? empty?])

andy.fingerhut08:06:10

I suspect they were added for convenience of use.

andy.fingerhut08:06:52

Out of curiosity, have you found no unnecessary functions in Haskell, or simply fewer than in Clojure?

ivana08:06:01

Looks like, but imho there should be a balance between convenience of use and hardness to remember many functions

andy.fingerhut08:06:38

Also, while ((juxt nil? empty?) '()) can be considered as a duplicate of (mapv #(% '()) [nil? empty?]), note that (juxt nil? empty?) is a function in its own right that can be passed to other functions, returned from a function as a value, etc., where your second expression doesn't make such a function easily separable in that way.

ivana08:06:57

No problem, if you work only with one blab, you can remember all its personal functions. But I think more uniq things - more comlexity. And there is not a big problem to wrote (fn [x] (mapv #(% x) [nil? empty?]))

bronsa09:06:17

@ivana remember that clojure is not curried like haskell, so the existence of remove/juxt is also convinient for higher order use

👍 4
bronsa09:06:23

consider (swap! a remove pos?)

hkjels11:06:20

A library should do one thing well ex. routing, ui or state A framework will have a bunch of batteries, usually routing, ui and state

👍 8
lukasz13:06:41

other way to think about it: framework will impose certain kind of structure in your application, library will not (usually)

joaohgomes15:06:10

Hey guys, I’m trying to disable assertions checks(pre/post hooks) for production code, but could not figure out a way to do so. It seems to be a setting for the Clojure compiler, not having effect in runtime. Wondering what is the proper way to set *assert* to false before code is compiled. Tried many things and nothing seems to be working. We’ll bundle the code as an uberjar.

ghadi15:06:59

@joaohgomes what are you using to compile?

ghadi15:06:02

if it's ordinary clojure code, you can (set! *assert* false) before calling compile, if it's leiningen: https://github.com/technomancy/leiningen/blob/87a6af9a12d5c479bfbb51f50b85c3fa4c2650a0/sample.project.clj#L286

Suni Masuno15:06:33

leiningen isn't the most common way to compile?

joaohgomes15:06:36

We are packing using: clojure -A:pack mach.pack.alpha.capsule ./target/my-app-api.jar -e build-dir --application-id my-app-api --application-version "$(git describe --tags)" -m my-app.main

ghadi15:06:26

can't help you there, you need to run some code before pack starts compiling

ghadi15:06:38

perhaps ask / file an issue

bronsa15:06:00

(set! *assert* false) in user.clj perharps

ghadi15:06:45

(Possibly better behavior is clojure to initialize *assert* to the JVM assertion status)

joaohgomes15:06:24

We are not loading user.clj in prod code. We tried (set! assert false) as the first line of the main file. Apparently, the require will load and compile before *assert* could be se to true false

bronsa15:06:01

not in prod code, in the classpath of that clojure invocation

ghadi15:06:16

need assert to be off before pack runs compile

ghadi15:06:42

you can always turn them off at the jvm level -da

ghadi15:06:14

no that won't work, never mind

Drew Verlee18:06:58

Whats the current state of the art in terms of Repl driven development? For example, last i checked, it was easier to just restart your repl when you added a new dep. Is that still the case?

dpsutton18:06:47

i see conflicting goals between "state of the art" and "easier". I always just restart my repl as I don't often add new things and its easiest for me to know i'm back in a clean state. I think deps.edn has a branch with this feature and nrepl has teased that its coming? possibly already landed. nrepl-refactor has had this for a while and I believe it is working with the current CIDER

Drew Verlee18:06:44

I suppose don't see this as conflicting with anything. I just want to add some functions to my system. Reloading everything up to that point should ideally result in the same state. I suppose it because i'm not relying on any outside state. I'll take a look at nrepl-refactor 🙂

tavistock19:06:17

probably hasnt landed yet but theres this http://insideclojure.org/2018/05/04/add-lib/

Suni Masuno19:06:54

Any guides on laying out the namespaces in a green field project?

Suni Masuno20:06:44

I more meant how to divide the logic within an application into namespaces. How are people architecting solutions?

seancorfield20:06:27

I don't think there's really any "standard" way in the community.

Suni Masuno20:06:54

Are there positions and ideologies?

seancorfield20:06:18

Some people like a fairly flat structure, with broad namespaces, some prefer a more deeply nested structure with more focused, shorter namespaces.

seancorfield20:06:06

I think probably the only common thread is to separate different concerns, e.g., persistence from business logic, and to try to organize via "domain" concepts where possible.

Suni Masuno20:06:16

Having recently bounced through Redux and Elm I was wondering if there were any architectural ideologues floating around.

seancorfield20:06:59

Clojure source 279 files 67068 total loc,
    3118 fns, 641 of which are private,
    423 vars, 29 macros, 60 atoms,
    580 specs, 21 function specs.
Clojure tests 308 files 19301 total loc,
    4 specs, 1 function specs.
So we have over 85k lines of Clojure with close to 300 source namespaces (and just over 300 test namespaces) and our source code averages about 200 lines per ns with our longest one being 2,000 lines (and only a handful are 1,000+).

👍 4
seancorfield20:06:34

No, Clojure is not very prescriptive about architecture, beyond trying to keep side-effects at the edges.

Suni Masuno20:06:47

Those numbers are... awesome

seancorfield20:06:44

We've been developing this since 2011 and it powers the back end of all our dating sites (about 40 or so of them), as well as a few dedicated Clojure web apps.

seancorfield20:06:14

Our approach to namespace organization has evolved over that time too, both in naming and actual organization.

seancorfield20:06:44

We started broad and flat and we've gradually moved into narrower, more focused namespaces as we've refactored old code and added new code.

seancorfield20:06:34

@drewverlee FWIW, I just restart my REBL/Socket REPL combo if I change/add new dependencies. That said, I don't do that very often so my REBL instance tends to stay up and running for days, sometimes even weeks!

seancorfield20:06:20

(last time I restarted my REBL instance was 10:18 am June 13th, when we made a pass over our dependencies to update a bunch of them -- so "only" four days so far)

Drew Verlee20:06:45

I think for most projects it tends to be the case that you dont add new deps very often. I was trying to use clojure in a more datascience type setting where i find that I want to try new libs relatively often (every 20 minutes or so). In order to find the one that fits my needs. Having to restart my repl 3 or 4 times in this setting becomes something of a creative drag.

jumar20:06:09

with Cider I used to use cljr-add-project-dependency which worked great but broke at some point. I don't know if it's working in the latest version but I still miss it every now and then.

seancorfield20:06:55

@drewverlee Agreed, and that's why I have an alias in my .clojure/deps.edn file that brings in the add-lib branch of tools.deps so I can start a REPL dedicated to exploration when I need to, and use add-lib to try out various things.

Drew Verlee20:06:23

🙂 im using that deps file right now.

Drew Verlee22:06:43

@U04V70XH6 i'm trying to use the setup you describe in the helpful youtube video you made about 2 months back. Everything is working except when i eval forms in atom via chlorine there not sent to REBL. forms evaled directly through the repl in started via the clj tool are though. Any ideas why this might be.

seancorfield22:06:40

@drewverlee Sounds like you're using the eval block commands instead of the inspect block commands

seancorfield22:06:36

If you look in my keymap https://github.com/seancorfield/atom-chlorine-setup/blob/master/keymap.cson#L37 I only bind to the inspect commands -- because I'm always running REBL (and Clojure 1.10.1).

seancorfield22:06:36

If you want to use Chlorine without REBL or on 1.9, you have to use the eval block commands (not the inspect block commands), so it sort of depends where you are.

Drew Verlee22:06:03

your first guess was right. ty!

seancorfield22:06:36

I used to have the inspect variants bound to ctl-, i and ctl-, I but once I got into the habit of always using REBL, it was easier to just bind ctl-, b and ctl-, B since those were easier to remember (and I'd been using them for months, before I introduced REBL).

dpsutton20:06:48

ah yeah i can see that being a pain

josh_tackett20:06:50

Anyone know a good SFTP library?

josh_tackett20:06:09

I am currently attempting with this one: https://github.com/iSource/clj-sftp

noisesmith20:06:47

that wrapper is very thin, a good place to start would be to attempt the auth / connection code in with-connection manually and see what might be failing

josh_tackett20:06:21

but getting connection timeout

noisesmith21:06:37

there's an SO post for this specific error in the lib that clj-sftp uses

noisesmith21:06:03

good example of a thin wrapper sometimes being worse than no wrapper at all

noisesmith21:06:52

if you used the underlying lib, it would be exposed