Fork me on GitHub
Martynas M11:06:00

Hey. I have a question about logic programming in general and not about core.logic. Let's say I have an event stream and I accumulate state over time. If I think about the incoming event stream as string characters then I could write a state machine (regex) that would capture some kind of state about the inputs. What I think about is to make this state machine for the incoming stream and be able to somehow say what is the current "state" of the state machine. I don't know how it could work and don't know if it makes much sense to you. But maybe there could be a library that could handle this? I could write the matching and checking by hand but it would be way nicer to specify some constraints and then allow to 'work itself out'. I don't know what the end result could be. In my opinion maybe it could be some kind of events or something. But first let's see if anybody understands what I'm talking about.

Ben Sless15:06:19

There are state machine libraries, why not use them?

Martynas M15:06:00

Yes, this is what I thought about but I didn't know what to look for. I'm not yet sure how to use it. Is it something like this one?


I'm not sure what you are talking about. Do you want to validate an event stream? Or emit events in response to incoming events? Are you familiar with finite state machine and finite state transducers?

Martynas M07:06:03

Hey. I didn't even see that you replied because you replied to the main topic but alright. Also that means that the other commenter will also miss this message. I want to not only validate but also emit events according to my internal state and incoming events. Finite state machine is familiar to me (regexes?) but I would like to have multiple of those machines at the same time for different contexts. And they must not "overlap" based on some kind of criteria (regex that stops matching because it currently already matches a string that has 5 of the first same chars) and if it happens then it should produce a rejection. I'll try to look up "finite state transducers". But for now I like to think about it as a "saga pattern".

Martynas M08:06:13

I'm trying to figure out whether there could be a framework for this (obviously probably yes but then how hard is it to have one) or whether I'll need to write all my "state machines" by hand and accumulate state on my own :thinking_face:


Ah ok, lets see if a get this: You want your process to receive event, and transitions states of a state machine based on incoming events. Your question is: Is there a framework that provides a high level way to define the state machine, and handle transitions based on events I don't really know of such a framework. I have some half baked library somewhere that provides a DSL to generate finite state transducers, but it is not in a usable state. Generating a finite state machine from a DSL is not that hard BTW, could be a fun project. I'm not sure what you mean with 'they should not overlap'| The problem is kind of abstract, do you have can you give an explanation of a problem you want to solve with this approach?

Martynas M04:06:27

If a user locks a resource then transaction from a different user should fail until the first user unlocks. This is where a basic regex approach would lack because it would expect that the inputs would already be "separated between contexts". Probably it wouldn't be too useful to model only one state-machine but I'd have to have a large DSL for the whole system :thinking_face:


Formal methods, like TLA+, come to mind, these give a high level language that is compiled down to a finite state model, which can be used to reason about properties of the program. I think code generation is also possible, but not sure how usable the results are.


TLA+ is related to logic programming, it's based on temporal logic.


@U028ART884X: sounds like you might be grasping for a dataflow system!? I’ve seen many of these in clojure over the years… here’s one: