Obfuna

Contents

Obfuna

Obfuna is an esoteric programming language designed to minimise the instruction set, the length of code necessary to express a program, and the readability while still remaining vaguely useful.

To achieve these goals, all Obfuna operations are assigned one-character names and take exactly one argument. In fact, the name Obfuna is derived from 'obfuscated' (Obfuna code is, at least initially, difficult to read) and 'unary' (all operations have exactly one argument). There are twenty six variables and one random-access unbounded array. All variables are dynamically typed as this cuts down on the code length.

Specification

Obfuna has 26 standard variables which are represented by the lower-case letters a to z.

There is one random-access array which is infinitely extendable (well, in theory anyway; in practice this will be limited by your machine's memory) which is represented by a number (indicating the position in the array - starting at 0) or a function returning a number surrounded by round brackets, i.e. ( and ). For example, the first element in the array is represented by (0). The size of the array increases as you assign to higher locations. The initial size of the array is 0.

There are two special 'variables' used to ascertain the current size of the array. $ holds the index number of the last element in the array and % holds the number of elements in the array. From above, it will be obvious that initially $ will be -1 and % will be 0. Assigning to these variables can grow or shrink (in which case you will lose data) the array to a specified size. These are of particular use as ($) can used to reference the last element in the array and (%) will reference one element beyond the end, allowing you to add a new element, treating the array like a stack.

In addition, there are three special 'variables' which act as I/O pipes. Passing a value to ?, prints the value to the standard output. Assigning a variable from ?, reads from the standard input. ! acts similarly except that in the case of output, it appends a newline (return) character to the value, and in the case of input, it preserves the newline from standard input. # works in exactly the same way as ? but inputs and outputs from and to the currently open file.

The syntax of Obfuna is extremely simple. There are only two types of instruction: function calls and assignments. Assigments take the form of <variable name><value> and function calls look like <function name><value> or <function name><function call>. Note you can nest functions in this way.

As an example, to assign the number 10 to the variable n, you simply write n10. There is no = operator.

Strings are quoted using the angle brackets, < and >. Anything between curly brackets, { and }, is considered a comment and will be ignored by Obfuna. These are particularly useful for naming variables more helpfully. Instead of just n10, you could write n{umber}10.

The only other syntactic element of Obfuna is the square brackets, [ and ]. Any code between a pair of square brackets will be considered a block to be processed as one instruction. This is of particular use when using flow control functions which skip or repeat only the next instruction.

Below is a list of all the functions using x as their argument for example purposes.

Character Name Comments
+x Plus Adds x to ($)
-x Subtract Subtracts x from ($)
*x Multiply Multiplies ($) by x
/x Divide Divides ($) by x
^x Raise Raises ($) to the power of x
Ax ASCII Converts x's numeric value to an ASCII character and returns the result
Cx Concatenate Appends x to the end of ($)
Dx Do Repeats the next instruction x times
Ex Evaluate Intereprets x as a list of obfuna instructions
Fx File Opens or re-opens x as a file. Not yet implemented.
Ix Integer Returns the integer portion of x.
Lx Length Returns the number of characters in x
Mx Mismatch Returns 1 if ($) is not equal to x, else returns 0.
Nx Numeric Returns the ASCII value of the first character of x
Ox Over Returns 1 if ($) is greater than x, else returns 0.
Qx Equal Returns 1 if ($) is equal to x, else returns 0.
Rx Random Returns a random integer from 0 to x
Ux Under Returns 1 if ($) is less than x, else returns 0.
Vx Invert Returns the inverse of x, i.e. 1/x
Wx While Repeats the next instruction while x is true (i.e. non-zero)
Xx Extract Returns the xth character of ($)

Examples

The best way to learn and get a feel for Obfuna is by example. A few very simple examples are shown below.

This program simply prints "Hello, world!" and a newline:

!<Hello, world!>

This runs through the 99 bottles of beer song:

(%)99
WO1[?($)!< bottles of beer on the wall...>-1]
!<1 bottle of beer on the wall.>

A simple program to ask a question and print the input back out to the screen:

!<Hi, I'm Obfuna. What's your name?>n?
?<Hello, >!n

Number guessing game: This simple program prompts the user to guess a random number between 0 and 50 and then guides hir along to the right answer by saying "too low" or "too high".

{assign r to a random number from 0 to 50}
rR50
(%)0

{Repeat the block while ($) is equal to 0}
WQ0
[
{Prompt for a guess and store it in g}
 ?<Make a guess from 0 to 50: >
g?

{Put the original number on top of the array for comparison}
($)r

{Make the appropriate comment}
DOg[!<Too low.>]
DUg[!<Too high.>]
DQg[!<Just right!>]

{Put truth value of r=g on top of the array}
($)Qg
]

Compact version:

rR50(%)0WQ0[?<Make a guess from 0 to 50: >g?($)rDOg[!<Too low.>]DUg[!<Too high.>]DQg[!<Just right!>]($)Qg]

Reversing a string: This takes in a string from the user and outputs it backwards. Very useful of course.

{Prompt for and get a string from the user}
 ?<Enter a string to reverse: > s?
r<>
n0
(%)r

{Repeat the loop a number of times equal to the length of s}
DLs[

{Put s on top of the array, chop out just the character we're on}
($)s
($)Xn

{Concatenate the result so far onto the end and store the new results as r}
Cr
r($)

{Increment the counter}
($)n
+1
n($)
]

{Print the final result!}
 !r

Compact version:

 ?<Enter a string to reverse: >s?r<>n0(%)rDLs[($)s($)XnCrr($)($)n+1n($)]!r

External links

Navigation

  • Art and Cultures
    • Art (https://academickids.com/encyclopedia/index.php/Art)
    • Architecture (https://academickids.com/encyclopedia/index.php/Architecture)
    • Cultures (https://www.academickids.com/encyclopedia/index.php/Cultures)
    • Music (https://www.academickids.com/encyclopedia/index.php/Music)
    • Musical Instruments (http://academickids.com/encyclopedia/index.php/List_of_musical_instruments)
  • Biographies (http://www.academickids.com/encyclopedia/index.php/Biographies)
  • Clipart (http://www.academickids.com/encyclopedia/index.php/Clipart)
  • Geography (http://www.academickids.com/encyclopedia/index.php/Geography)
    • Countries of the World (http://www.academickids.com/encyclopedia/index.php/Countries)
    • Maps (http://www.academickids.com/encyclopedia/index.php/Maps)
    • Flags (http://www.academickids.com/encyclopedia/index.php/Flags)
    • Continents (http://www.academickids.com/encyclopedia/index.php/Continents)
  • History (http://www.academickids.com/encyclopedia/index.php/History)
    • Ancient Civilizations (http://www.academickids.com/encyclopedia/index.php/Ancient_Civilizations)
    • Industrial Revolution (http://www.academickids.com/encyclopedia/index.php/Industrial_Revolution)
    • Middle Ages (http://www.academickids.com/encyclopedia/index.php/Middle_Ages)
    • Prehistory (http://www.academickids.com/encyclopedia/index.php/Prehistory)
    • Renaissance (http://www.academickids.com/encyclopedia/index.php/Renaissance)
    • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
    • United States (http://www.academickids.com/encyclopedia/index.php/United_States)
    • Wars (http://www.academickids.com/encyclopedia/index.php/Wars)
    • World History (http://www.academickids.com/encyclopedia/index.php/History_of_the_world)
  • Human Body (http://www.academickids.com/encyclopedia/index.php/Human_Body)
  • Mathematics (http://www.academickids.com/encyclopedia/index.php/Mathematics)
  • Reference (http://www.academickids.com/encyclopedia/index.php/Reference)
  • Science (http://www.academickids.com/encyclopedia/index.php/Science)
    • Animals (http://www.academickids.com/encyclopedia/index.php/Animals)
    • Aviation (http://www.academickids.com/encyclopedia/index.php/Aviation)
    • Dinosaurs (http://www.academickids.com/encyclopedia/index.php/Dinosaurs)
    • Earth (http://www.academickids.com/encyclopedia/index.php/Earth)
    • Inventions (http://www.academickids.com/encyclopedia/index.php/Inventions)
    • Physical Science (http://www.academickids.com/encyclopedia/index.php/Physical_Science)
    • Plants (http://www.academickids.com/encyclopedia/index.php/Plants)
    • Scientists (http://www.academickids.com/encyclopedia/index.php/Scientists)
  • Social Studies (http://www.academickids.com/encyclopedia/index.php/Social_Studies)
    • Anthropology (http://www.academickids.com/encyclopedia/index.php/Anthropology)
    • Economics (http://www.academickids.com/encyclopedia/index.php/Economics)
    • Government (http://www.academickids.com/encyclopedia/index.php/Government)
    • Religion (http://www.academickids.com/encyclopedia/index.php/Religion)
    • Holidays (http://www.academickids.com/encyclopedia/index.php/Holidays)
  • Space and Astronomy
    • Solar System (http://www.academickids.com/encyclopedia/index.php/Solar_System)
    • Planets (http://www.academickids.com/encyclopedia/index.php/Planets)
  • Sports (http://www.academickids.com/encyclopedia/index.php/Sports)
  • Timelines (http://www.academickids.com/encyclopedia/index.php/Timelines)
  • Weather (http://www.academickids.com/encyclopedia/index.php/Weather)
  • US States (http://www.academickids.com/encyclopedia/index.php/US_States)

Information

  • Home Page (http://academickids.com/encyclopedia/index.php)
  • Contact Us (http://www.academickids.com/encyclopedia/index.php/Contactus)

  • Clip Art (http://classroomclipart.com)
Toolbox
Personal tools