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

Inline multi-line functions #397

Open
mkruselj opened this issue Sep 13, 2023 · 1 comment
Open

Inline multi-line functions #397

mkruselj opened this issue Sep 13, 2023 · 1 comment

Comments

@mkruselj
Copy link
Collaborator

mkruselj commented Sep 13, 2023

Let's say we have a function like:

function math.clamp(x, min, max)
    if (x < min)
        x := min
    else if (x > max)
        x := max
    end if
end function

We currently cannot inline this function in cases like these (or at all, really - cannot even assign such a function to a variable directly):

if math.clamp(x, 0, 100) = 50

What would need to happen is:

temp := math.clamp(x, 0, 100)

if temp = 50

There would have to be a proxy variable for every expression that is bool'd together. Probably makes sense to use an array instead.

if math.min(x, 0) # 0 and math.clamp(y, 0, 100) = 50

becomes:

temp[0] := math.min(x, 0)
temp[1] := math.clamp(y, 0, 100)

if temp[0] # 0 and temp[1] = 50
    <code>
end if
@eitherys
Copy link
Collaborator

This needs to respect short-circuit evaluation. The rules are

For expression if A and B

proxies for A
if A
    proxies for B
    if B
        code

For expression if A or B

proxies for A
if A
    code
else
    proxies for B
    if B
        code
end if

Of course this would have to be written properly as part of an expression tree to build how far the if-statements expand when expressions are more complex. I would not add this feature if you can not make it respect short-circuit evaluation; it would invalidate basic rules of programming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants