14 comments

[ 2.7 ms ] story [ 37.7 ms ] thread
Nice to see this passed around on Hacker News. I think the whole concept of lenses is super cool and useful, but suffered from the usual Haskellificiation problems of being presented in an unnecessarily convoluted way.

I think Accessors.jl has a quite nice and usable implementation of lenses, it's something I use a lot even in code where I'm working with a lot of mutable data because it's nice to localize and have exact control over what gets mutated and when (and I often find myself storing some pretty complex immutable data in more 'simple' mutable containers)

Was hoping this was data lenses, like cambria from ink&switch

https://www.inkandswitch.com/cambria/

Not sure how "A Lens allows to access or replace deeply nested parts of complicated objects." is any different from writing a function to do the same?

Julia curious, very little experience

Certain aspects of this me of the modf macro for Common Lisp:

https://github.com/smithzvk/modf

You use place syntax like what is used with incf or setf, denoting part of some complex object. But the modification is made to the corresponding part of a copy of the object, and the entire new object is returned.

I have to admit I don’t really understand the point of doing this instead of just obj.a = 2 or whatever.
Lenses also let you take interesting alternate perspectives on your data. You can have a lens that indexes into a bit of an integer, letting you get/set a boolean, for example.
Is this like setf in lisp?
In the simplest case, yes, but in general no, lenses are more general
Guys, What's you're opinion on Julia?

I am thinking of using it for data science work.

Any draw backs? or advantages I should know about?

Is Julia a general purpose programming language? I mean I did check the web site which contains a "General Purpose" section, yet the articles seem to center around "scientific applications".
it is a general purpose language, but it's happy place is math. Most languages (except Fortan Matlab and R) are very much oriented towards writing web servers/compilers etc, so Julia gets lots of wins in science just by virtue of caring more about math.

Julia is a completely reasonable general purpose language, but getting people to switch generally requires a ~10x better experience, and Julia can't deliver that for general purpose applications.

oh... i thought this was going to be about simulating optical lenses and lens physics.
Is set basically syntactic sugar for deepcopying a struct, mutating the specified field, and then returning that deepcopy? Seems like it could be quite slow.
Now if only the Julia community didn't keep insisting on ligatures and impossible-to-look-up Unicode symbols - the hollow semicolon for compose right to left, seriously?
Can this be used for Read-Copy-Update (RCU) ?