MUF (programming Language) - Hello, World

Hello, World

The standard "Hello World" program would look like this:

( a standard demo program ) : HelloWorld me @ "Hello, world!" notify ;

The first line is a comment. Text in parentheses is ignored by the compiler and during program execution. MUF is not a particularly readable language, and MUF programs are used, installed, and maintained in a hurly-burly environment by users and programmers of widely varying capabilities. Comments describing a program's authorship, terms of distribution, means of installation, and program flow are helpful and important.

The second line — a colon followed by a name, set flush left — opens the declaration of a word. This program contains one word; its name is HelloWorld.

The third line contains all the executable code in the program. "me" is a variable; it holds the dbref of the user running the program. "me" is a special variable that is declared and initialized by the server when the program is run. The programmer can also declare and initialize his or her own variables.

The @ at sign is the FETCH operator. It "fetches" the value stored in the variable "me" (the user's dbref), and puts it on the stack.

"Hello, world!" is a string. Simply including the string in the code does an implicit PUSH, putting the data on the stack. After this statement, the string will be put on the stack (above the user's dbref).

"notify" is a primitive. It instructs the server to output the string on the top of the stack to the player with the dbref that is currently stored as the second-from-top element on the stack. The user will see the string on his or her screen, and both data will be removed from the stack. If the stack did not contain a dbref and a string, in the proper order, the program would crash.

The semi-colon on the fourth line marks the end of the word.

The stack trace for this program would be:

2 ("") (HelloWorld) 3 ("") V0 3 ("", V0) @ 3 ("", #1) "Hello, world!" 3 ("", #1, "Hello, world!") NOTIFY Hello, world! 4 ("") EXIT

Data types can be differentiated by their appearance within a stack trace. Strings appear as characters surrounded by quotation marks ("Three Thousand" or "3000"). Dbrefs appear as an integer preceded by an octothorpe or pound sign (#3000). A number will appear as the number itself (3000). A variable appears as an integer prefixed with either "V" (for global variables that are shared between all programs and libraries in a call chain), "LV" (for variables local to the given program — module scope) (LV3), or "SV" (for function-scoped variables) (SV2).

(There is an empty string (also called a "null string") at the base of this stack because the program was called with no arguments. If the command that invoked the program were called "hello", and the user typed "hello", then the stack trace would be as above. If the user typed "hello foo", then "foo" would be an argument to the command. The stack trace would show "foo" in place of "", but since the program never references this element, it makes no practical difference.)

Note that "notify" appeared in lower case in the source code, and in all upper case in the stack trace. MUF is case insensitive, but some programmers follow a convention of typing primitives and server-defined variables in uppercase, and all other statements in Upper-lowercase or lowercase.

Turning HelloWorld into a functioning program on a MUCK would require the following steps:

  1. The programmer acquires a Mucker bit if he or she does not already have one.
  2. The programmer types "@program HelloWorld" to create the program object and edit its contents.
  3. The programmer types "i", to begin Inserting source code.
  4. The programmer types or uploads the source code.
  5. The programmer types a . period to exit the editor's Insert mode.
  6. The programmer types "c" to compile the source code into an executable program.
  7. The programmer types "q" to exit the editor.
  8. The programmer creates a command to invoke the program, by typing in MUCK commands such as:
    1. @action hello=here
    2. @link hello=HelloWorld

Read more about this topic:  MUF (programming Language)

Famous quotes containing the word world:

    All the world loves a clown.
    Cole Porter (1893–1964)