When you begin to study programming, it is often very helpful to resort to an analogy with a cooking recipe to give a first informal idea of ​​what is meant by algorithm. And in case you didn’t know, there is a programming language called Chef that is designed to make programs look like cooking recipes. Who would say that a programming code would be hidden behind a cooking recipe.

CHEF is a language whose programs have the structure of a cooking recipe. The basic elements of the language are the ingredients, which have the role of variables, and the containers (plates), which act as stack-type data structures (although with some additional operations to the usual ones). Every program begins with the name of the recipe, and is followed by the list of ingredients and the method of preparation (main body of the algorithm). Within the latter, we have different actions to insert / extract ingredients from the bowls, or to alter their values. For example:

Take <ingredient> from refrigerator: reads a value from keyboard, and stores it in ingredient.

Put <ingredient> in [n-th] bowl: Enters the ingredient value at the top of the indicated stack.

Add | Remove <ingredient> in [n-th] bowl: add | subtracts the ingredient value from the value at the top of the indicated stack.

Combine | Divide <ingredient> in the [nth] bowl: Multiply | divides the ingredient value to the value at the top of the indicated stack.

Pouring contents of [n-th] bowl onto [m-th] plate: Copies items from one pile to another.

Serve for k diners: it shows on the screen k values, taken in order from the first dish, after the second if necessary, etc.

In addition to these basic operations, there is a general iterative construction, which allows simulating while – endwhile loops. Specifically, when we encounter an action of the type <verb> <ingredient> (where the verb can be anything other than one of the reserved words) we start a while loop conditional on the ingredient value being greater than zero. The end of the loop is marked with an action of type <verb> [<ingredient>] until it is <adjective>. Again, the verb and adjective (typically a participle) indicated are arbitrary, and if an ingredient is indicated its value is decremented by one before returning to the beginning of the loop.

Other related reads:
Shakespeare Unique Programming Language
ArnoldC For Arnold Schwarzenegger Lovers
ReMorse is a language with 4 simple instructions


Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *