::SHE+ILA:: Events, Waitable and Trapable

117
0
  • Squishy Plushie's avatar Artist
    Squishy Pl...
  • DDG Model
    DaVinci2
  • Access
    Public
  • Created
    1w ago
  • Try

Prompt

A beautiful purple-haired woman wearing a long purple velvet ankle-length dress with flouncy sleeves and purple suede high heels. She is waiting at an event.

More about ::SHE+ILA:: Events, Waitable and Trapable

The statement {? EVENTCODE : lambda; EVENTCODE2 : lambda2 ?}; declares two trappable events (like exceptions) such that when EVENTCODE occurs, the procedure "lambda" is called with parameters describing the event. When the procedure containing the {? ... ?} statement goes out of scope, the previous settings of the event map are restored. This works something like C++'s try/throw/catch exception handler, except that the {? ... ?} statement is coded before the code to be tried, rather than after.
The same construct can also be used to monitor the fullness or emptiness of a Buf : {? ?Buf : ttyout("Buf just became empty"); Buf? : ttyout("Buf just became full") ?};
We can also allow the fullness or emptiness of a Buf to block the current thread (WAITABLE EVENT) :
Foo <:: { ?Buf; ttyout("Buf is no longer empty"); };
The use of "?" in this way outside of an event declaration block, causes the kernel to suspend the thread until the Buf is no longer full or empty, this can also be used as a semaphore mechanism to allow one thread to signal another one.
The user can throw custom events and exceptions by means of "!^", the "bang hat" operator, for example : Foo <:: { ttyout("about to throw user exception"); E'BADINPUT !^ ("Foo", LINE, NOW(), #stack);};

Comments


Loading Dream Comments...

Discover more dreams from this artist