Message Boards Message Boards

0
|
2780 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Can you generate your own types of events?

The system generates events associated, for example, with mouse clicks.

Is it possible to generate your own kind of events based on some type of occurence. For example, you are reading a character at a time from some input, and you want to generate an event when the input satisfies some condition (perhaps when it is a vowel).

Say you are reading characters and you want to generate an event (call it "gotIT") whenever you read the character "X" or you are reading a sequence of numbers and whenever a peak is detected (say you read 10 20 15) once you have read the number 15 you realize that there was a peak at number 20 and you want to "fire" an event called "gotPeak".

The next question would be that if it is possible to do so, how do you hook the event to some function (the Event Handler). In other words, how would you have a function register to be called whenever the "gotPeak" event is fired?

In this way, as you come up with other event handlers for that event, you simply register them with that event and each function registered with event "gotPeak" will get called whenever "gotPeak" is fired.

POSTED BY: Henrick Jeanty
3 Replies
Posted 1 year ago

The original examples were iterating through lists. Dynamic is probably not the approach you want in that case. Based on the original examples of iterating through lists, something using Reap and Sow might be what you're looking for.

POSTED BY: Eric Rimbey

After thinking a bit about it I think that I might actually have an answer to my own question. I think I have been thinking the wrong way about Mathematica's capabilities with respect to events. As usual, Mathematica surprises me with its approach to solving problems. I was trying to shoehorn Mathematica into the mold of other languages when thinking of events. I believe that Dynamic is the answer to my question. Basically if you declare a Dynamic variable and a Dynamic expression which is a function of that variable, you have essentially allowed x to be its own event generator and any expression that is a function of x has essentially subscribed to the event generated when x changes. To me that is a much better model than for instance what I do in C# with .Net Perhaps others can put in their 2 cents.

POSTED BY: Henrick Jeanty

8-20-22 Hi Hendrick, Great questions. As corollary, could sequences of events be recorded as well? This then brings to mind, two additional related questions- 1. Could nucleotide sequences in RNA be detected and counted? 2. And could fractals be identified among various types of similarly linear sequences?

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract