Thank you for all your work on this, it's very helpful. I have a feature request based on how I've started organizing my kOS scripts.
Is your feature request related to a problem? Please describe.
kOS doesn't support user defined structures, but you can fake them by using lexicons with the suffix syntax. I've gotten into the habit of using some "object oriented" practices to organize projects. I set up fake structures by using functions that look like this:
function MYUSERSTRUCTURE{parameter initVar.local SELF is Lexicon().set SELF:SUFFIX1 to {user_function().}.set SELF:SUFFIX2 to initVar.return SELF.}
This makes the MYUSERSTRUCTURE function act like the initializer for built-in structures. So I can put together code that looks like:
set STRUCTUREINSTANCE to MYUSERSTRUCTURE(anInitVar).STRUCTUREINSTANCE:SUFFIX1().
I use some different capitalization to help keep track of what things are intended to do, but that doesn't prevent me from breaking my own rules for faking a user defined structure. It would be helpful if there was a way to add structures to the set of built-in structures.
Describe the solution you'd like
If reasonable, I'd like to have a directive I could use to add structures to the list of in-built ones. Something that might look like:
\\ #structure MYUSERSTRUCTURE <initTypeInfo> SUFFIX1 <suffix1TypeInfo> SUFFIX2 <suffix2TypeInfo>function MYUSERSTRUCTURE{parameter initVar.local SELF is Lexicon().set SELF:SUFFIX1 to {user_function().}.set SELF:SUFFIX2 to initVar.return SELF.}
Where <...TypeInfo> might specify the input/return types of the "suffixes" (if convenient for implementing the feature, if it's easier to default these types to arbitrary number of (structure) inputs, (structure) output to avoid wrong-arity and wrong-type errors, that would still be really useful). Then I could use some of the same tools available for built-in structures, like the drop down lists of suffixes and the warnings about performing a set on a structure suffix.
Thank you for all your work on this, it's very helpful. I have a feature request based on how I've started organizing my kOS scripts.
Is your feature request related to a problem? Please describe. kOS doesn't support user defined structures, but you can fake them by using lexicons with the suffix syntax. I've gotten into the habit of using some "object oriented" practices to organize projects. I set up fake structures by using functions that look like this:
function MYUSERSTRUCTURE{
parameter initVar.
local SELF is Lexicon().
set SELF:SUFFIX1 to {user_function().}.
set SELF:SUFFIX2 to initVar.
return SELF.
}
This makes the
MYUSERSTRUCTURE
function act like the initializer for built-in structures. So I can put together code that looks like:set STRUCTUREINSTANCE to MYUSERSTRUCTURE(anInitVar).
STRUCTUREINSTANCE:SUFFIX1().
I use some different capitalization to help keep track of what things are intended to do, but that doesn't prevent me from breaking my own rules for faking a user defined structure. It would be helpful if there was a way to add structures to the set of built-in structures.
Describe the solution you'd like If reasonable, I'd like to have a directive I could use to add structures to the list of in-built ones. Something that might look like:
\\ #structure MYUSERSTRUCTURE <initTypeInfo> SUFFIX1 <suffix1TypeInfo> SUFFIX2 <suffix2TypeInfo>
function MYUSERSTRUCTURE{
parameter initVar.
local SELF is Lexicon().
set SELF:SUFFIX1 to {user_function().}.
set SELF:SUFFIX2 to initVar.
return SELF.
}
Where <...TypeInfo> might specify the input/return types of the "suffixes" (if convenient for implementing the feature, if it's easier to default these types to arbitrary number of (structure) inputs, (structure) output to avoid wrong-arity and wrong-type errors, that would still be really useful). Then I could use some of the same tools available for built-in structures, like the drop down lists of suffixes and the warnings about performing a set on a structure suffix.Thanks again.