Matt's Blog: while { coding }
    Back to Matt's Homepage   |   Hire Matt

Introduction To Wheeler, Part 3: Transitions and Mutual Dispatch

Hey, quick, watch this video before you read any further. It’s under 2 minutes long and it is *fascinating*.

That video is about how cell membranes work. Did you notice how proteins, enzymes, etc. can only pass through the cell membrane if they are the right shape (and flavor)? That’s how values trigger transitions in Wheeler.

Transitions

If categories are the most minimal representation of state, then transitions are the most minimal representation of action. Transitions are how computation happens in Wheeler. After all, organizing data is only half the battle with programming. Once you have the data in the form you want, you have to actually do something.

You can think of transitions as being very much like an event handler. You define a transition to trigger when an interaction between one or more categories happens.

Since Wheeler is still a work in progress, transitions are not yet native. Instead, transitions are created in Python, the language Wheeler is built on.

Remember our Hello example?

Here’s the transition defined for it in Python:

def printer(category):
	for item in category:
		print item.name[1:-1],
	print
	return []

ROOT.create('print').add_handler( STRING, printer )

(I’ve omitted some unimportant details for clarity.)

What you might be able to suss out here is that there is a ROOT category that all categories live within, and I’ve created a “print” category within that. In addition, I’ve added a transition (with add_handler) which knows to watch for interactions with items in the string category. If the transition finds an interaction that matches, it executes the printer() function, which simply calls Python’s ‘print’ function.

Mutual Dispatch

When more than one transition is triggered by an expression, the transitions all execute AND – at least in concept – they all execute *at the same time*.

This is very much like the real world. If two objects collide you don’t say that one or the other of them collided first. The collision is mutual and simultaneous. In that same way, when categories interact, the interaction is mutual and simultaneous.

Here’s the final snippet of Wheeler for this introduction:

In case it’s not clear what is going on here, we have some numbers, which are in the category ‘number’, some text in the category ’string’, and some other categories (’print’, ‘+’) which give it all meaning with transitions. One transition knows to add all of the numbers in the expression when the plus sign is present. Another transition knows to print all of the strings in the expression to stdout when the ‘print’ category is present.

When presented with this jumble of categories, Wheeler figures out what to do based on the criteria of the transitions. This effectively creates a typed-dispatch mechanism. I call this simultaneous, polymorphic behavior “Mutual Dispatch”.

That sums up Wheeler as currently implemented.

There’s still a lot of work to be done. I’ve covered what Wheeler is currently capable of. There are other planned features that I didn’t cover and hope to implement soon. I will provide more info here as new features are added.

I hope you find it as oddly fascinating as I do! Feedback is not just requested, it is begged for. I also strongly encourage you to grab the code, play, and contribute.

(Thanks to Westside Programmers and #pdxfunc for letting me present on Wheeler a few times over the past year. Having the chance to present and receive feedback has firmed up the concepts in my mind and made them easier to distill into this introduction.)