MoonPeanut Language Reference ----------------------------- MoonPeanut 0.0010 Created in 2005 by Edward Blake This language is basically ALPHA at the moment, things will change. This reference is just to get you started and not meant as a formal reference of the language. There may be many bugs with the interpreter as well. Language Paradigm ----------------- MoonPeanut relies heavily on functional practices (no goto for you!), stacks, reliance on only 26 global function handles (uppercase letters from A to Z). Function clauses are also equivalent to strings in that :: and "" create the same data structures, which might mean something for reflectivity. Function clauses can start with a backslash to add functional arguments, up to a pipe (e.g. \abc|). These lowercase arguments can then be used in the function body. Also note, function arguments are not available in scope to nested functions. Functions can be both called, pushed on the stack, and passed as arguments to be called by other functions. Function Calls -------------- Function calls will normally cause a normal stacked call _if_ the function is not the last part of a function body. If the function call happens on the last token of a function body (in the case of a conditional, if the ? is the last token of the function body), the function call will be tail recursive capable and will not keep an intensive return history. (All of this is transparent to the coder if he doesnt know what all this tail recursion business is about, until it comes to infinite call loops.) Language Elements ----------------- # Comment delimiter Probably the most important delimiter... : Function body delimiters Delimits a function body, which is technically the same as a string. " String body delimiters Delimits a string, which is technically the same as a function body. ' Quote This important character causes delayed evaluation of double quoted strings and colon'ed function bodies. Quotes are stripped as they travel through the evaluation parsers. The more the quotes, the less likely the following : and " characters will be handled. A-Z Function Handles Function handles are used to store function bodies for later execution, a function handle appearance by itself causes a function call, but a function handle appearance preceded by a comma (,) causes a function assignment with the last element in the stack. A function handle appearance preceded by a underscore causes the function handle itself to be pushed on the stack. a-z Function Arguments Function arguments are defined at the beginning of a function body between \ and |, they may appear anywhere within the current function body, but may not be embedded in function bodies within the current function body. An occurance of the function argument in the function body causes an eager evaluation (as opposed to lazy). , Assigner Used with function handles to assign functions to handles. _ modifier USed with function handles to push the handle onto the stack instead of its normal behaviour. ! Standard Output with Newline Causes the last stack entry to be printed, however it does not cause it to be removed from the stack. } Shovel Purges the stack. ? Conditional Takes 3 arguments, the closest from the right being the conditional, which should be pre-evaluated to either "1" or "0". A "0" causes the else-branch to be executed (which is the middle argument), and a "1" causes the if-branch to be executed (which is the leftest of the 3). The two branches should be function bodies. Function bodies in these conditionals may pick up some variables off the stack using an argument declaration. = Equality Quite literally just compares two strings. < Lesser than When the 2 last arguments on the stack are numbers, the operator works numerically, otherwise it is done lexicographically. > Greater than When the 2 last arguments on the stack are numbers, the operator works numerically, otherwise it is done lexicographically. + Add, or concatenate Adds the last two numbers on the stack together, or if they aren't both numbers, concatenates both strings together. - Subtract Subtracts the last two numbers on the stack together. It's effects on strings are not defined yet. * Multiply, or concatenate-and-trim Multiplies the last two numbers on the stack together, or if they aren't both numbers, concatenates both strings together and then trims spaces on both sides afterwards. / Divide Divides the last two numbers on the stack together. It's effects on strings are not defined yet. & And Ands the last two numbers on the stack together. It's effects on strings are not defined yet. | Or Ors the last two numbers on the stack together. It's effects on strings are not defined yet. ~ Not Inverses the last element in the stack. 0-9 Digits Digits are placed on the stack a digit at a time. Hello World in MoonPeanut ------------------------- "Hello World"! Disclaimer ---------- The author makes no warranties of any kind, either expressed or implied, including, but not limited to, this software's fitness for any particular purpose. The author takes no responsability from damages, including physical, mental and emotional, that may occur from the use of this software, including lost sleep. Use at own risk. Web Site -------- The MoonPeanut may be rediscovered on http://www.cyanwerks.com/moonpeanut