You are browsing as a guest. Sign up (or log in) to start making projects!

9h 7m 36s logged

The light

I can see it… (what is it?) … the light at the end of the tunnel… (what are you talking about?) .. its almost here

Yea no it ain’t

Though the project isn’t done, I will admit I am nearing the closing moments of the IR stage, with only 1 last hurdle to overcome before I can transpile projects beginning -> end.

Here’s a small overview of what’s been done in the last two weeks (nah who am I kidding its all last night, I haven’t touched this in a bit)

Procedures

Katnip is scratch. Kinda. It transpiles to scratch. So it needs procedures.

I took a giant bite out of the huge problem that is procedures. It is very complex to try and emulate a return system in a program that just doesn’t support it.

Having taken a DSA class, this was a problem that I took to paper, and got the following solution:

  1. Stacks are beautiful.
    Let me elaborate. A stack is a structure that follows FiLo, or first-in, last-out. This is super important for returning from procedures, when considering the fact that a single variable will not be enough for systems when/if the function recurses. So this way, you push and pop on the stack to keep the order, and all return values are kept track of nicely!
  2. Mangled vars.
    Scope is a really hard concept to grasp, but even harder to emulate in a non-scoped language. For the most part, I want to keep Scratch’s inherent scope-less design, in the sense that variables can exist in similar ways. But I do want scopes. So I take back the before-last sentence.
    To do this, I mangle vars, allowing scopes to exist, multiple instances of the same code to run, and to have variables not collide.

For loops

A smaller sections, but still cool.

A for loop in scratch is a hidden–but supported–block. You can only iterate a variable, lets call it x, from 1..y inclusive, where y is the max range.

So for lists, this means lowering this:

for (x, myList) {
    looks.say(x);
}

into this:

for (x, listLength(myList)) {
    x = myList[x];
    looks.say(x);
}

Additionally, if doing a range function like this:

for (x, range(4, 10, 2)) {
    looks.say(x);
}

it lowers into this:

for (x, 3) {
    x = x * 2 + 4;
    looks.say(x);
}
0
12

Comments 2

@stratustraipsing

I agree, stacks are beautiful 🫡

@b1j2754

@stratustraipsing they really are- I love elegant data structures like them in general