Event Driven Programming is a philosophy where a program commits itself to running forever, waiting for things to happen, and then handling them. An “event” then is defined as “something which has to be handled”.
But let us start with the idea of “things that happen”. Most of the time, a program like EPIC sits quietly, sleeping. EPIC tells the operating system “wake me up when any of these things occur”. These are the kinds of things EPIC wakes up for
Every time EPIC is awaken from sleep, it is because an Event has occurred. EPIC is asleep at all times it is not handling an Event. This process of going to sleep, being woken up, handling an event, and then going back to sleep, is called an “event loop” or a “looper”. EPIC's core operation is as an event looper.
The simplest thing that has to be “handled” are messages that come from people on irc. If someone sends you a msg, that message comes in from the IRC server. EPIC determines that you have receivced a new msg and needs to display it on your screen. Therefore, displaying a msg to your screen is an example of an “event”. Inside EPIC, this is called a “MSG” event.
EPIC will ordinarily display a MSG event to your screen. But you may not like how EPIC formats the display of the event, and you want to do it your own way.
The fundamental operating principle of EPIC is that
For most events, the default behavior is fine, and you don't want to change it. It's for those events that you do want to change the default behavior, you need a way to provide your intentions to EPIC.
The on command is how you register an event handler with EPIC. You must know the “type” of the event, you must know the “pattern” of the event, and you must provide code to be run. A simple example of overriding the MSG event default behavior:
on ^msg * {echo msg from $0: $1-}
tbd
tbd
tbd
tbd