arturo icon indicating copy to clipboard operation
arturo copied to clipboard

Create new `:event` type and related handlers/emitters as built-in functions?

Open drkameleon opened this issue 1 year ago • 7 comments

See also:

https://discord.com/channels/765519132186640445/829324913097048065/1084769083771330632

drkameleon avatar Mar 13 '23 10:03 drkameleon

About this new type, how does should it work?

RickBarretto avatar Mar 13 '23 16:03 RickBarretto

Well, the truth is this is something that remains to be studied.

A few thoughts...

  • we could have 2 different functions, one for handling events (on) and one for emitting/triggering events (emit).
  • there could be system-defined events (e.g. Nim clearly supports adding a hook for Ctrl+C events -> https://nim-lang.github.io/Nim/system.html#setControlCHook%2Cproc%29), which we could properly handle if necessary
  • the user may also create different event on his own
  • all of this would have to comply to a new :event type
  • each event could also carry some data (perhaps any valid Arturo value encapsulated)

A rough example of what I'm talking about:

on 'ctrlC [e][
    print ["Received control-c event:" e]
]

or...

setNum: function [x,val][
     previousVal: var'x
     let x val
     emit.with:#[
           previous: previousVal
           current: var'x
     ] 'numberChanged 
]

on 'numberChanged [e][
     print "Number changed!"
     print ["previous value:" e\data\previousVal "current value:" e\data\currentVal]
]

a: 2
setNum 'a 3 
print a ; a has become 3, and the event has been triggered in the background

That's a very rough sketch, but this is pretty much what I've had in mind 😉


The whole idea is very, very similar to that of functions; and that's a reason why I haven't implemented it yet. Now, that being said, the Ctrl-C idea for example is something that could be used with events (but obviously not with functions, as they are in Arturo), given that the "emitter" is the system itself.

drkameleon avatar Mar 13 '23 17:03 drkameleon

Thanks for the explanation, I liked this idea!

RickBarretto avatar Mar 13 '23 17:03 RickBarretto

Thanks for the explanation, I liked this idea!

Let's see... This needs some careful thought before!

For now, I would prefer it if we focused on existing issues & testing rather than adding something totally new, since - as it happens - with new features come new bugs. But it's definitely in my to-do list!

drkameleon avatar Mar 14 '23 15:03 drkameleon

For now, I would prefer it if we focused on existing issues & testing rather than adding something totally new, 

I totally agree with it! 😅

RickBarretto avatar Mar 14 '23 18:03 RickBarretto

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 10 '23 01:11 stale[bot]

Closing issue as stale.

stale[bot] avatar Mar 09 '24 03:03 stale[bot]