Parse this sic
Parse this sic is an esoteric programming language by User:Digital Hunter. The name has a cute double meaning, and also serves to continue the pattern of languages I've created that end with "ic".
If there's anything that needs clarification please bring it up on the talk page. If there are any glaring errors use your best judgement on how to clear them up.
Language overview
Parse this sic, or PTS, is a stackbased language with selfmodifying code, built on the premise of the "word" datatype. Each word is essentially a string (but calling them strings is cursed and illegal) with an attached numeric value, and from this point forth words will be described with double quotes (as any string would). Anything that evaluates to a word can be passed to a parenthetical expression, and is known as a label. How exactly words' values are determined will be described in detail later. The null word is a special word that looks like an empty string, and is the shortest word with a value of zero.
Whitespace is never ignored, and words can and probably will contain interesting whitespace characters that an implementation must handle neatly. Additionally, whitespace contributes to the character count of a program which will matter to you in a few minutes if you're reading this for the first time.
Certain expressions will evaluate to a number, which is the natural result of performing arithmetic. The program itself will keep track of the correct value with a word that suffices, and the programmer can assume that any given number will always be mapped to the same representative word. A good implementation would store all numbers as the shortest word with the correct value. A list of the shortest words with specific values will eventually be provided. To either eliminate or espouse your confusion, this page will be written with normal base10 numerals unless otherwise specified, and with the hope that you don't think too hard about the fact that every base is base10.
Every character in your source code is given an index, with the first given index 1 and the last given index 0. Indices increase from left to right by one per character, and wrap around the edges. For example, in
((1&&))*=
, the =
at the very end has indices 0, 9, 9, 18, 18, and I think you can see the pattern. Yes, it does get annoying to keep track of indices in long programs where the code that needs indices changes the length of all the code and you have a lot of things all depending on each other. No, nobody's doing anything about it.
Character indices wrap because code execution wraps around the edges. A program without a proper terminating case will thus repeat indefinitely.
Commands and keywords
Commands are commands, and keywords are special words that change the effects of a threeparameter parenthetical. This is a basic overview of their properties.
Command or keyword  Description 

+

Pops a word off the stack and jumps to the character in the program matching the index of the word's value. Technically evaluates to that word but this is nearly unusable. Is NOP if stack is empty. 


Flips the code reading direction between LTR (default) and RTL. Also flips the indices of every character. Technically evaluates to the null word but this is nearly unusable. Parentheses pair the same way regardless of code direction; a single parenthesis can act as either an open or a close. 
*

Pops a word off the stack and evaluates to it as a label if inside a parenthetical, outputs the word otherwise. Is NOP if stack is empty. 
/

If the code direction is LTR and the value of the word on top of the stack is less than 1, skip to past the next / found.
If the code direction is RTL and the value of the word on top of the stack is greater than 0, skip to past the next Technically evaluates to the word peeked at but this is nearly unusable. 
&

Tells the program to stop reading a word. Creates a label to that word to which the whole bit (as in bunch) evaluates. 


Skips to past the next  in the code. Please don't ever make use of the fact that this evaluates to the null word. Do realise that this can be used as almost comments. However, the most effective way to write comments is to surround them with & on both sides.

=

Kills program execution. 
()

Parenthetical expressions come in four flavours: zeroparameter, oneparameter, twoparameter, and threeparameter. They will be described more clearly later. 
Anything else  Activates program wordreading. 
"ameliorate"

When the first parameter in a threeparam evaluates to "ameliorate" exactly, the parenthetical evaluates to a word with the value of the sum of the other two parameters. 
"dominate"

Same deal as above; evaluates to the third subtracted from the second. 
"times"

Same deal as above; evaluates to the product of the other two. 
"spaces"

Same deal as above; evaluates to the integer quotient where the second is the dividend and the third is the divisor. If the third has a value of zero, evaluates to the null word. 
"walking"

Same deal as above; the second parameter is interpreted as a PTS program operating on the same stack as the main program, but with independent indices. All zeroparams immediately evaluate to the third parameter. The whole expression evaluates to the concatenation of everything output from the miniprogram through * (null word if no output from miniprogram). However  this is IMPORTANT  the altered stack is the ONLY side effect of the miniprogram.

"succeed"

Same deal as above; the first (determined by code direction) instance after the closing parenthesis of this expression of a substring of the code that matches the second parameter exactly will be replaced with the third parameter, with the search wrapping around the edges. If no replacement can be made, evaluate to the null word. If a replacement is made, evaluate to the word that was replaced (the second parameter). 
"ditto"

Same deal as above; evaluates to the second parameter if the second and third parameter match. Evaluates to the null word otherwise. 
A neat 7command 7keyword situation.
More on words
Words are neat because they serve the function of both a string and a number. Note: I put number in italics when referring to numbers, those interesting technical words that result from an arithmetic threeparam.
When the time comes to determine the value of a word, its equivalent string is searched through characterbycharacter from the beginning until a valid digit is encountred. A digit qualifies as any 0..9
or A..Z
character (casesensitive), and the first digit found will determine the base in which the rest of the word is read as a number  0 indicates unary, 1 indicates binary, Z indicates uhh base36. Every nondigit will be ignored when calculating the value of the word from then on.
For example, the word "140f9ai392(324"
has a value equal to 2 (with or without the quotes!), because the word is read as the binary number 10. A nice consequence of PTS's number system is that both "0" and "1" have the same value.
In code, words are generally first created with a word literal. When the program is run, if a noncommand character is encountred it is treated as the first character in a word and wordreading mode is activated. Every character read from then on is added to the word, until &
is found. This ends the word reading and creates a label to the word that was just read, which can then be passed to a parenthetical or just discarded (but why would you ever want to do that? So cruel). For example,
140f9ai392(324&
will act as a label to the word "140f9ai392(324"
that is destined to do many great things. Do ignore the fact that this label is immediately discarded. Other than wasting memory, however, floating labels are helpful for word values that may be used later, or for placeholders with the "succeed"
functionality. Additionally, marking comments and whitespace for readability with &
will likely be used in larger programs so an implementation should be able to handle it effectively.
Parenthetical expressions
At long last.
Zeroparam
First comes the zeroparam. ()
is the sole example. When encountred in a program ordinarily, the user will be prompted for an input, which is automatically cast as a word. The zeroparam will then evaluate to that word if passed to an outside parenthetical. However, in a "walking"
miniprogram, zeroparams will not prompt for input but instead evaluate to the third parameter from the outside program as described earlier.
Oneparam
Next comes the oneparam. (oneparam&)
is a valid oneparam, with the word "oneparam"
as its one parameter. Anything that evaluates to a word can be passed to a oneparam. A oneparam's sole purpose is to push its parameter onto the stack, but it also evaluates to that word and can be used to do many things. It can even be passed to itself, like ((darkness&))
, and push the same word twice!
Twoparam
Third comes the twoparam. (1f1sh&2f0sh&)
is a valid twoparam, where "1f1sh"
and "2f0sh"
are its parameters. A twoparam sees the entire program as one long (and technically infinite) word, and evaluates to the word that is the substring marked off with the indices determined by the values of its parameters, inclusive. This was incredibly wordy, so here's an example.
uncopyrightable&(3&6&)(D&A&)(1&&)(0&&)=
This code first creates a label to the word "uncopyrightable"
which is immediately discarded. Sorry. Anyway, the first twoparam looks at character 3 and character 6 to evaluate to "copy"
and then also be immediately discarded. The next twoparam evaluates to "bath"
. The final two both look from the very first (value 1) to the very last (value 0 (the second &
labels the null word)) characters, and both evaluate to "uncopyrightable&(3&6&)(D&A&)(1&&)(0&&)="
which is the entire program. This makes it very easy to create pretty lame quines, because the source code can always be directly accessed by PTS programs, but interesting/traditional quines can still be written with other means.
Threeparam
At even longer last, the threeparam. (perowanfe&word1&word2&)
is a valid threeparam. But wait, "perowanfe"
isn't one of the keywords listed with the handy acronym Astute Dinosaur Thinks Stars Want Some Dinner! This is fine, because the threeparam combines the functionality of functions with the equivalent of variable assignment and also word concatenation. Three uses for the threeparam.
Above were described the effects of threeparams if their first parameter evaluates to one of the keywords. In the example (perowanfe&word1&word2&)
, however, the second and third uses of the threeparam are demostrated concurrently. From this point on in the program, anything that evaluates to "perowanfe"
such as perowanfe&
will instead evaluate to "word1word2"
 unless it is the first parameter of a threeparam in which case the threeparam will act to reassign its value  hence the concatenative ability and pseudovariable assignment. Some examples assuming these examples were already executed somewhere prior:
(perowanfe&conch&shell&) & Anything that evaluates to "perowanfe" now evaluates to "conchshell" (instead of "word1word2") & (word1word2&conch&shell&) & Anything that evaluates to either "perowanfe" or "word1word2" now evaluates to "conchshell" & (variable&New_Value&&) & Anything that evaluates to "variable" now points to "New_Value" &
For convenience, if the second or third parameters in a redefinitionstyle threeparam is the null word, then the first parameter will point to the exact value of the nonnullword parameter. This is to make working with numbers not a complete pain in the backside.
Parenthetical expressions can (and will) be nested, and are evaluated in the order of code direction, deepest first; if the code is LTR then the program will "enter" any parentheticals it sees from the left, and go as deep as possible. This matters for, say, the effects of stack manipulation. Parentheses pair the same way regardless of code direction  any given (
could act as an open or a close.
Numbers
It is specified that it is unspecified how any program will represent internally any given number that isn't 0 (by the null word) or 2..35 (by the digits 2..Z), and any programs written in PTS must assume that numbers other than those 35 cannot be trusted (for output purposes). Note: 1 is not included in those safe numbers because both "0"
and "1"
are valid words with value 1 as mentioned above somewhere.
To argue this reasoning, take for example the number 6 (negative six). A PTS snippet such as (dominate&3&9&)
will evaluate to that number 6, but because there is no word with value 6 the number does not exist. It can still be pushed to the stack and interacted with (though outputting it or any other number other than the safe numbers is undefined behaviour), but in your mind it should appear as a black indecipherable fog. This is how all numbers should be treated in PTS (again, other than the safe ones).
However, because these numbers obey all the same mathematical rules as the numbers you're used to, "conversion" of them to a word that when read in decimal is that number corresponding to the value of the number is possible with a simple baseconversion algorithm. In PTS, this is most readily achieved with a snippet of code that may be executed via "walking"
. For example:
((*))( &&&)/(S&)+/(&*)( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))/(413&)+/( &0& &)(&*)((spaces&*A&))(C&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(C&)+/(**)( &1& &)((spaces&*A&))(C&)+
is a simple (bidirectional!) algorithm whose purpose is to leave the element currently on top of the stack untouched but push a new word that reads as a baseA (base ten) numeral and then terminate (and return control to the part of the program that executed it with "walking"
). It is equivalent to the following (really bad) pseudocode:
duplicate the top of the stack set a variable (newline) to the null word if the top of the stack > 0 push the number that is (current top of stack) mod (A) if this new top of stack is > 0 if it is > 1 (checks by pushing the top of the stack  1) set the newline variable to the concatenation of (this top of stack digit) and (its prior value) discard the two extraneous top values replace the top with it integerdivided by A jump back to the very first ifcheck otherwise (it is equal to 1) set the newline variable to the concatenation of (the word "1") and (its prior value) discard the two extraneous top values replace the top with it integerdivided by A jump back to the very first ifcheck otherwise (it is equal to 0) set the newline variable to the concatenation of (the word "0") and (its prior value) discard the single extraneous top value replace the top with it integerdivided by A jump back to the very first ifcheck otherwise (it is zero and the process is done) discard the top of the stack (zero) push the newline pseudovariable's value to the stack kill execution
where a % b
is evaluated with a  (b * (a / b))
if /
means integer division, because PTS does not have a builtin modulo operator.
A simple functionish like this one is essential for any PTS program with meaningful numerical output, though it should be noted that this particular function is intended for use in a setting where negative numbers won't appear. Note that this little algorithm will work (as long as the bounds are correct) regardless of the code direction when it is run with "walking"
(the sideeffect of swapping code direction does not last).
A similar function with the reverse effect can be written as well, interpreting the word on top of the stack as a decimal number that is converted to a (unspecified) PTScompatible form:
(p&&(dominate&p&1&))((ditto&(p&p&)H&))/(&*)( &)=/(&*)( &&(times&A& &))(2&)((ditto&(p&p&)0&))/(&*)+/( &*(ameliorate&(p&p&) &))+((*&%&deeccus))(&&& )(&1&&p)&H%
The most effective (and only) way to use some of PTS's commands is using numbers, however, so it is essential that you can come up with words with the right value on the fly. You can find a list here of numbers that you can use as a lookup table of sorts when writing PTS programs.
Example programs
These examples will eventually be followed up with explanations and prefaced with the knowledge required to understand them and hopefully debug them.
Hello, world!
The simplest one pushes the word "Hello, world!"
to the stack to be outputted.
(Hello, world!&)*=
Quite a fun one:
((Saying&the following&))*=Hello, world!
The Rth character just so happens to be the =
, so "Saying"
points to the first character after that (the Sth character is H
here) and "the following"
points to the last character.
Cat program
This one will prompt the user for word (basically string) input indefinitely.
(())*
Input is taken, pushed to the stack, and outputted, and program execution wraps around to do it all again. Adding a =
to the end will make it a simple terminating cat.
Reverse cat
(succeed&%&())(&)+=*(&%)
Takes an input and reprints it reversed, demonstrating the basic principle behind .. a nonterminating example:
(%&)=+((()&%&deeccus))+(&1)*(()(&&O)&gniklaw)
Note that the "succeed"
is never called in the main program; the side effect of replacing the %
with the input is therefore limited only to each instance of that code being called with "walking"
. Because I'm silly, I wrote this code with the intention of it being RTL without realising that it works just fine (and identically) LTR.
ROT13 cipher
(p&&301&)NOPQRSTUVWXYZABCDEFGHIJKLM&(succeed&&())p&(((p&(ameliorate&p&1&)&)p&))((ditto&(*)p&))/=/*/(((*)*))*/*_&
Simple and lazy implementation of a ROT13 encoder/decoder. Uses the fact that capital letters have a numerical value in PTS; does not work for lowercase letters. Ignores all other characters as it should, except for the digits 0123456789
which also behave interestingly.
Does not work if input begins with a character that is a PTS instruction other than 
, or contains a &
anywhere followed by any PTS instruction other than 
.
Infinite loop
While any PTS program without a =
is trivially an infinite loop, here's one infinitelyexecuted program that neither reaches the end nor has any +
.
(succeed&&(1&&))
A good implementation will crash upon trying to run it (the program length doubles with each iteration).
Here's a similar program that will lead to some kind of recursion error:
(walking&(1&&)&)
Factorial
Prompts the user for input of something whose value will be evaluated in the normal PTS way (use unary or binary input to be safe), and outputs whatever the implementation decides is the best way to represent the number that is the input's factorial.
/((times&(*)(walking&(1&&)(dominate&*1&))))*=*(&1)(*&)/(())
For example, inputting "5"
could output:
"AA"
 best implementation!"1111000"
 understandable"00000.."
(120 times)  ☃
That example uses recursion which prevents it from involving a converttobaseA segment easily while still showcasing the use of PTS's builtins "intuitively", but it's still a neat little program that does the right job by basically assuming that it does the job of outputting the factorial and simply passing the torch to a "walking"
call of itself to find the factorial of one less than its own job, with the base case of 0! = 1.
The following solution does output the base2 represented factorial of the input, with a simple converttobase2 operation built right into the code:
(Input a number to be factorialed below. Note this needs a PTS number so use binary or unary to be safe! Input: &)*((( &&())))(Factorial of &)**( in binary is: &)* ^ This'll take an input, use newline as our "counter", and also pushes it to the stack Now, we're going to push each number less than that input onto the stack until we reach 0 Something like [5] becomes [5 4 3 2 1 0] &/((dominate&(*)1&))(J6&)+/(Then the top of the stack is cleared &*) and the goal now is to perform a loop where the top two stack values are popped and their product is pushed. By decrementing the value in our counter and checking that it stays above zero, this sort of loop functionality is achieved! &(( &&(dominate& &1&)))/(&*)((times&**))(845&)+ < this is just that multiplying step /( Now, we have the completed factorial on top of the stack as intended. The only problem here is that it's in the form of a PTS "number"! The next step is just to convert it to a consistent form, and I've chosen to stick with using binary (I feel like unary would end the universe) &*)( &&&)//( &)*( &)*= That bit of code there is the end condition, just output whatever's in our new use of newline as our binary word placeholder. We push to the stack our factorial modulo 2, which conveniently in PTS logic falls on both ends of the slash command (technically we use ditto instead of dominate because there are only two cases in binary and it's just slightly shorter) ((ditto&(*)(times&(spaces&(*)2&)2&)))/( &0& &) if they're the same, put a 0 in front of our placeholder concatenation thingy and then jump to the final step /( &1& &) if they're not the same then put a 1 in front of our placeholder and continue to the final step  < this is a "universal landing pad" sort of structure! > &(&*)((spaces&* divide by 2 for the next iteration ... &))(WD ... and jump back to repeat > &)+ until the top of the stack is zero and the base conversion is complete
Here's the same program, minimised:
(( &&()))/((dominate&(*)1&))(A&)+/(&*)(( &&(dominate& &1&)))/(&*)((times&**))(100111&)+/(&*)/(413&)+/( &)*=((ditto&(*)(times&(spaces&(*)2&)2&)))/( &0& &)/( &1& &)_&(&*)((spaces&*2&))(93&)+
Unary and binary are the only two bases that have a valid inPTS representation for every number, and because this particular program is singleinput singleoutput it can conveniently be plugged into any larger program to be run with "walking"
to produce a meaningful value. If used in such a way, it may be more efficient to operate directly on the top of the stack, and this can be done by simply replacing the ()
at the start with a *
and deleting the *
in the middle by the =
.
Fibonacci numbers
The following prompts the user for n (interpreted as a PTS number  unary or binary to be safe) and outputs the nth Fibonacci number (in decimal!), if the 0th and 1st are 0 and 1, and each next term is the sum of the previous two.
(&)(1&)(( &&(dominate&()1&)))/(&*)(82&)+/((ameliorate&*1&))/(1&)*=/(0&)*=( &)( &&(dominate& &1&))/(&*)(walking&(C0&DB_&)&)(82&)+/(&*)(walking&(DC_&&)&)*= &(t&&*)(b&&(ameliorate&t&(*)))(t&)(b&)=( &&&)/(K&)+/*( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))/(96&)+/*( &0& &)((spaces&*A&))(7&)+((dominate&(*)1&))/*( &* &)((spaces&*A&))(7&)+/**( &1& &)((spaces&*A&))(7&)+
If the user inputs "9" or "1001" or "000000000", the program will output "34".
Kolakoski sequence
The first three terms are hardcoded. This program has no end condition and will continue indefinitely.
(1,2,2,&)*(p&&D4&)_/*&(((p&(ameliorate&p&1&)&)p&))/((dominate&*1&))(succeed&%&1%&)(1,&)*(303&)+ /*(((p&(ameliorate&p&1&)&)p&))/((dominate&*1&))(succeed&(&&)(c&2&(&&)))(2,&)*(1111111&)+122%
ThueMorse sequence
This program has no end condition and will continue indefinitely.
(0&)*(succeed&((a&&0&)R&)&)/+(&&&a)((&1*&p))((&%&a&a)&%&deeccus)/((&p(&(&1&p&etaroilema)&p)))&((ditto&*0&))/(a&a&(1&))/(a&a&(0&))_&*(&*)_&%&
Lookandsay sequence
Uses the version also known as the "Say what you see sequence"; the rule starting with "1"
and continuing indefinitely. No end condition.
(o&&,&)(succeed&((n&&1&)T&)&)/(s&&*)(c&&1&)(&3*&p)(&&&n)(&*&o)(*&o&deeccus)*((((&,&n&t))))/((&p&p))& ((((dominate&)1&(p&&(ameliorate&p&1&)))(*1&p&)))((ditto&(*)s&))/(**)(c&&(ameliorate&c&1&))(G&)+ /(**)(n&n&(t&c&s&))(1&)+,_
Collatz sequence
Short program that outputs the chain of numbers associated with the function associated with the Collatz conjecture, in the usual baseambiguous PTS way.
(())&((dominate&(*)1&))/_/=&(&*)((dominate&(*)(times&(t&(spaces&*2&)&)2&)))/(t&(ameliorate&(times&t&6&)4&)&)_/&(&*)((t&))*(,&)*_
Expanding upon the logic to slot in baseconversion is possible and simple.
Truthmachines
/*(1&)(3&)+=*(&0)/((&1()&ottid))
There is a shorterbyonechar version that does the same job but is simply less interesting:
((ditto&()1&))/(G&)(1&)*+/(0&)*=
On account of the fact that it's "straightforward" to see what's going on.
Roman numerals
Secondshortest program (single extraneous newline) the author could find implementing some sort of Roman numeral system. Input PTS number (unary/binary to be easy) up to "F9F"
, outputs strict Roman numeral evaluation.
(())((dominate&*1&))/(succeed&I&II&)(5&)+//(I&)*= (&*)((((((((((((succeed&))))))))))))((*IIIII&V&))//*((*IIII&IV&))/ &/*((*VV&X&))/ &/*((*VIV&IX&))/ &/*((*XXXXX&L&))/ &/*((*XXXX&XL&))/ &/*((*LL&C&))/ &/*((*LXL&XC&))/ &/*((*CCCCC&D&))/ &/*((*CCCC&CD&))/ &/*((*DD&M&))/ &/*((*DCD&CM&))/ &/.&
The upper bound is arbitraryish, because this program supports up to M and its author still does not quite understand the rules of Roman numerals.
Because of the absolute mess left on the stack after this program finishes, it is not recommended for use in any reasonable setting and exists only for demonstrative purposes.
Digital root
Contrary to what is said on the digital root calculator page, such a program in PTS is less than easy due to its lack of decimal bias.
The following program is really 3 "functions" and a master program in disguise: one to interpret a decimal input, one that converts valid PTS values to a decimalreadable form, and one that finds the sum of the digits of a supplied (assumed) decimal value.
( &&&)/(K&)+/*( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))/(96&)+/*( &0& &)((spaces&*A&))(7&)+((dominate&(*)1&))/*( &* &)((spaces&*A&))(7&)+/**( &1& &)((spaces&*A&))(7&)+((( &&(dominate& &1&)) &))((ditto&(*)H&))/**=/*((ditto&(*)0&))/**(2&)+/*((ameliorate&**))(2&)+(((*&%&deeccus)))(&1&& )&H%( &&(dominate& &1&))((ditto&( & &)H&))/(&*)(K4&)+/(&*)((times&*A&))((ditto&( & &)0&))/(&*)(2&)+/(&*)((ameliorate&*( & &)))(2&)+((dominate&(*)9&))/(&*)(walking&(3&&)&)(walking&(20110&601&)&)(K4&)+/(&*)*=+(((()&$&deeccus)))(&1&& )&H$
It essentially works the bruteforce way, repeatedly first converting the value on top of the stack to decimal and then summing the digits until it is less than 10.
Using the 1+(n1)%9
trick makes a much shorter program:
( &&(dominate& &1&))((ditto&( & &)H&))/(&*)/*((times&*A&))((ditto&( & &)0&))/(&*)(2&)+/*((ameliorate&*( & &)))(2&)+((dominate&*1 &))((dominate&(*)(times&(spaces&*9&)9 &)))/((ameliorate&*1&))*=*(&1)/ +(((()&%&deeccus)))(&1&& )&H%
Note that there are 3 and only 3 newline ('\n') characters in the above that are there for aesthetics; it will be left as an exercise to the reader to determine which three.
Square root calculator
Takes two integers, and finds the square root of the first to the precision of the second.
(Input below an integer you'd like to find the square root of, and then approximately the number of digits of precision you want Input both in decimal (base ten) Square root of: &)*((()))( Number of digits: &)*(d&&())( Square root of &)**( is: &)* (p&&(dominate&p&1&))(2&)((p&p&))((ditto&(*)H&))/***( &)=/( &*(times&A& &))((ditto&(*)0&))/**+/( &*(ameliorate&* &))+((*&%&deeccus))(&&& )(&1&&p)&H%(succeed&( &&%&)*)(((dominate& &1&) &))( &&(dominate& &2&))((ditto&(*)_A&))/**= /*((dominate&(*)A0&))/( &&*)*( &)= /(&*)(J&)+_A%(d&)(walking&(FB&JI&)&)(d&&*) &(walking&(JJ&MK&)&)(s&&&)(m&&&)(a&&&) &//(TS&)+(walking&(FB&JI&)&)(m&(ameliorate&(times&m&400&)*)&) &(t&&9&)((dominate&m&(times&(ameliorate&(times&s&A&)t&)t&)))((ameliorate&(*)1&))/(&*)/(**)(t&(dominate&t&1&)&)(PJ&)+ (m&&*)(s&(ameliorate&(times&s&A&)(times&t&2&))&)(t&)//(a&a&0&)((dominate&*1&))/(a&a&t&)_&/(a&a&1&)_&(&*)(4343&)+ (a&a&.&)((d&(dominate&d&1&)&))//(Y5&)+(m&(times&m&400&)&) &(t&&9&)((dominate&m&(times&(ameliorate&(times&s&A&)t&)t&)))((ameliorate&(*)1&))/(&*)/(**)(t&(dominate&t&1&)&)(966&)+ (m&&*)(s&(ameliorate&(times&s&A&)(times&t&2&))&)(t&)//(a&a&0&)((dominate&*1&))/(a&a&t&)_&/(a&a&1&)_&(&*)(906&)+ (a&)*=
Prime number generator
Takes a PTS number input and lists out (in decimal) all the prime numbers up to and including that input using a sort of Sieve of Eratosthenes approach. Output is separated by " "
characters.
(())(A7&)+ (&)(//(411&)+((dominate&(*)(times& &(spaces&(*) &))))/(&*)(succeed& (&(c&(2&6&)*))/(**)_&(8&)+ (&)=/((dominate&(*)1&))(A7&)+/(**)/( &&*)(walking&(B&A6&)&)( &)(walking&(E3&&)&)*( &)*(10010011&)+/=( &&&)//*( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))//*( &0& &)((spaces&*A&))(7&)+((dominate&(*)1&))/*( &* &)((spaces&*A&))(7&)+/**( &1& &)((spaces&*A&))(7&)+
The difficult part of implementing an eratosthesieve in PTS is that the stack cannot be looked through trivially; this hurdle is overcome by making use of PTS code's ability to edit itself. As the stack is read back in the main logicdense part of this particular program, stack elements that survive the sieve are popped while some code that comes later is modified to have extra oneparams that'll push everything back onto the stack (so deeper elements can be tested as well).
Pi calculator
Takes a PTS number input and outputs some decimal approximation to pi (3.14159265...) whose accuracy vaguely corresponds to the input.
(())( &&8&)/((dominate&*1&))( &&(times&A& &))(C&)+/(c&& &)( &&&)((ameliorate&(spaces&c&(times&(ameliorate&(times& &4&)1&)(ameliorate&3&(times&4& &))))*))((spaces&c&(times&(ameliorate&(times& &4&)1&)(ameliorate&3&(times&4& &)))))/(&*)( &&(ameliorate&1& &))(2102&)+ /( &*&)//(&*)( &)*=((dominate&(*)(times&(spaces&(*)A&)A&)))//(&*)( &0& &)((spaces&*A&))(G0&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(G0&)+/(**)( &1& &)((spaces&*A&))(G0&)+
For example, inputting "C"
outputs "3141591620995"
while "5"
gives "313837"
. Execution takes about A times longer for each increment of whatever's input.
This particular program uses Leibniz's approximation of pi, a special case of the inverse tangent formula.
Phi calculator
Takes a PTS number input and outputs some decimal approximation to phi (1.6180339887...) whose accuracy vaguely corresponds to the input.
((c&&()))(D5&)+( &&(dominate&*1&))(&)(1&)( &)/*/((ameliorate&*1&))/(1&)=/(0&)=( &)( &&(dominate& &1&))/*(walking&(B3&&)&)(2110&)+/*(t&&*)(&*)(t&)= (t&&*)(b&&(ameliorate&t&*))(t&)(b&)= (walking&(G&&)&)((ameliorate&c&1&))(walking&(G&&)&)( &&1&)(c&)/(&*)(c&&(dominate&c&2&))( &&(times&A& &))(F5&)+/(&*)((spaces&(times&* &)*))( &&&)//(&*)( &)*=((dominate&(*)(times&(spaces&(*)A&)A&)))//(&*)( &0& &)((spaces&*A&))(652&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(652&)+/(**)( &1& &)((spaces&*A&))(652&)+
For example, inputting "Q"
outputs "16180339887802"
while "9"
gives "161764"
. Unlike the pi calculator, this one handles inputs as large as "ZZ"
easily.
This particular program determines phi as the ratio of consecutive (big) Fibonacci numbers.
Euler's number calculator
Takes a PTS number input and outputs some decimal approximation to e (2.718281828...) whose accuracy vaguely corresponds to the input.
(i&&())(c&&( &&1&))(i&)/(&*)(1&)(1&)(1&)((times& &2&))(1&)(1&)(c&&(times&V8&c&))( &&(ameliorate&1& &))(i&&(dominate&i&1&))(K&)+/(&*)(t&&(d&&*))(n&&*) &/(d&&(ameliorate&n&(times&d&*)))(n&&(times&t&*))(t&&d&)(10011000&)+ /((spaces&(times&(ameliorate&(times&d&2&)n&)c&)d&))( &&&)//(&*)( &)*=((dominate&(*)(times&(spaces&(*)A&)A&)))//(&*)( &0& &)((spaces&*A&))(G5&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(G5&)+/(**)( &1& &)((spaces&*A&))(G5&)+
For example, inputting "Z"
outputs "2718281828459045235360287471352662497757247093699959574966967627724076630353547594571382178525166427427466"
while "5"
gives "2718281828470583"
.
This particular program generates a truncated simple continued fraction representation of e on the stack which is simplified for an approximation.
FizzBuzz
Loops FizzBuzz from 1 to "410"
which is 105 in decimal (so it can finish with a FizzBuzz).
(&)((ditto&(*)(times&410&1&)))/=/*(((ameliorate&*1&)))(401&)+(&100100001)(&4)*(& )*(&(&&1)&gniklaw)+(&8B)((&A*&secaps))&_(& *& )*/&_(& &1& )**/((&1(*)&etanimod))/(& &0& )*/(((&A(&A(*)&secaps)&semit)(*)&etanimod))/=(& )*/=(& )**/(&&& )*/(& )*&/_(&zzuB& & )/(((&5(&5(*)&secaps)&semit)(*)&etanimod))*&/_(&zziF&& )/(((&3(&3(*)&secaps)&semit)(*)&etanimod))(&&& )
Note the extra space (' ') at the start of the second line; some interpreters (such as the one this author is using) will incorrectly handle the side effect of redefining newline ('\n') that should be limited to only the "walking"
call (which leads to a messy doubleprinting scenario) and the cleanest solution is just to alter the printed separator invisibly.
99 bottles of beer
This one prints all ten verses of 9 Bottles of Beer with the typo "1 bottles of beer" because I'm lazy. A full program will follow, but this shorter example demonstrates the basic logic of a 99 bottles program. Note the newlines and the double newline in the middle. Necessary for proper spacing of the verses and changing this aesthetically will also require label changes.
(No&)*((3231&544&))*(No&)*((3231&EC&))*(! Go to the store, buy some more, &)*(9&)*((3231&550&))*(.&)*=+(&5)*(& .)*((&36&I))*/*(&oN)/(((&0*&etanimod)))*(& ,dnuora ti ssap ,nwod eno ekaT !)*((&X&I))*((*))*(& ,llaw eht no reeb fo selttob )*((*))/+(&)/(&9)
This particular program could be edited quite easily to almost be a proper 99, but runs into the particular problem that numbers' representations are unspecified. Even if they were specified, by the rules of PTS a decimalbiased song wouldn't be possible anyway  without a base conversion function.
Despite its shortcomings, it's a good example of PTS's flow control, and most prominently the changing behaviour of /
when reversed.
If the bulk of the program was written for LTR, changing the decision portions isn't difficult but adds length to the program which isn't great.
With all that in mind, this is a full 99 Bottles of Beer, complete with base conversion and good grammar.
(L4&)+ 99 bottles of beer written in Parsethissic =*(&.)*((&8F&3G))*(&99 ,erom emos yub ,erots eht ot oG !)*((&8F&111000001))*(&oN)*((&8F&5G))*(&oN .)*((&8F&3G))*(&oN)*((&EH&AI ))*(&reeb fo elttob 1)*((&000000001&5G))*(&elttob 1)(*&)[h]+(&525)*(& .)*((&8F&3G))*(&(&7D&1 )&gniklaw)((&1*&etanimod))*(& ,dnuora ti ssap ,nwod eno ekaT !)*((&8F&111000001))*(&(&7D&1 )&gniklaw)*(& ,llaw eht no reeb fo selttob )*(&(&7D&1 )&gniklaw)(*&)/+(&0K)/((&1(*)&etanimod))(&99)&((*))( &&&)/(S&)+/(&*)( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))/(413&)+/(&*)( &0& &)((spaces&*A&))(C&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(C&)+/(**)( &1& &)((spaces&*A&))(C&)+
For readability, some of my twoparams have a newline in one of their bound words that doesn't affect the value. Newlines and whitespace can always be interspersed in nonprinting words, though using spaces for character padding to make index counting easier is discouraged. Note the small [h]
hidden in the author's code that is in direct violation of the discouragement expressed in the previous sentence.
Deadfish interpreter
Prompts the user for input of a oneline idso Deadfish program. Note: this one doesn't seem to like outputting "1".
( &&&)/(N&)+/(&*)( &)=((dominate&(*)(times&(spaces&(*)A&)A&)))/(403&)+/( &0& &)(&*)((spaces&*A&))(7&)+((dominate&(*)1&))/(&*)( &* &)((spaces&*A&))(7&)+/(**)( &1& &)((spaces&*A&))(7&)+((ditto& &(ameliorate&FF&1&)))/( &&&)/((ameliorate& &1&))/(100001001&)+/( &&&)(**)(p&&(dominate&p&1&))((ditto&(p&p&)i&))/(&*)( &&(ameliorate&1& &))(2&)+/(&*)((ditto&(p&p&)d&))/(&*)( &&(dominate& &1&))(2&)+/(&*)((ditto&(p&p&)s&))/(&*)( &&(times& & &))(2&)+/(&*)((ditto&(p&p&)o&))/(&*)( &)(walking&(3&D1&)&)*( &)*(2&)+/( &*)((ditto&(p&p&)H&))/=/(&*)(2 &)+((()&%&deeccus))(&&& )(&1&&p)(&O&&o)(&S&&s)(&D&&d)(&I&&i)&H%
Because this is the PTS wiki page, the author of this program will provide an explanation for it, with the convention that RTL code is shown with the wrong parenthesis types for readability.
Program execution hits the 
at the start to read RTL from the very end. The relevant part of the program now is
%H&(i&&I&)(d&&D&)(s&&S&)(o&&O&)(p&&1&)( &&&)((succeed&%&()))+[ et cetera ]
. %
is not a command and so starts wordreading, ended by &
. The first four threeparams make it so that any word evaluating to one of idso will point to their capitalised variant, with the unfortunate sideeffect that this interpreter accepts caseinsensitive Deadfish, but this step is important because "ditto"
cannot do anything useful if the words it compares have zero value (like lowercase letters). The next threeparam establishes "p"
as a pointer of sorts, keeping track of which Deadfish instruction is next to be executed. The last threeparam initialises the newline to act as this program's accumulator "variable", that will keep track of the Deadfish program's accumulator. The H
will mark the end of the Deadfish program later.
We're left with ((succeed&%&()))+
. There's a oneparam that will push the value of (succeed&%&())
to the stack; this threeparam looks through the entire program for the first %
to replace with user input. This just so happens to be the %
from the very start, so if the user inputs "diissiso"
the snippet looks now like
diissisoH&(i&&I&)(d&&D&)(s&&S&)(o&&O&)(p&&1&)( &&&)((succeed&%&()))+
which acts to store the Deadfish code safely at the very end of the main program (remember that this snippet is backward). (succeed&%&())
evaluates to "%"
which is pushed to the stack, +
pops it and sees its value as zero, sending the program back to the end (/start) 
.
Program execution is sent back to LTR, and the code from indices "3"
to "D1"
is conveniently skipped over by  < these > 
. Note that this skipped code is in fact quite similar to the baseconversionofthetopofstack function showcased earlier on this page. The rest of the PTS program is quite straightforward, if the reader may first accept that each "check" pushes its value to the stack to be peeked by /
and this value is immediately discarded to keep the stack clean:
 Check if the accumulator's number matches the number equal in value to
(ameliorate&FF&1&)
(256)  if so, set the accumulator back to null.  Check if the accumulator's number is (1) by testing the greaterthanzeroness of oneplustheaccumulator. After these first two tests the top two extraneous stack values are discarded.
 Decrement the number evaluated to by
"p"
. The first time, this makes it point to the last (index zero) character in the PTS program, the first character in the Deadfish program. Each time after, it points to the next character in the Deadfish program.  Check if the character pointed to by
"p"
matches"i"
 if so, increment the accumulator and jump back to index"2"
, which is the first
which will skip past the converttobaseA function and restart from the beginning of this list.  Repeat the above bullet for Deadfish
"d"
and decrementing.  Repeat the above bullet for Deadfish
"s"
and squaring.  Repeat the above bullet for Deadfish
"o"
, but push to the stack the current number of the accumulator,"walking"
run the converttobaseA function, pop and output the new top of the stack, and also output a space before jumping back.  If the character pointed to by
"p"
happens to be a "H", this means either the Deadfish code is depleted or contains a capital H for some reason, so the PTS program ends.  If none of those checks succeeded then we may as well jump back to the start, because why not. The stack is cleared and the program jumps back to
"2"
.
Note that although the baseconvert algorithm redefines newline for use in its evaluation, this is limited in scope to only when it is called with "walking"
and does not affect the value of the main program's accumulator.
This program also demonstrates the three ways of storing information in PTS:
 The stack: most reliable, but can be unwieldy at times.
 Threeparam pseudovariableassignment: can actually be the best (variables are powerful, after all) but because of PTS's quirky treatment of numberical words should be used carefully.
 Modifying the source with
"succeed"
and reading it back with twoparams: be very careful when doing this, but it is the only way for a PTS program to break a word apart and understand it in any meaningful way beyond the simple PTS builtins.
Computational class
Parse this sic is Turingcomplete, by virtue of there being an almostUnderload interpreter written in it. If the Underload commands ~:!*()^aS
are substituted with WDIGPCRAS
, the following PTS program takes this semiUnderload code as input.
(succeed&$&())(succeed&)((OB&OB&))((ditto&H&(*)))/= /*((ditto&W&(*)))/(**)(*W&&)(t&&*)(b&&*)(t&)(b&) /*((ditto&D&(*)))/(**)(*D&&)((*))_& /*((ditto&I&(*)))/(**)(*I&&)(&*)_& /*((ditto&A&(*)))/(**)(*A&&)((t&(t&P&*)C&))_& /*((ditto&S&(*)))/(**)(*S&&)*_& /*((ditto&G&(*)))/(**)(*G&&)(t&&*)((t&*t&))_& /*((ditto&R&(*)))/(**)(*R&*)_&(F&)+ /*((ditto&P&(*)))/((**)*) /(Error!!&)*=(b&&OB&)(t&&1&)(t&)/ /(&*)((succeed&(OC&(dominate&b&1&))&))(succeed&PC&&)(F&)+ (&*)(((b&(ameliorate&b&1&)&)b&))((ditto&(*)C&))/(**)(t&(dominate&t&1&)&) /*((ditto&(*)P&))/(**)(t&(ameliorate&t&1&)&)_& /(**)_&(110010001&)+$H
Underload is Turingcomplete, so the trivial WDIGPCRAS derivative is as well. For demonstrative purposes, this is a PTS program that takes an Underload program as input and converts it into something the above program can read.
(&)(~&*W&)(:&&D&)(!&&I&)((7&7&)&G&)((1&1&)&P&)((3&3&)&C&)(^&&R&)(a&&A&)(p&&10011010&)(succeed& &())(((p&(ameliorate&p&1&)&)p&))((ditto&(*)H&))/=/**(400&)+ H
Info to come
This wiki page is awaiting:
 Summary of stack manipulation
 Summary of flow control
 Indepth discussion of the commands
 Better organisation
 Probably some more category links
 Links