Skip to content

Add syntax for dynamic loops #29

@AdvancedAntiSkid

Description

@AdvancedAntiSkid

Is your feature request related to a problem? Please describe.
HSL is trying to be a real programming language, however housing has too many limits for this. Recently I've found a workaround to implement loops via recursive function calls.

Describe the solution you'd like
Create fully-functional for and while loops. Lets take a look at how a for look should look like.

Users should declare something like this:

fn foo() {
    for (stat player i = 0; i < 10; i++) {
        chat($"iter: {i}")
    }
    chat("something after loop")
}

This should be converted to housing-compliant functions:

fn loopInit() {
    stat player i: int = 0
}

fn loopTick() {
    stat player i: int

    if (i < 10) {
        chat($"iter: {i}")
        i++
        loopTick()
    } else {
        loopMerge()
    }
}

fn loopMerge() {
    chat("something after loop")
}

Describe alternatives you've considered

Additional context
The merge step must be added to capture the remaining code after a loop. According to my testings, the actions after a (recursive?) function trigger DO NOT wait for the function to complete. Meaning that we can corrupt logic flow if we have any code with dependency to the loop after the loop. This forces us to put the remaining code in a merge function that is invoked after the loop is completed.

Metadata

Metadata

Labels

compilerSomething regarding the compilerenhancementNew feature or requestruntimeSomething regarding the runtime modulesyntaxSyntax support for a feature
No fields configured for Feature.

Projects

Status
In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions