Follow

I recently noticed that the form:

```js
let procI = N
let args = [...]
while(true) {
switch(procI) {
case 0:
...
case 1:
...
...
}
}
```

And the form:

```js
function proc0(...) {...}
function proc1(...) {...}
...
procN(...)
```

Are functionally equivalent from a stackless perspective. Where, calls `procM(...)` in the 2nd form are equivalent to `args = [...]; procI = M; continue` in the 1st form. The while+switch / 1st form simulates pushing to an argument stack and jumping to different instruction offsets

This is really useful because it allows you to "call" certain functions as continuations without increasing the stack depth

Sign in to participate in the conversation
Qoto Mastodon

QOTO: Question Others to Teach Ourselves
An inclusive, Academic Freedom, instance
All cultures welcome.
Hate speech and harassment strictly forbidden.