Try-Catch-Finally Block
// Prep, Rescue, Cleanup is Sous's version of Try-Catch-Finally
Blocks
prep {
ingredient _x := 0;
serve("Started");
eightysix("Error Entered", Exception);
} rescue (Exception e) {
serve(e);
} rescue (ValueError v) {
serve(v);
} cleanup {
serve("Finished");
}
Functions
// Functions are created using the `recipe` keyword
ingredient temp := 350;
recipe CheckTemperature() : int {
if (temp > 300) {
serve("Temperature is hot
enough for baking.");
} else {
serve("Temperature too low.
Increase heat.");
}
 return temp;
}
ingredient x := CheckTemperature();
if (x != 300) {
 serve("Temperature is not 300 degrees.");
} else {
 serve("Temperature is 300 degrees.");
}
Loops
// Example of looping through an array using a regular for loop
ingredient menu := ["Soup", "Salad", "Steak", "Dessert"];
for (ingredient dishIdx := 0; dishIdx < count(menu); ++dishIdx)
{
serve("Preparing ", menu[dishIdx]);
}
// OR Using Pyth Style Syntax
ingredient Z := 0;
ingredient C := count(menu);
FDrZC {
serve("Preparing ", menu[Z]);
}
// OR Using python style `in` collection loop
for (item in menu) {
serve("Preparing ", item);
}
Classes
// Class Usage: Initializing a class using Dish and creating a new
Object
Dish Cake {
ingredient flour : string;
ingredient sugar : string;
ingredient eggs : string?;
recipe MixIngredients(ingredient x : int)
{
serve("Mixing
ingredients: ", flour, ", ", sugar, ", ", eggs);
}
recipe Bake() {
serve("Baking the
cake...");
}
}
Cake myCake := new Cake("2 cups", "1 cup", poached "hello");
myCake.MixIngredients(2);
ingredient flour := 5;
serve(stale);
myCake.Bake();
Fibbonnaci
// Fibbonnaci in Sous
ingredient N := 10; // Number of Fibonacci numbers to generate
ingredient first := 0, second := 1, next := 0;
serve("Fibonacci Sequence up to ", N, " numbers:");
for (ingredient plate := 0; plate < N; ++plate) {
if (plate <= 1) {
next = plate;
} else {
next = first + second;
first = second;
second = next;
}
serve(next, " ");
}
'''
for loop can be replaced as seen below:
ingredient Z := 0;
FPrZN {
ingredient plate := P;
...
}
'''
Using Classes As Structs
// Classes can be used as structs for accessing members
Dish Chef {
ingredient name : string;
ingredient age : int;
ingredient isHeadChef : boolean;
}
Chef headChef := new Chef("Coby", 22, fresh);
Chef sousChef := new Chef("Other", 21, stale);
// serve("Head Chef is ", headChef.name);
// serve("Sous Chef is ", sousChef.name);
ingredient chefs := [headChef, sousChef];
serve(chefs[0].isHeadChef);
if (chefs[0].isHeadChef != fresh) {
eightysix("Head Chef must be the first
indexed chef!", ValueError);
} else {
serve("valid ordering");
}
Private Class Members
// Private members can be specified by a _ chaarcter as a prefix
to the variable name
// These variables are only accessible within the class
Dish FamilyRecipe {
ingredient _ingredients : string;
ingredient _instructions : string;
ingredient _heat : int;
recipe bake() {
serve("start
preheating at ", _heat, " degrees");
ingredient i :=
0;
ingredient e :=
_heat;
while (i < e) {
serve("preheating...
", i," degrees");
i
= i + 1;
}
serve("preheating
complete");
serve("mixing
ingredients: ", _ingredients);
serve("baking at
", _heat, " degrees for 30 minutes");
return;
}
}
FamilyRecipe grandma_cookies := new FamilyRecipe("flour, sugar,
eggs, butter", "mix ingredients, bake at 350 degrees", 350);
grandma_cookies.bake();
'''
grandma_cookies._ingredients; // Error: _ingredients is a private
variable
'''