Alchemy

Overview
Alchemy is an esoteric programming language created by User:EvincarOfAutumn in April 2008.

Each Alchemy program consists of a series of "reactions", which perform arithmetic operations and I/O, numeric line labels, and conditional jumps to those labels. Comments are given in parentheses.

Elements
Variables in Alchemy are called "elements". Elements have the following properties:


 * Element names are alphabetic.
 * Element names must begin with a capital letter.
 * The names of dry elements end with.
 * The names of wet elements end with.
 * Each element has a "substance number" equal to the sum of the ASCII character values in its identifier.
 * The names of water-soluble elements begin with.

Predefined Elements
The following elements are defined at the start of an Alchemy program, and have the indicated initial values.

(To be decided)

Steps
Steps may be given numeric labels with a declaration of the form:

Step Number:

Where  is an integer.

The programmer may conditionally jump to a label:

ElementName? Number

If  is nonzero, then program execution jumps to Step.

Reactions
The general syntax of a reaction is:

ProcessName ElementList (Solvent): ProductName

Where  is the alchemical process to be performed,   is a list of the names and amounts of the elements used in the reaction,   defines which solvent to use for the reaction, and   indicates the element to which the result of the reaction should be stored.

Processes

 * - Divides the first element by all following.
 * - Inputs a value for each element.
 * or  - Subtracts all following elements from the first.
 * or  - Calculates the arithmetic mean of all elements.
 * - Truncates the first element and returns it.
 * - Decrements the first element and returns it.
 * - Returns the bitwise AND of all elements.
 * - Returns the bitwise OR of all elements.
 * - Returns the bitwise inverse of the first element.
 * - Returns the product of all elements.
 * - Outputs the value of each element.
 * - Returns the sum of all elements.

Element Lists
An Element List is of the form:

Number Unit ElementName, Number Unit ElementName, ...

Where  is an integer number;   is   (drams) for dry elements or   for wet elements; and   is an identifier.

Solvents
The general form of a solvent declaration is:

Number oz SolventName

Where  is an integer and   is either   or. may only be used as a solvent if all of the elements in the reaction are water-soluble. is a universal solvent, but it may be used only in an amount equal to its substance number (813) times the number of ingredients in the reaction. If this amount is overrun by a reaction, then the reaction immediately following must not use Alkahest.

The amount of solvent used for a reaction must be exactly equal to the amount required for the ingredients. Dry ingredients require  or   per dram, and wet ingredients require   or   per ounce.

Explosions
Every error that can occur in a program as a direct result of the programmer's carelessness causes an Explosion. All Explosions are fatal. The interpreter deletes all files in the same folder as any source file that Explodes.

The following Explosions are defined:


 * Substance Explosion - Element amounts do not produce the same values.
 * Insufficient Alkahest Explosion - The reaction attempted to use Alkahest when the supply was depleted.
 * Insolubility Explosion - Not all given elements are soluble in water.
 * Excessive Solvent Explosion - Too much solvent was supplied for the reaction.
 * Insufficient Solvent Explosion - Not enough solvent was supplied for the reaction.
 * Ambiguous Step Explosion - Attempted to declare a duplicate line label.
 * Undefined Step Explosion - Attempted to jump to a nonexistent line label.

More might follow.

Snippets
The following commented snippet computes the product of  and   and stores the result in.

( Mercurius has a substance number of 959. ) ( Saturnium has a substance number of 968. ) ( The least common multiple of 959 and 968 is 928312. ) ( The amount of Mercurius required is 928312/959 or 968 drams. ) ( The amount of Saturnium required is 928312/968 or 959 drams. ) ( Mercurius is dry, so it requires 1 oz Alkahest per dram. ) ( Saturnium is wet, so it requires 2 oz Alkahest per dram. ) ( The amount of Alkahest required is 1*959+2*968 or 2895 ounces. ) ( The amount of Alkahest used is greater than the substance of Alkahest(813), ) ( times the number of elements (2), so the supply of Alkahest is depleted. ) ( The product should therefore be water-soluble, ) ( so the next reaction doesn't try to use Alkahest. )

Fuse 968 dr Mercurius, 959 dr Saturnium (2895 oz Alkahest): Aquariatus

Full Examples
(I don't have all day!)

External resources

 * Alchemy interpreter by User:Shadwick on Bitbucket