KOSDelegate¶
The structure KOSDelegate is what you get when you use the Delegate at-sign syntax, as in this example:
function myfunc { print "hello, there". }
local print_a_thing is myfunc@. // <--- Note the at-sign '@'.
// print_a_thing is now a KOSDelegate of myfunc.
You also get a KOSDelegate when you use the Anonymous function syntax like so:
set del1 to { print "hello, there". }.
// del1 is now a KOSDelegate.
A KOSDelegate is a reference to the function that can be used to call the function later elsewhere in the code.
Be aware, however, that it will not let you call the function
after the program is gone and you are back at the interactive
prompt again. (See ISDEAD
).
The full explanation of the delegate feature is explained elsewhere. This page just documents the members of the KOSDelegate structure for completeness. The full explanation of how this structure works and what it’s for can be found on the delegate page.
Structure¶
- structure KOSDelegate¶
¶ Suffix
Type
Description
same as the function this is a delegate for.
calls the function this delegate wraps.
another KOSDelegate
creates a new KOSDelegate with some arguments predefined.
True if the delegate refers to a program that’s gone.
- KOSDelegate:CALL(varying arguments)¶
Calls the function this KOSDelegate is set up to call.
The varying arguments you pass in to this are passed on to the function this KOSDelegate is calling. The exact number of arguments you pass should match the number the function expects, minus any that you have pre-set with the
:BIND
suffix.This is further explained elsewhere.
Note that in some cases you can omit the use of the explicit suffix
:CALL
and just use parentheses abutted against the KOSDelegate variable itself to indicate that you wish to call the function.
- KOSDelegate:BIND(varying arguments)¶
Creates a new KOSDelegate from the current one, which will call the same function, but in which some or all of the parameters the function will be passed are pre-set. The arguments you pass in will be bound to the leftmost parameters of the function. When using this new KOSDelegate to call the function, you pass in only the remaining arguments that were not designated in the call to
:BIND
.This is further explained elsewhere.
- KOSDelegate:ISDEAD¶
- Type
- Access
Get only
It is possible for a KOSDelegate to refer to some user code that no longer exists in memory because that program completed and exited. If so, then ISDEAD will be true.
This can happen because kOS lets global variables continue to live past the end of the program that made them. So you can do something like this:
function some_function { print "hello". } // NOTE: my_delegate is global so it keeps existing // after this program ends: set my_delegate to some_function@.
If you run that program and get back to the interactive terminal prompt, then my_delegate is still a KOSDelegate, but now it refers to some code that is gone. The body of some_function isn’t there anymore.
If you attempt to call my_delegate() at this point from the interpreter, it will complain with an error message because it knows the function it’s trying to call isn’t there.
DONOTHING (NODELEGATE)¶
- structure NoDelegate¶
Suffix
Type
Description
Every suffix of
KOSDelegate
- DONOTHING¶
There is a special keyword
DONOTHING
that refers to a special kind ofKosDelegate
called aNoDelegate
.The type string returned by
DONOTHING:TYPENAME
is"NoDelegate"
. Otherwise an instance ofNoDelegate
has the same suffixes as one ofKOSDelegate
, although you’re not usually expected to ever use them, except maybeTYPENAME
to discover that it is aNoDelegate
.DONOTHING
is used when you’re in a situation where you had previously assigned aKosDelegate
to some callback hook the kOS system provides, but now you want the kOS system to stop calling it. To do so, you assign that callback hook to the valueDONOTHING
.DONOTHING
is similar to making aKosDelegate
that consists of just{return.}
. If you attempt to call it from your own code, that’s how it will behave. But the one extra feature it has is that it allows kOS to understand your intent that you wish to disable a callback hook. kOS can detect when theKosDelegate
you assign to something happens to be theDONOTHING
delegate. When it is, kOS knows to not even bother calling the delegate at all anymore.