Skip to content
JonoCode9374 edited this page Sep 8, 2019 · 3 revisions

The same conventions apply in Tutorial.

Program Flow

If Statements

As mentioned in the introduction, Keg has a readable and intuative way of expressing if statements, for and while loops. The form of an if statement is:

[...1 ∆| ...2∆]

When an if statement is run, the last item on the stack is popped, and if it is non-zero, ...1 is executed. If there is a |...2, it is executed if the popped value is 0.

For Loops

The form of a for loop is:

(∆...1|∆ ...2)

When a for loop is run, if ...1 is present, it will be evaluated as used as the number of times the loop will be run (if it isn't given, the length of the stack will be used). ...2 is the body of the for loop, which will be executed.

While Loops

The form of a while loop is:

{ ∆...1|∆ ...2}

When a while loop is run, ...1 (if given) will be the condition of the loop (if it isn't present, 1 will be used as the condition of the loop) and ...2 will be executed until the given condition is false.

User Defined Functions

One of the special features of Keg is user-defined functions, which are defined using the following form:

@name ∆n∆ | ...ƒ

Where: name = the name of the function (note that it needs to be one full word, and that it can't contain any @'s) n = the number of items popped from the stack ... = the body of the function

If n isn't present, no items will be popped from the stack, and all code in the function will be applied to the main stack