Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Faking User Defined Structures #182

Open
girbrother2 opened this issue Jun 8, 2021 · 0 comments
Open

[Feature] Faking User Defined Structures #182

girbrother2 opened this issue Jun 8, 2021 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@girbrother2
Copy link

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.

@girbrother2 girbrother2 added the enhancement New feature or request label Jun 8, 2021
@girbrother2 girbrother2 changed the title [Feature] <Faking User Defined Structures> [Feature] Faking User Defined Structures Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants