Fork me on GitHub
#off-topic
<
2018-07-21
>
_rj_r_03:07:45

anyone here have any experience with systemd timer/service on Arch?

benzap17:07:04

So i've started developing a scripting language closely tied to clojure data structures, and i've kind of hit a roadblock. In the language, I want to support indexing facilities similar to languages like javascript, python, and lua while maintaining the persistent data structures. However! I also want to include metaprogramming facilities to overload this functionality. This unfortunately makes things much more complicated. For example, something like: x = {:a {:b {:c 42}} could be accessed like so: x.a.b.c, which could then also be assigned to in a similar fashion: x.a.b.c = 43. This would then support overloading these facilities through prototype-based metafunctions. ie. setmeta(x {__index (function (this key) return this[key] end)}) The problem is nested associations to inner data. I'm assuming that languages like python, lua, and javascript depend on referencing to simplify the resolution, but I can't seem to wrap my head around how I could go about supporting the same functionality using persistent data structures that are each immutable. So i'm looking for suggestions on how I might go about supporting this, or if it's even possible? I was thinking of adopting some sort of navigator system in order to tag the hashmaps which could be hidden behind the scenes. Another approach would be to somehow adapt the clojure types into weak referenced types, but I feel like this would be a lot of work for not much gain.

benzap17:07:16

Another possibility is to forget the association functionality, and adopt more of the clojure approach

benzap17:07:42

ie. assoc-in(x [:a :b :c] 43)

benzap17:07:05

I think indexing could still easily be supported, the problem really seems to be association

benzap17:07:52

but this would tie into indexing, since I feel like i'd have to maintain some sort of navigator when progressing through the data structure in order to effectively re-associate a variable

jonahbenton17:07:23

once you change something deep in a data structure, the root has also therefore changed

benzap17:07:08

Within clojure though, right? I manage my own state machine for the language

jonahbenton17:07:15

so what are the semantics of =

benzap17:07:51

= is for association

benzap17:07:15

so to associate x to 42, x = 42

benzap17:07:46

i'll just post the github repo, things are still in the early stages so certain semantics could change

jonahbenton17:07:28

if you have x = {:a {:b {:c 42}}, then y = x, then x.a.b.c = 43, what does y have?

benzap17:07:29

so far, I still need to implement the data accessor and getter stuff, metamethods, and module

benzap17:07:34

y will store x, ie. (= x y), however, I was hoping that when I change y, it would not be a reference to x

benzap17:07:47

namely: `x = {:a 42} y = x y.a = 43 print x == y ;; false`

benzap17:07:28

but a nested association becomes difficult to write a metamethod for overloading

benzap17:07:58

I had some ideas, but it would be less expressive. For example, how would I deal with something like x.y.getInstance().z = 43 ?

benzap17:07:14

it would be impossible with persistent structures, unless there's something i'm missing

benzap17:07:22

referencing makes this dead simple

jonahbenton17:07:50

hmm, what functionality do you mean with "weak referencing"? these issues are about resolution, but weak references are really specifically about gc, not the broader spectrum of resolution.

jonahbenton17:07:12

do you know the spectre library?

benzap17:07:12

I might be using the wrong terminology

benzap17:07:23

Yeah, I know about it

jonahbenton17:07:26

yeah- i don't want to get hung up on it

benzap17:07:27

It was something i've considered

jonahbenton17:07:03

it sounds like there are questions about semantics- like, are there immutability semantics, or copy on write semantics

benzap17:07:47

so in python, when you create a dict, and I associate x = {}, and then say y = x; y["a"] = 1, both x and y still store a reference to the same data structure, right?

benzap17:07:55

Yeah, I want them to be immutable

benzap17:07:03

but they aren't...

benzap17:07:16

ah yes, copy on write

jonahbenton17:07:23

yes, python not immutable

benzap17:07:38

so if I say x = {}, and y = x, manipulating x will not affect y. There is no relationship between them at that point

jonahbenton17:07:23

yup, got it. so a copy on write scripting language

benzap17:07:04

I could definitely do this without using the association techniques they use in lua, python, javascript

jonahbenton17:07:09

yes- there is a valuetypes vs referencetypes distinction there

benzap17:07:56

I was hoping to play closer to a scripting language that acts like lua, so it's possible that i'll have to pass around references instead. I just can't imagine that being straightforward lol

jonahbenton18:07:06

well, the thing is that some of the difficulties you're referring to are optimizations. the simplest thing is that when you perform assignment (or association), to just make a copy

jonahbenton18:07:12

copy on write is an optimization allowing for lazily sharing the same value

benzap18:07:05

This might be an implementation problem on my part, since I have no way of referencing some deeply nested cases

benzap18:07:21

ex. the x.y.getInstance().z example

benzap18:07:44

how do I assoc-in in that case?

benzap18:07:16

I need to resolve the navigation in some way

benzap18:07:44

It requires quite a bit of semantic analysis

benzap18:07:19

However, if I just adopted a reference model of doing things. I could evaluate the chain on the left side to obtain the reference, and associate directly

benzap18:07:34

It wouldn't require any navigation resolution

benzap18:07:09

It's possible i'm thinking about this too hard

jonahbenton18:07:49

well- these concerns are only issues if you have more than one thing pointing to the same data structure/resolution root

jonahbenton18:07:02

and/or permit concurrent access

benzap18:07:20

yes, but only if I value those semantics. I don't mind if x and y did in fact share the reference. I'm working within the constraints of how clojure handles these types

benzap18:07:11

In fact, if someone had a library that implemented the clojure data structures with referencing in that manner, i'd probably jump on it and use that instead haha

benzap18:07:24

i'm not concerned about supporting concurrency

jonahbenton18:07:39

hmm, i don't follow- doesn't spectre do exactly this thing? allow for function application to deeply nested elements of a data structure?

jonahbenton18:07:31

giving you back the data structure following the results of that application?

benzap18:07:01

Ya, it is something I should consider

benzap18:07:11

maybe I should start studying spectre 🙂

benzap18:07:34

My only other concern

benzap18:07:54

I need to look over the source code of spectre to see if it uses eval

benzap18:07:09

I'm hoping to make a native-image of my scripting language in the future

benzap18:07:27

so if I could include spectre, I just hope it doesn't cause issues

benzap18:07:20

An alternative would be to use zippers

jonahbenton18:07:09

yes- spectre is basically more ergonomic and capable zippers. to a first approximation, it might be interesting to do a translation of your syntax into spectre navigation, see if there is alignment. i would think that eval would not be needed, but don't know. it would be nice to have a fast starting copy on write scripting language, can't think of one in that space

benzap18:07:48

Alright, spectre it is, I think the method call resolution wouldn't be an issue either since it could also return it's own separate navigator. I'll look into maybe tacking on additional navigation data when I pass around data. A copy on write scripting language would be interesting if it works out lol

jonahbenton18:07:06

sounds cool, good luck!

benzap20:07:07

So I just thought about it some more, and I am overcomplicating it. The concept of a call on the left side of the association doesn't make sense, since you would do that if you were returning a 'reference' Since i'm never returning references, and i'm always doing copy-on-write, it doesn't make sense, so I simply won't support it.

jonahbenton20:07:38

gotcha, though it is an interesting use case- a syntax that supports dynamic navigation along with nested modification. it seems like it doesn't necessarily have to imply reference semantics- if there is no other way to use the root thing under which the navigation is taking place- e.g. if there is no concurrency, and prior assignments/associations to the root thing are already decoupled from it (for lack of a better term)- you don't lose the copy-on-writeness. each statement basically takes the world and creates a new world. anyway- it's your language, you can just decide on the semantics and on the syntax which most pleasingly gets there. 🙂

benzap21:07:27

Yeah, i'm still exploring the idea of spectre, it would be interesting to include it's functionality as a first-class feature with it's own syntax sugar

jonahbenton17:07:09

will go into thread