off-topic

https://github.com/clojurians/community-development/blob/master/Code-of-Conduct.md Clojurians Slack Community Code of Conduct. Searchable message archives are at https://clojurians-log.clojureverse.org/
2020-09-10T00:29:49.118900Z

The typical formula here is test lib + http lib. There isn't a reason for those to be bundled.

borkdude 2020-09-10T10:05:28.122800Z

I made an #http-kit channel

jumar 2020-09-10T12:38:29.123400Z

Does anyone have experience with https://zio.dev/ ? If so, could you share that and what you think about it?

borkdude 2020-09-10T13:27:49.123700Z

TIL: https://www.darlinghq.org/

2020-09-10T16:50:23.128Z

Hello, everyone :). I wonder how the knowledge and experience acquired writing and designing Clojure programs can be leveraged in other languages? I really appreciate the default idioms if Clojure and wondered which one where easily transported in other languages, such as python?

emccue 2020-09-12T18:44:41.236700Z

In python, the dataclasses module has a decorator you can use with the frozen=True argument to make immutable objects with a copy method a'la java or scala immutable objects

emccue 2020-09-12T18:45:08.236900Z

you can also use the pyrsistent library for persistent lists, maps, and sets

2020-09-10T17:01:14.130700Z

I used to have a day job in PHP and I tried to apply some Clojure principles where I could. You can, for example, have a class that has basically no data fields and all static methods, and that works like a Clojure namespace, assuming the methods use a lot of generic data types like arrays and hash maps. And you can avoid using inheritance and global variables.

2020-09-10T17:01:54.131400Z

I have no experience using immutable data structures in production code in languages other than Clojure, but Python already has immutable tuples and frozen sets. There is no frozen dict, but I have written tiny-to-medium sized Python programs that used mutable dicts instead of creating custom classes for data before, in the Clojure style of 'just use maps' for collections.

2020-09-10T17:02:01.131800Z

The down side is if you’re on a team and they want to write plain vanilla PHP/Python/etc, and they look at your code and go bleh.

☝️ 1
🎉 1
2020-09-11T11:40:51.193300Z

I did lunch-n-learns, which were well-received at the time but produced few if any changes in the way everyone else was coding. Eventually I moved on to another employer and repeated the cycle until I finally got a full-time Clojure position.

2020-09-11T12:55:33.198400Z

Nice! I tried some demos and pairing together. They tried to apply them but I don't think they entirely understood the point nor did they put any extra effort into learning. Eventually those devs left onto bigger and greater things, and the CTO stepped down where I took on some aspects of the role. From there I was able to hire clojure devs and we began using it in our tooling and backend. I did keep in touch with one former dev and it turns out he started using a curried FP library, less OOP, and now even adopted RxJS after resisting it when we first started working with it.

2020-09-11T12:57:20.199300Z

“…dragged kicking and screaming into the Century of the Fruitbat,” as Terry Pratchett used to say.

2020-09-11T13:35:43.202100Z

Too true!

2020-09-10T17:02:50.131900Z

Several languages have immutable persistent collection libraries for them, some also inspired by Phil Bagwell's work and others, and in some cases directly inspired by Clojure's implementations of them.

2020-09-10T17:03:28.132100Z

e.g. JavaScript immutable.js, Scala <something>, and I suspect probably dozens of others.

2020-09-10T17:07:58.132700Z

The main thing Clojure did for my PHP programming was teach me a new way of looking at problems and how to solve them.

2020-09-10T18:34:41.133800Z

ZIO is an effect system coupled to a dependency injector. Both ideas are great, but unifying them in a single abstraction is questionable IMO

2020-09-10T18:35:58.134Z

I've not used it in anger but from what I've heard it's solid tech

2020-09-10T19:56:56.134800Z

Can someone point me to how to actually search at https://clojurians-log.clojureverse.org/ ? I only seem to be able to click on specific channels, then dates

2020-09-10T19:58:28.134900Z

you can google search on a specific site (general tip)

2020-09-10T19:58:51.135100Z

yeah I just played with that, basically site: operator, kind of works

2020-09-10T19:58:54.135300Z

thanks for the reminder

borkdude 2020-09-10T19:59:32.135500Z

@jeffrey.wayne.evans You can also use the Zulip archive. E.g. to search in the clojure-spec channel: https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/clojure-spec

👍 1
2020-09-10T20:10:57.135800Z

thanks for the suggestion, @borkdude!

2020-09-10T22:15:52.136100Z

I know the feeling. I was learning FP through our JS codebase and the other devs didn’t like it because it wasn’t as easy even though it made a lot of systems way simpler, deterministic, and scalable. They sometimes would give it a try but as soon as any obstacle was encountered they would bow out to an OOP solution often introducing mutable state.

2020-09-10T22:19:00.136300Z

It was hard to stress that it works best when our system uses FP as a default to reduce stateful complexity as much as possible instead of just using it at the edges when we could slow down to try and learn it.

2020-09-10T22:31:47.136500Z

Another challenge was trying to express that it isn’t just about FP as a coding style, it was about having a common set of principles that guides our entire design process for interfaces and functionality.

2020-09-10T22:32:11.136700Z

Oops I’m quite chatty today. Didn’t mean to hijack your convo, I guess your post took me back to the dark times.

idiomancy 2020-09-10T22:38:47.138200Z

So, I always trip over modeling this kind of problem and I'm wondering if anyone has any advice. What I'm trying to express is that y should be modified inversely to the magnitude of y. so like, ideally as y approaches 0, the change in y is reduced. but of course, when y is less than one, 1/y > y

idiomancy 2020-09-10T22:38:56.138700Z

what is the operation I'm actually thinking of here?

idiomancy 2020-09-10T22:40:12.139100Z

"delta y is inversely proportional to y"

2020-09-10T22:40:30.139800Z

If smaller y means smaller change, then "delta y is proportional to y" is closer to that meaning

phronmophobic 2020-09-10T22:41:19.141Z

you could do something like y = y * 0.8

2020-09-10T22:41:50.142400Z

new_y = old_y + constant * old_y is the only formula that strictly follows the interpretation of "delta y is proportional to y", at least according to the meaning of "proportional" that I know.

idiomancy 2020-09-10T22:41:57.142700Z

err, right. I have this example kind of backwards, because im actually applying a counter velocity, so I want the size of that counter velocity to be greater the greater y is

2020-09-10T22:42:38.143300Z

where constant can be a negative number in my formula.

phronmophobic 2020-09-10T22:43:19.144200Z

y = y * k, where k is some constant which is how friction works

phronmophobic 2020-09-10T22:43:33.144600Z

I think

idiomancy 2020-09-10T22:44:48.146400Z

err, wait, my mental model is definitely screwed up, so I'll just explain the thing. the thing is a spring. I want the damping of the spring to be less when the spring is in an extended position

2020-09-10T22:45:22.147400Z

Is damping in any way related to 'force'?

idiomancy 2020-09-10T22:45:24.147500Z

so a regular spring dampening would be y * -k * deltaTime

idiomancy 2020-09-10T22:45:46.148300Z

where y is the displacement, or current degree of extension of the spring

idiomancy 2020-09-10T22:45:59.148800Z

negative k because its a force applied in the opposite direction

2020-09-10T22:46:24.149500Z

The ideal spring law I learned in physics was that many springs exert a force that is a constant times the distance that the spring is away from its rest position, which is 0 at its rest position, positive in one direction, and negative in the other, so the force is always directed back towards rest position.

idiomancy 2020-09-10T22:46:56.150Z

right, which is hooke's law, which is the formula I just wrote

2020-09-10T22:47:35.151600Z

except Hooke's law relates force and position, and has no deltaTime in it. But I am guessing that you are doing some kind of discrete time simulation that approximates continuous time?

idiomancy 2020-09-10T22:48:24.152600Z

yeah but hooke's law doesn't have to deal with a nondeterministic timestep in between applications of the formula lol

idiomancy 2020-09-10T22:49:38.154900Z

this is correcting for the fact that I'm in a discrete nondeterministic environment and I calculate this factor in discrete steps. I need the dampening to increase as the spring approaches its rest position, because otherwise the spring overcorrects and picks up too much acceleration and never comes to rest

2020-09-10T22:49:57.155300Z

Many discrete time simulations of physical systems maintain position and velocity of objects at all times of interest, calculate forces, add up the net force on each object, then do "new_velocity = old_velocity + F / object_mass", then take the velocity vector times delta_t to get an offset that the object moves during delta_t

idiomancy 2020-09-10T22:50:30.155700Z

right, yeah. thats another reasonable way to do that

2020-09-10T22:50:57.156600Z

I might have that new_velocity formula off a bit there .... been a while.

2020-09-10T22:51:41.157600Z

F/m is acceleration, and perhaps that needs to be multipled by delta_t, also, to put it in units of velocity.

idiomancy 2020-09-10T22:52:18.158300Z

well, anyway I appreciate the input. the deltaTime business isnt where the confusion here lies. thats just a constant that gets applied to any force that occurs in a frame

2020-09-10T22:53:13.159100Z

When you say nondeterministic time step, are you saying that you aren't simply making delta_t a constant in your simulation, but that it is expected to change from one discrete step to the next, for some reason?

phronmophobic 2020-09-10T22:54:14.160700Z

in theory, you get to pick the deltaTime for each step of the simulation, but if you're trying to display the simulation in realtime, your deltaTime may vary to match your frame rate

2020-09-10T22:55:18.162100Z

Oh, if by dampening you mean friction, then yeah, that is one of the forces involved, completely independent of the spring restoring force, and many objects have an approximate friction force that is "- c * velocity_vector", where c is called the dynamic coefficient of friction, IIRC

✔️ 1
2020-09-10T22:55:46.162700Z

So you would want to calculate both of those forces at each time step, and add them, before calculating the new velocity.

2020-09-10T22:56:52.163300Z

but note that the friction force is not proportional to the current offset from the rest position, it is proportional to the current velocity vector.

2020-09-10T22:58:20.164200Z

So the friction force is actually greatest when the object is moving fastest, which in an oscillating spring is going to be when the offset from rest position is 0, i.e. the object zips by the rest position faster than at any other time during its movement, in a single 'sweep'

2020-09-10T23:16:43.164300Z

Though I’m curious, did you try demos, pairing and tutorials to win them over? Or did they just encounter it in code review?

idiomancy 2020-09-10T23:20:17.165300Z

Basically what it comes down to is that I want a function that takes some input x and produces a y between 0 and 1, where y is larger the closer x is to 0

idiomancy 2020-09-10T23:28:41.167100Z

so... that sounds kind of like cosine

idiomancy 2020-09-10T23:29:23.168200Z

its cosine-ish

idiomancy 2020-09-10T23:31:28.168700Z

if my input range was between 0 and pi, then that would be true for cosine

2020-09-10T23:32:19.169200Z

There are an unlimited number of such functions, if you don't need the damping effect to behave like friction.

👍 1
2020-09-10T23:33:08.170100Z

e ^ (-x^2)

idiomancy 2020-09-10T23:34:05.170700Z

oh wow

chucklehead 2020-09-10T23:34:07.170900Z

can you not just do the absolute value of the cosine?

idiomancy 2020-09-10T23:34:30.171600Z

yeah this actually might be exactly what I need

2020-09-10T23:34:34.171900Z

That would decrease up to pi, then increase again, which may not be what he's looking for

chucklehead 2020-09-10T23:34:55.172700Z

ah, yeah

2020-09-10T23:34:58.172800Z

if one knew the maximum distance from the rest point, you could scale that distance so it was in the range [-pi, pi] and use cosine

idiomancy 2020-09-10T23:35:31.173500Z

I think e ^ (-x^2) is perfect, actually

idiomancy 2020-09-10T23:35:56.174100Z

I can just multiply x by another constant to customize for the shape I'm after

idiomancy 2020-09-10T23:37:46.174400Z

huh, man...

2020-09-10T23:38:28.175400Z

The base can be anything, e.g. 50 ^ (-x^2), which is just another way of scaling the shape of the curve.

2020-09-10T23:38:45.175700Z

But e is pretty cool.

idiomancy 2020-09-10T23:39:03.176100Z

oh its not a special property of e ? lol, shows you what I know

2020-09-10T23:39:41.176800Z

Any positive real number raised to the power 0 equals 1, so any positive number works there

idiomancy 2020-09-10T23:42:29.179100Z

man thats awesome. Im really, really happy to have (I'll just sub in k) k^(-x^2) pattern available. I feel like I run into this problem a lot

2020-09-10T23:43:19.179600Z

Are you trying to achieve spring-like oscillating motion?

idiomancy 2020-09-10T23:46:26.181200Z

yeah, a mass that, when disturbed, oscillates back and forth, where that oscillation decays at some rate I control

idiomancy 2020-09-10T23:47:16.182400Z

but with the additional constraint that I can only work by setting the forces acting on them, not their positions directly

2020-09-10T23:48:11.183800Z

Because if the simulation uses a step like next_y = (e^(-cur_y^2)) * cur_y, where y is the offset from the rest position, and you repeat that, it will not ever oscillate around the 'rest position'. If it starts out with cur_y = 10, say, then the next values of y will just get smaller and smaller, but always positive, and slow down the closer it gets to 0.