Thursday, May 31, 2012

The Wittgen Programming Language

In this entry, I would like to introduce a new programming language: Wittgen. For now, I will only specify the language in semi-formal terms without much elaboration. Wittgen will be used in future entries to explore issues in cognition and philosophy.

The Wittgen programming language consists of just two instructions and one special variable name.

Wittgen allows you to assign any text string to a variable of any name. It also allows you to retrieve the text assigned to that variable. Lastly, it has a special variable called “Doing Now”. Every execution step consists of retrieving the contents of Doing Now, removing the first assign found in that content and performing that assign. In the course of performing that assign any retrieve operations indicated in the text are performed before committing the assign. That is all there the system does.

The assign operation is indicated in a text string as:
        <variable name>:=<assigned text>}
The symbols < and > are not part of the language, they are used only here to indicate that whatever is between the < and the > can be replaced by any text string. For example:
        My variable:=hello world!}
means assign the text “hello world” to a variable called “My variable”. If “My variable” has never been encountered it is created as a new variable. If it already exists, the contents, or what the variable points to, are replaced by the new text string. The name of the variable extends from the end of the last assign until the “:=” symbol. The text to be assigned extends from the “:=” symbol to the “}” symbol.

The retrieve operation is indicated in a text string as:
        @<variable name>}
For example: @My variable}, found in a text string will be replaced in its entirety (i.e. including the @ and } symbols by the text “hello world!” from the previous example. The following example demonstrates the complete usage:
        part 1:=hello}
        part 2:=world}
        greeting:=@part 1} @part 2}!}

The example consists of three lines but the line breaks are ignored. The first line assigns the text “hello” to a variable which is now created called “part 1”. The second line assigns the text “world” to the variable called “part 2”. The third line replaces the text @part 1} using a retrieve operation on the variable “part 1” with the text “hello”. @part 2} is replaced by “world” and therefore the text “hello world!” is assigned to the variable greeting.

If a retrieve operation is attempted but the is no variable of that name, the retrieve operation fails. For example, if there had been no previous assign to "part 1", then there is no variable "part 1" and the retrieve fails.

Before actually assigning the text to the variable name, all retrieve operations are performed with one exception. The text to assign may contain encapsulated assign statements. Any retrieve instruction between the “:=” and its corresponding “}” will not be evaluated.

One variable has special significance. The variable called “Doing Now” determines the next assign executed. Wittgen is programmed by creating a source file of text containing a series of assigns (at least one). Executing the source file assigns all the text in the file to the variable Doing Now. Wittgen continues executing as long as Doing Now points to some text. The first assign is removed from the contents of variable Doing Now such that Doing Now points to the remainder. The assign is performed as described above including any text replacements due to retrieve instructions. When the assign is complete the text referred to by Doing Now is again accessed, the (next) first assign removed, executed, again Doing Now is accessed etc. until Doing Now points to no assign.

Note that the assign may change the contents of Doing Now such that when the assign is complete, the next assign is not the one that would have been performed if the assign had not taken place. The next blog entry will give examples of this.

If, in the course of an assign, a retrieve instruction is performed and the retrieve operation fails, the entire assign operation will fail. If the variable being assigned to does not exist, it will not be created. If the variable already exists, it continues to refer to the text it did before the assign operation began and the content it refers to is not changed.

The Wittgen language is entirely defined by the contents of this entry. It includes no other capabilities or instructions found in standard programming languages. It does not have an if, for, loop, goto, function, =, list head (car), list tail (cdr) or variable declaration. It contains no inbuilt support for mathematical operators such as +, -, *, ^ or %. It has no predicate operators such as >, <, <>, >= or <=. It contains no integer, floating point, array, struct or class types. The functionality of these operations, however, may be created using the two instructions that Wittgen does have.

In future entries, many more examples will be given. These will help clarify how Wittgen is actually used and how it works.

No comments:

Post a Comment