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.
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
The following elements are defined at the start of an Alchemy program, and have the indicated initial values.
(To be decided)
Steps may be given numeric labels with a declaration of the form:
Number is an integer.
The programmer may conditionally jump to a label:
ElementName is nonzero, then program execution jumps to Step
The general syntax of a reaction is:
ProcessName ElementList (Solvent): ProductName
ActionName is the alchemical process to be performed,
ElementList is a list of the names and amounts of the elements used in the reaction,
Solvent defines which solvent to use for the reaction, and
ProductName indicates the element to which the result of the reaction should be stored.
Calcinate- Divides the first element by all following.
Digest- Inputs a value for each element.
Putrefy- Subtracts all following elements from the first.
Coagulate- Calculates the arithmetic mean of all elements.
Fixate- Truncates the first element and returns it.
Cerate- Decrements the first element and returns it.
Distill- Returns the bitwise AND of all elements.
Sublimate- Returns the bitwise OR of all elements.
Filter- Returns the bitwise inverse of the first element.
Fuse- Returns the product of all elements.
Multiply- Outputs the value of each element.
Project- Returns the sum of all elements.
An Element List is of the form:
Number Unit ElementName, Number Unit ElementName, ...
Number is an integer number;
dr (drams) for dry elements or
oz for wet elements; and
ElementName is an identifier.
The general form of a solvent declaration is:
Number oz SolventName
Number is an integer and
SolventName is either
Water may only be used as a solvent if all of the elements in the reaction are water-soluble.
Alkahest 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
1 oz Alkahest or
2 oz Water per dram, and wet ingredients require
2 oz Alkahest or
3 oz Water per ounce.
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.
The following commented snippet computes the product of
Saturnium 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
(I don't have all day!)