Skip to content
kritixilithos edited this page Aug 22, 2017 · 8 revisions

Carrot is a string-based esoteric programming language built for code golfing.


This is how every program in Carrot looks like:

stack^operations

The stack starts off as a String that can further be manipulated with the operations. The stack doesn't need to be enclosed in quotes. Another thing to note is the the stack is basically a String and not an array. Next up is the caret ^. This is required in every program as it separates the stack from the operations. The operations manipulate the stack, to put it simply. At the termination of the program, the stack, after all the operations are applied, is printed to the output.

Stack

Now it is worth noting that the language is built from misnomers. By "stack", I mean just a placeholder where data is stored, something like a variable. There are many types of stacks: string (also called "stack"), int (stackI), float (stackF) and array (stackA). However, only one is used at a time. You can also switch between stacks using certain operators.

Data types

Carrot has several data types which are used

  • c^rrot: this is the first data type implemented in Carrot and the whole language is based around this date type. The c^rrot generally follows this format: data^ where the caret ^ is used to indicate the end of c^rrot. Every character in a c^rrot is pushed to the end of the stack. The down-caret v is also used in a similar fashion as the caret, but data in the down c^rrot is pushes to the beginning of the stack instead.

  • String: this is a string. "data"

  • Number: numbers in Carrot are always floats (misnamed as ints). -12.56

  • Regex: a regular expression is in the form: '/pattern/flags'. It uses JavaScript regex

Operators

Operators depend on the stack type [and the datatype given as an argument to itself]. Nilads only depend on the stack type, while Monads depend on the datatype as well. More on operators can be found here in the wiki: Monads and Nilads

Input

(todo: outdated)

The input is automatically split into newlines into an array. To pop the top value of the input, $ is used. This can be used in c^rrot mode and even as an argument to an operator, the stackMode decides whether the input should be interpreted as a float or a string. The # contains what is left of the input array, but in the form of a string (the elements of the array are joined by newlines). Again, this can also be used in c^rrot mode and as an argument to an operator. So far, this can only be used for string mode and regex mode (where you can only use #– which acts as $ in string mode).

Clone this wiki locally