,,,

From Esolang
Jump to navigation Jump to search

,,, (pronounced 'Commata' , plural of 'Comma') is another stack-based esolang made by totallyHuman. ,,, utilizes numerous lesser-used unicode characters to manipulate the stack. Some of these characters may not be even displayed in certain devices due to technical issues, making programming in the language sometimes extremely difficult. However, ,,, is significantly useful for golfing, making extra characters useless at most cases. Its filename extension is '.,,,'. ,,, is currently a work in progress, as it lacks numerous programming statements like loops.

Syntax

A ,,, program can consist of the following commands:

Character Functions
+ Pop the top 2 values and returns their sum. If they are strings, concatenate the second top string to the top string.
- Pop x and y, and push y-x.
× Pop the top 2 values and pushes their product. If one of the values is a string, then push it multiplied by the other number. e.g "banana" and "3" push "bananabananabanana".
÷ Pop x and y, and push y/x.
% Pop x and y, and push y mod x.
* Pop x and y, and push y to the power of x.
Replace the top value with its square root.
Pop and output the top value.
Drop the top value.
¬ Pop x. If x = 0, push 1, else, push 0. (Logical NOT)
Pop x and y. If either x = 0 or y = 0, push 0, else, push x (logical AND)
Pop x and y. If y = 0, push x, else, push y (logical OR)
i Convert top value to an integer. If the operation cannot take place, throw a ValueError.
f Convert top value to a float. If the operation cannot take place, throw a ValueError.
s Convert top value to a string. If the operation cannot take place, throw a ValueError.
c Convert top integer to a character.
o Convert top character to integer.
Pop x. Remove x characters from the start of the next top of the stack (Which should be a string).
Pop x. Retain the first x characters of the next top of the stack (Which should be a string).
Pop x. Retain the first letter of the top string, then remove the next x - 1 letters and repeat. e.g if x = 4 and the top of stack is "abcdefghij", the result will be "aei". If x = 2, then it would be "acegi".
& Pop x and y. Perform bitwise AND on x and y and push it.
| Pop x and y. Perform bitwise OR on x and y and push it.
^ Pop x and y. Perform bitwise XOR on x and y and push it.
~ Pop x. Perform bitwise NOT on x and push it.
« Pop x and y. Bit shift y to the left x times and push it. (Similar to pushing y * (2 ^ x))
» Pop x and y. Bit shift y to the right x times and push it.
: Pop x. Push x twice. (Duplicate x)
< Pop x and y. If y < x, push 1, else, push 0.
> Pop x and y. If y > x, push 1, else, push 0.
= Pop x and y. If y = x, push 1, else, push 0.
Pop x and y. If y ≤ x, push 1, else, push 0.
Pop x and y. If y ≥ x, push 1, else, push 0.
± Pop x. If x > 0, push 1, else if x < 0, push -1, else, push 0.
p Pop x. If x is prime, push 1, else, push 0.
Swap top two values.
Reverse the entire stack.
Pop x and push it to the bottom of the stack.
Pop x from the bottom of the stack and push it.
Pop everything in the stack and push (one of) the smallest value(s).
Pop everything in the stack and push (one of) the biggest value(s).
# Pop the entire stack and push their sum.
Pop the entire stack and push their product.

Note: If an empty stack is popped, an IndexError will be thrown, or if the popped values are in wrong types, a TypeError will be thrown

IO

Input

Unlike most other languages, ,,, does not utilize any standard input. Instead, there exists pre-defined arguments with the input data. At the start of program execution, the argument(s) is / are pushed onto the stack before any actual command is called. There is no command for getting input in ,,,.

Output

There is a print function in ,,, which outputs and pops the top value of the stack. However, after the program completes its last command (i.e execution is done), the top value is automatically printed.

Pushing values

To push custom values using code to the stack, you need to specify the data type of the character.

  • If the value is a character, you need to put a single quotation mark (') right before the character. (e.g 'h pushes the character h). Not doing so will result in an UnknownValue error.
  • If the value is a string, you need to put a double quotation mark (") right before the string (The ending quotes are semi-optional). Not doing so will again result in an UnknownValue error.
  • If the value is a number (integer or decimal), you do not need to do anything. (Note: if you want to push 2 separate numbers consecutively, you should put a whitespace character (spaces, tabs, returns, etc.) between them.)

Note that there is no boolean data type in ,,,. These are the only data types. The numbers can also be either integers or floats (decimals).

Logic and loops

Unfortunately, ,,, lacks control flow statements (if-statements and multiple loops), which limits ,,,'s functionality. Hence, infinite loops and logical calculations which are essential for problems like Truth-machines cannot be constructed, making ,,, a bit useless.

However, there are some ways to use logic in ,,,. Most of the commands of ,,, result in pushing either 0 or 1. These bits can be used for producing logic.

Logic can be incorporated by using the format:

<CodeToRunIfTrue> * boolean value (1 or 0).

For example, if we wanted to half the input number only if it was divisible by 2, we could use the following code:

2÷:2×2%1+×i

This uses the formula a/2(1 + a%2) where a is the input argument, proving that logic can be incorporated in ,,,. The 'i' at the end of the program is optional; it prevents the extra '.0' from being printed.

Comments

Normally, an unknown character command results in UnknownCommand errors. Comments in ,,, are declared using the format:

###<insert comment here>\n

...where \n denotes a mandatory newline.

Example programs

Hello, world!

"Hello, World!

The Hello world program is very simple: It starts with double quotes, which signify that the following bytes are strings. After the string is pushed, the program ends and the top value (the Hello, world! string) is printed. Note that the ending quotes are not needed.

Pseudo truth-machine

:48+c↻9999×1+i×

Since ,,, does not have any loop statements, there cannot be infinite 1's when 1 is the input. ,,, lacks repetition. So this program only prints a finite number of 1's (10000 to be precise). Note that the input argument is assumed to be a float.

Turing-Completeness

The lack of infinite loop makes ,,, Turing-incomplete (obviously).

External resources