Fork me on GitHub

I made an #http-kit channel


Does anyone have experience with ? If so, could you share that and what you think about it?


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


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


Great, thanks for sharing.

David Pham16:09:23

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?


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.


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.


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

David Pham05:09:57

Thank a lot!


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


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


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.


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.

🎉 3
☝️ 3
eccentric J22:09:52

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.

eccentric J22:09:00

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.

eccentric J22:09:47

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.

eccentric J22:09:11

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

eccentric J23:09:43

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


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.

eccentric J12:09:33

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.


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


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

Jeff Evans19:09:56

Can someone point me to how to actually search at ? I only seem to be able to click on specific channels, then dates

Lennart Buit19:09:28

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

Jeff Evans19:09:51

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

Jeff Evans19:09:54

thanks for the reminder


@U0183EZCD0D You can also use the Zulip archive. E.g. to search in the clojure-spec channel:

👍 3
Jeff Evans20:09:57

thanks for the suggestion, @U04V15CAJ!


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


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


"delta y is inversely proportional to y"


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


you could do something like y = y * 0.8


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.


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


where constant can be a negative number in my formula.


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


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


Is damping in any way related to 'force'?


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


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


negative k because its a force applied in the opposite direction


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.


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


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?


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


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


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


right, yeah. thats another reasonable way to do that


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


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


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


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?


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


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

✔️ 3

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


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.


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'


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


so... that sounds kind of like cosine


its cosine-ish


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


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

👍 3

yeah this actually might be exactly what I need


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


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


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


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


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


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


But e is pretty cool.


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


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


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


Are you trying to achieve spring-like oscillating motion?


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


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


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.