arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
723 stars 32 forks source link

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

Open drkameleon opened 1 year ago

drkameleon commented 1 year ago

See also:

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

RickBarretto commented 1 year ago

About this new type, how does should it work?

drkameleon commented 1 year ago

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

A few thoughts...

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.

RickBarretto commented 1 year ago

Thanks for the explanation, I liked this idea!

drkameleon commented 1 year ago

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!

RickBarretto commented 1 year ago

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

I totally agree with it! 😅

stale[bot] commented 1 year ago

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] commented 8 months ago

Closing issue as stale.

stale[bot] commented 3 weeks ago

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.