MUF (programming Language) - Overview

Overview

Like Forth, MUF is a stack-based, compilable, structured language. MUF programs are created by entering source code in an interactive MUF editor (a feature of the MUCK server) and compiling it into a "program object" — a referenceable object in the MUCK's database providing redirection to the executable code. Because the editor is relatively crude, most MUF programmers write source code in a text editor on a client machine and upload it into the editor.

The language supports several primitive data types: strings, integers, floats, dictionaries, arrays, database references (usually referred to as dbrefs), and boolean locks. A string is a series of characters, used primarily to process input and output. Originally, MUCK supported only integer numbers, but support for floating point numbers — as well as arrays and dictionaries — was added around 1995. A dbref is a reference or index to a named object in the MUCK database. Boolean locks are a very MUCK specific data type often used to validate user's permissions to do various actions. MUF also stores references to variables on the stack, and allows these references to be manipulated with mathematical and boolean operators. For this reason, variables may be regarded as yet another datatype in MUF.

MUF is stack-based. Runtime data is stored in a LIFO stack, and MUF programs work primarily by manipulating the contents of the stack. Variables exist to make this easier, but they were deprecated as being dangerous to use until function-scoped variables were added around 1995.

MUF implements a core language of approximately 200 functions known as primitives. Each primitive performs a specific task. For example, the NOTIFY primitive outputs a string to a player. Other primitives perform tasks such as recalling or storing information, converting data types, utilizing data on the program stack to perform conditional logic, or manipulating the stack itself.

A complete list of primitives is output by the MAN PRIMITIVES command. Further information on a specific primitive is available with the command MAN . For example, typing "man notify" will provide information on the NOTIFY primitive. These documentation entries begin with the name of the primitive, followed by a "stack effect" statement. Stack effects are shown in the form of ( x1 x2 .. -- y1 y2 .. ), where text to the left of the double dash mark indicates data and the order it must be placed on the stack before that particular primitive can be used. Text to the right of the double dash indicates data elements that will be returned to the stack once the primitive has completed its operation.

Like Forth, MUF is easily extensible: programmers may combine primitives and data to form new named subroutines. As in Forth, user-created subroutines are properly known as words, but many MUF programmers frequently use the term function interchangeably. A MUF word declaration opens with a colon and the name of the word, followed by the primitives, data, and identifiers that make up the word's code. A word's declaration is closed with a semi-colon. As in most structured languages, whitespace is insignificant, with one exception: there must be no leading whitespace before the colon that opens a word declaration. The core language is supplemented by numerous program libraries containing user-defined words.

Program execution begins at the opening of the last word declared within a program. This is because all subroutine-words, define statements, and libraries need to be declared and defined before they can be used. This beginning word does not need to be named 'Main', as the only name restrictions imposed are that some reserved words and variables are not duplicated.

MUF programming on a MUCK server is governed by a system of permissions implemented through Mucker bits. By default, users (or "players") on a MUCK do not have permission to use the MUF editor, which means they cannot create or alter programs. At the site administrators' discretion, an individual player may be given a Mucker bit, which is a setting on the player's account that allows him or her use of the MUF editor, with varying degrees of freedom. An M1 bit (Apprentice) is the lowest setting: the player may create and alter programs, and may use a restricted set of the MUF primitives. An M2 bit (Journeyman) gives the user access to an extended set of primivitives. The M3 bit (Master) gives the user access to all but a very few primitives. The Mucker bit also controls the maximum number of instructions that may be executed in a given instance of the program.

Transforming a MUF program into a usable command or feature also requires creating a command or trigger to invoke the program. At the time of execution, any remaining text from the command line used to call the program is pushed onto the stack, this provides one method for the user to pass arguments into the code to be acted upon.

Read more about this topic:  MUF (programming Language)