551
\$\begingroup\$

Notes

  • This thread is open and unlocked only because the community decided to make an exception. Please do not use this question as evidence that you can ask similar questions here. Please do not create additional questions.

  • This is no longer a , nor are snippet lengths limited by the vote tally. If you know this thread from before, please make sure you familiarize yourself with the changes.

This thread is dedicated to showing off interesting, useful, obscure, and/or unique features your favorite programming languages have to offer. This is neither a challenge nor a competition, but a collaboration effort to showcase as many programming languages as possible as well as possible.

How this works

  • All answers should include the name of the programming language at the top of the post, prefixed by a #.

  • Answers may contain one (and only one) factoid, i.e., a couple of sentences without code that describe the language.

  • Aside from the factoid, answers should consist of snippets of code, which can (but don't have to be) programs or functions.

  • The snippets do not need to be related. In fact, snippets that are too related may be redundant.

  • Since this is not a contest, all programming languages are welcome, whenever they were created.

  • Answers that contain more than a handful of code snippets should use a Stack Snippet to collapse everything except the factoid and one of the snippets.

  • Whenever possible, there should be only one answer per programming language. This is a community wiki, so feel free to add snippets to any answer, even if you haven't created it yourself. There is a Stack Snippet for compressing posts, which should mitigate the effect of the 30,000 character limit.

Answers that predate these guidelines should be edited. Please help updating them as needed.

Current answers, sorted alphabetically by language name

$.ajax({type:"GET",url:"https://api.stackexchange.com/2.2/questions/44680/answers?site=codegolf&filter=withbody",success:function(data){for(var i=0;i<data.items.length;i++){var temp=document.createElement('p');temp.innerHTML = data.items[i].body.split("\n")[0];$('#list').append('<li><a href="/a/' + data.items[i].answer_id + '">' + temp.innerText || temp.textContent + '</a>');}}})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><base href="http://codegolf.stackexchange.com"><ul id="list"></ul>

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Why preserve a tag for one question, is it still bad for SE to have untagged question? \$\endgroup\$
    – l4m2
    Commented Jan 4, 2023 at 1:43

241 Answers 241

1
5 6 7
8
9
5
\$\begingroup\$

PyCal

Factoid:

PyCal is a math-based programming language written in Python, hence the name. It's designed to compete in code-golf challenges that need math.

Length 1 snippet

!

OK, let me explain a little about PyCal. PyCal has two "variables". One variable's value can be set by the user. The other variable's value comes from the values that some commands return. For example, the F returns the nth Fibonacci number.

Anyways, the ! command outputs the value that is in the user-set variable. By default, it's 0, so the above snippet outputs 0.

Length 2 snippet

IP

This snippet outputs the first n prime numbers as a list.

Let me explain what this does:

I gets input, and converts it to an integer before storing it in the variable. (From now on, I'll call the variable that the user can change "variable". The other one will be called the result. Read snippet 1 for more info)

P takes the variable's value and prints n prime numbers. For example, if the value is 5, it will output the first 5 primes.

So, here's what it will look like if the input is 10:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

Length 3 snippet

(7)

Ah, it's good to be back, I took a long break.

Anyways, let's get on with the explanation. Well, this is actually really simple. It changes the value of the variable to 7. Of course, this doesn't output anything. You can add a ! to the end to output the number.

Length 4 snippet

(wip)

Length 5 snippet

(i)S!

This snippet gets the square root of the input. (i) sets the value of the variable to the input and converts it into an integer. S calculates the square root.

\$\endgroup\$
2
  • \$\begingroup\$ I didn't think it would be Python + Math, I thought it would end up being Python + Pascal... \$\endgroup\$
    – XiKuuKy
    Commented Sep 20, 2016 at 12:37
  • \$\begingroup\$ @XiKuuKy It's Python + Calculator. PyMath and Pyth (:P) are both taken \$\endgroup\$
    – m654
    Commented Sep 25, 2016 at 9:24
5
\$\begingroup\$

Straw

Straw is a 1D stack-based language I created.
It mainly operate on strings.
You can try it online here.

Length 1

<

Take one line of input and exit.

Length 2

->

- take an item from the secondary stack, and > print it.
Straw have 2 stacks: The first is initialized with an empty string, and the second with Hello, World!.
So this code prints Hello, World!.

Length 3

9#>

Any character which is not a command is pushed on the stack, and # convert a decimal number to unary. It's needed to make any operations on numbers, because Straw don't have numbers, it only operate on strings. So this example prints 000000000.

Length 4

<<+>

Take two lines of input, concatenate (+) and print.

\$\endgroup\$
5
\$\begingroup\$

Arithmescript

Making an entry for Arithmescript here.

Codes

Length 1 snippet

i

Prints the value of i in the console.

Factoids

  • I am the creator of Arithmescript.
  • Arithmescript extends JavaScript.
  • It is sort of discontinued.

Demos

You can try out code in the latest version of Arithmescript at the official site.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Will you add snippets 2-4? \$\endgroup\$
    – acrolith
    Commented Sep 26, 2016 at 0:05
5
\$\begingroup\$

D2

Factoid

D2 is a Brainfuck-like turing tarpit with a 2D memory model

Length 1

.

This prints 0. Why?

. is, like in Brainfuck, the print command. But since cells are limited to 36 values, D2 use a shift-state system to print most ASCII characters. In shift state 0, the alphabet is 0123456789abcdefghijklmnopqrstuvwxyz, and since the cell is initialized to 0, this print 0.

Length 2

;.

Now this print !.

The ; instruction increment the shift state. In shift state 1, the alphabet is !@#$%^&*()ABCDEFGHIJKLMNOPQRSTUVWXYZ, so this print ! because the current cell is 0.

Length 3

>}+

Explanation:

>   Turn the cursor 90° to the right
 }  Advance in the tape
  + Increment the pointed cell

So the memory after this is:

0
1

This demonstrate D2's 2D tape

Length 4

+$}^

This set the first cell of the tape to 1, put the value in the register, advance one cell and put the value of the register in the cell.

\$\endgroup\$
5
\$\begingroup\$

FEU

FEU (File Edition Utility) is a heavily regex-based language to edit files.

0 bytes

Cat program. Yep.

In FEU, the input is took implicitely at the start of the program anv every command works on the input. The input is printed at the end.

1 byte

/

/ execute the next block each time the input match a regex. Here, it will crash anyway because the block is not closed (end).

2 bytes

u/

The command u convert the input to unary, and the input is implicitely printed.

3 bytes

s/a

s is the substitution command, so this remove the first a in the input.

Empty fields are optional.

\$\endgroup\$
5
\$\begingroup\$

Octopen-Baru

Please note, this is a noncompeting answer because this langauge came out a few minutes ago.

Length 1 Code

Simple Quine, the Ruby output is puts('見').

Length 2 Code

倍五

Which returns 100 .chr (which is 'd').

Length 3

5那}

Which returns 5.times {}, so essentially do nothing five times!

Length 4

口同愛r

Which returns r=gets;puts r, so it takes whatever you input and gives it back!

Factoid!

This language has no purposeful use of the newline character. Also, all the commands come from Kanji/中文. Also still under active development.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Noncompeting answers are allowed, as this is a catalog. \$\endgroup\$ Commented Oct 24, 2016 at 20:54
5
\$\begingroup\$

Alphafuck

I'll use upvote * 2 because this language uses pairs

Length 6 snippet

noT INF

This is a infinite loop. Transpiles to -[].

Length 4 snippet

uMhM

Reads a letter and prints it. Transpiles to ,..
This does the same thing: uM hM.

Length 2 snippet

um

Now we're getting into things. This snippet transpiles into Branfuck +, which increments the current memory cell by one.

Length 1 snippet

1

Anything that isn't an letter is ignored. This snippet is basically a comment.

Factoid

Alphafuck is an esolang I made that transpiles to Brainfuck.

\$\endgroup\$
5
\$\begingroup\$

FurryScript

Factoid

FurryScript was made for random text generation. It has some unusual features, such as:

  • No negative integer literals
  • Subtraction, but no addition
  • The return value of a subroutine is "OK", "bad", or "very bad"

Test snippets here.

Length 1

1

An integer literal. This won't really output anything, because first you have to convert it to a string. This can be done by appending an empty string:

1 +<>

Length 2

SU

Subtraction. Pops two values y and x and pushes x subtracted from y. For example, this:

6 5 SU +<>

outputs this:

1
\$\endgroup\$
4
\$\begingroup\$

Bitwise Cyclic Tag

Factoid:

Bitwise Cyclic Tag is a programming language with only two commands, 0 and 1. It operates on an unbounded tape of bits and is somehow Turing-complete...? I don't yet understand this, but I'll be learning the language along with all of you. Bitwise Cyclic Tag is incredibly simple, even compared to brainfuck and other Turing tarpits, making it a very useful tool for proving other languages' Turing-completeness—if it can interpret BCT, it can do anything! In fact, our very own Ørjan Johansen did just this to prove /// Turing-complete in 2009, writing this interpreter.

Length 1 snippet

0

This here is half of the language. When a zero bit is encountered in the code, the first bit of the data tape is discarded (some implementations print it as well). That's it.

This program demonstrates an important feature of BCT: the code is not run just once, but over and over until the data tape is empty (hence, "cyclic"), at which point execution halts. Therefore, this 0.125-byte program can be considered a sort of cat program, as in any implementation that prints on discard, this will print the entire starting data tape in order and exit gracefully.

Length 1 snippet

1

This here is the other command in BCT. It's a touch more complicated. When a one bit is encountered in the code, if the first data bit is a one, the following bit in the code is appended to the data (on the end). If the first data bit is a zero, nothing happens. In either case, the bit in the code immediately following the 1 is skipped.

It is worth noting that I was not completely honest about repeated execution in the first snippet. The code is treated as a loop (think Haskell's repeat), so if this snippet is executed, the bit possibly written is the 1 itself. This snippet, then, will infinitely add ones to the end of the data if the tape starts with a 1 or do nothing forever otherwise.

\$\endgroup\$
4
\$\begingroup\$

Keg

Factoid

Keg is a stack-based golfing language, created by PPCG user Lyxal, that focuses on simplicity and readability. It is fairly unique compared to most other golfing-based languages, since it has few instructions, and alpha-numeric characters are automatically pushed to the stack. It also has implicit input and output.

Length One

"

An example of the stack controls in Keg. This rolls the stack, which puts the top of the stack to the bottom. It is the opposite of ', which rolls the stack in the opposite direction, putting the bottom of the stack at the top.

Length Two

ab

Since these are alpha-numeric characters, they get auto-pushed to the stack as their respective ASCII values, which in this case are 97 and 98.

Length Two (bytes)

ߞ

Since this is not an instruction, this will be pushed onto the stack automatically. Keg allows Unicode characters to be pushed onto the stack, so this pushes 2014.

Length Three

83*

Any numbers get auto-pushed to the stack. In this case, it pushes 8, then pushes 3, and then multiplies them, giving 24.

Length Four

¿:+.

This shows how duplicating items and integer printing works by using nice input (evaluation of input) to double the given number.

Length Five

[a|b]

An example of an if statement in Keg. When an if statement is run, the top item of the stack is popped. If it is non-zero, the left code is run, whilst if it is zero, the right on the right is run. Note that the right side is optional

Length Six

(56*|1

An example of a for loop in Keg. The number on the left side is how many times it'll run, whilst the code on the right is what's run. In this case, it pushes 1 to the stack 30 times. If the left side isn't specified, it will automatically be the length of the stack. Also, all ending brackets get automatically completed at the end of the program, making this valid.

Length Seven

{!4>|.}

An example of a while loop in Keg. The code on the left is the condition, and the code on the right is what's run. In this case, while the length of the stack is greater than 4, it outputs the top element of the stack as an integer.

Length Eight

\ 
& &:.& 

This demonstrates a unique features of escaping characters and accumulator usage. The \ instruction escapes the newline, which has an ASCII value of 10, then the accumulator is set to 10. After that, the accumulator value will be accessed and printed, resulting in the program printing 10.

Length Nine

`Snippet`

This demonstrates the usage of strings in Keg. It pushes the string "snippet" and prints it.

Length Eleven

^!~$%(_|")_

This showcases most of the commands in one concise program. This removes exactly 1 character from 1 line of input randomly.

Length Twelve

@d1|:+ƒ¿@dƒ.

This defines a function called d and assigns the code :+ to it (doubling the input passed to it). Nice input is then taken (¿) and d is called on the input.

Keg Related Links

Esolangs Page

Official Github

Try it Online!

Keg Chatroom

\$\endgroup\$
4
\$\begingroup\$

Arn

Arn is a golfing language I designed recently. It's a functional paradigm with variable-based storage, and has a few cool features I enjoy. The full syntax can be found by clicking the name at the top of this post. An online interpreter can be found here for those interested.

Features

Type casting

Arn will automatically cast types based on the following:

  • Arrays casting to Strings or Ints will take the 0th element.
  • Strings or Ints casting to Arrays will split on every character OR every space if there are any.

Assumptions

The variable _ will be automatically assumed in any place where one a value is missing but required.

Similarly, any closing ), ], }, ", ', or ` can be ignored if it reaches the end of an expression or the program.

STDIN

STDIN will automatically be assigned to the variable _ at runtime. It will be a string if STDIN is one line, or an array split on newlines otherwise.

Functions

Since functions exist in this language, and that means a Standard Library can exist! You will see example functions for that later.

Packing

In order to help Arn compete with other, golfing languages, a packed form exists. This form is shorter, encoded based on a modified CP1252 found here. The average compression rate, as far as I've found, is ~17%.

I am very happy with the encoding, I spent hours and hours on it. It may change to become every more concise in the future (if possible, and if I can figure out how) but until then, this will be how it works.

The interpreter can run Carn (Compressed Arn) and regular Arn without any indication of which is passed.

Compressed Strings

Should be pretty self explanatory. They are based on a dictionary found here.

The code is F * 100 + S OR F * 100, depending on if 1 valid compressed character or 2 are passed. Compressed strings are denoted with either ' or `, where the former capitalized every word and the latter just the first. You can find a full description on the GitHub page, linked at the top of the post.

Showcase

From top to bottom.

1 byte

_

This is a very simple program, it will just return STDIN. Output is implicit in this language.

2 bytes

+4

This program will add 4 to STDIN and return it. The same as saying _ + 4

3 bytes

4,7

Above features the use of an infix; specifically, the , infix. This infix is the pair verb; it takes the left and right argument, turning them into an array.

5 bytes

.fact

This little snippet shows us two new features (three, really!): the . infix, the fact function, and implicit casting. Since no value is passed to the . fix, it assumes _ on the left. This is then passed to the factorial function. The factorial function uses the 1-range fix, which takes an integer, and so _ is automatically casted to an integer.

7 bytes

+{+1}\~

This showcases the extremely useful \ prefix. This prefix operates as both a fold and map fix; it will map using the block preceding it (if provided) and then fold with the fixes preceding that. This snippet also shows the 1-range fix, ~, in action.

Essentially, this program takes a number on STDIN. It creates a range, from [1, n] (where n is the input). Then it maps over this range, incrementing each entry by one. Finally, it adds all of the entries together.

\$\endgroup\$
3
\$\begingroup\$

Logy

Logy is a logic, imperative and functional programming language.

0 bytes

A program without the main rule do nothing.

1 byte

#

Start a line comment

2 bytes

->

The rule definition operator

\$\endgroup\$
3
\$\begingroup\$

SQF

Factoid:

SQF (Status Quo Function) is the scripting language for the Real Virtuality engines (O:FP, ArmA, ArmA 2, ArmA 3). The games written for the engine are functionally just mods made in SQF.

Length 0 Snippet:

This is technically valid SQF, and does nothing unless it is treated as code, in which case it is a no-op.

Length 1 Snippet:

+

+ does the usual things in SQF:

  • Concatenation of arrays
  • Concatenation of strings
  • Addition of numbers

And something really cool as well:

  • Deep-copying of arrays (as a unary prefix)

Length 2 Snippet:

_x

_x is a magic variable which is used in these cases:

  • The current element in the optional predicate block argument of count (an array function)
  • The current element in the main block of a forEach block

Length 3 Snippet:

a-b

This subtracts b from a, if the operation is applicable to the types of a and b.
Like quite a few things in SQF, it does something particularly neat with arrays:

  • When a and b are arrays, the result of a-b is the set exclusion of b from a
\$\endgroup\$
3
\$\begingroup\$

Pushy

Info:

Pushy was never meant to be a language. It was originally just a postfix expression calculator, implemented with a stack. However, I (FlipTack) expanded it, adding several built-ins, loops, and (sort of) strings, it evolved into a language.

Snippets:

Note: in the showcase update, all answers are CW, so feel free to contribute to this post! Also, snippet length is no longer restricted by vote count.

Click on the header of any snippet to run it in the online interpreter!


Length 7 Snippet:

95&34_"

This program is the beginning in a chain of programs which output larger versions of themselves.

This program pushes 95, copies (&) it, then pushes 34. _ prints the stack's values, and " prints it again but as a string, resulting in:

95 95 34
__"

Which in turn outputs:

95 95 34
95 95 34
__"

5 or so iterations later, it looks like this:

95 95 34 95 95 34 95 95 34 95 95 34
95 95 34 95 95 34 95 95 34 95 95 34
__"__"__"__"
95 95 34 95 95 34 95 95 34 95 95 34
95 95 34 95 95 34 95 95 34 95 95 34
__"__"__"__"

...and it keeps growing forever. (If you iterate ~8 times, TIO begins to cut the output)


Length 3 Snippet:

:H"

This is in fact an adaption of my asterisk triangle answer. Given an integer, for example n = 5, it prints a "d-triangle" of this size:

d
dd
ddd
dddd
ddddd

This is a concise example of both loops and char-code conversion in Pushy:

:    \ Input times do (consuming input):
 H   \   Push 100 to the stack (character code for 'd')
  "  \   Print the whole stack, as a string.

As each iteration pushes a new 'd', this creates a triangle.

Notice there is no "end-loop" delimiter: this is normally signified with a ;. However, the interpreter automatically assumes these to be at the end of the program if omitted.


\$\endgroup\$
1
  • \$\begingroup\$ What's with the downvote? \$\endgroup\$
    – FlipTack
    Commented Nov 8, 2017 at 18:23
3
\$\begingroup\$

tinylisp

Factoid:

tinylisp is a language made by @DLosc for an "interpret this language" challenge. Its intent is to demonstrate what a Lisp-like language can do using only very few builtins.

Here is an interpreter.

Snippet 1:

d

This single character is perhaps the most used builtin in tinylisp: the def builtin. It can be used to define variables and functions, and is basically required for every tinylisp program. Like any other lisp-like language, you define things like this:

(d x 10) // Creates a new variable x, and sets it to 10
(d succ  // Successor function, will be properly covered later
  (q (
    (x)
    (s 1 (s 0 x)))))

Snippet 2:

()

Everything in tinylisp (and basically most Lisp-like languages) are built off of parentheses. In tinylisp, these parentheses define an empty list - which is one of three data types in tinylisp:

  • Symbols
  • Numbers (which will be covered in the next snippet)
  • Lists

Snippet 3:

1.5

tinylisp has numbers, but surprisingly enough, this is not a number. Numbers (at least, numbers you can type down before compilation) in tinylisp only have the characters 0-9 in them, and anything else is a name, so these "numbers" aren't numbers in tinylisp:

-13    (contains -)
.335   (contains .)
17,232 (contains ,)

There's currently no way to define floats in tinylisp, however I'm working on implementing a fraction "class" thing in tinylisp. - Qwerp-Derp


Snippet 4:

disp

This is a four-character builtin in tinylisp, however most builtins are only one character (see snippet 1 for an example). This basically returns a value to STDOUT, with a trailing newline.


Snippet 5:

(v 1)

Yes, finally, a full statement that actually evaluates to something!

This evaluates the number 1, and therefore returns 1. That's simple enough - more complicated examples are to come.

Try it online! (from snippet 5 onwards, you should be able to test all of the programs).


Snippet 6:

(q(1))

This snippet quotes the list (1), and therefore evaluates to (1). I'm doing the best I can with 6 bytes...

q basically takes anything, and then returns the same thing, unevaluated. So for a program like this:

(q (s 1 2))

Instead of returning 3, it returns (s 1 2) instead.

Try it online!


Snippet 7:

(s 1 2)

s is the subtraction builtin; more specifically, it subtracts two integers. The above returns -1. Incidentally, s is the only way to get negative numbers in tinylisp (compare snippet 3).

Try it online!


Snippet 8:

(q(()1))

This is the simplest example of a lambda in tinylisp, and is essential to both evaluating other things and creating functions. The structure of lambdas is like so:

(q (  ;; Lambdas have to be quoted using "q", so not to get evaluated
  ()  ;; A list of arguments, in this example there are 0 args, so
      ;; this is an empty list
  1   ;; The "body" of the lambda: in this case, we're returning 1
      ;; for every input.
))

This statement is essentially similar to the Python lambda lambda:1 (which is also 8 bytes long, coincidentally). It can be used like so:

( (q(()1)) )  ;; evaluates to 1

Try it online!

\$\endgroup\$
2
  • \$\begingroup\$ You don't actually say how to define floats. What if I want to enter 1.5? \$\endgroup\$
    – Pavel
    Commented Jan 26, 2017 at 4:01
  • \$\begingroup\$ @Pavel There's no way to define floats in tinylisp, unfortunately... :p \$\endgroup\$
    – clismique
    Commented Jan 26, 2017 at 4:02
3
\$\begingroup\$

Triangularity

Factoid

Triangularity is a minimalistic esolang, which can (for now) only perform very basic arithmetic and string / list manipulation. As its name might suggest, every piece of code should be padded nicely with triangles of dots. Valid Triagularity programs must have the character count listed in OEIS A056220 (except for -1), otherwise you are probably doing something wrong.

Length 1

)

This just pushes a 0 onto the stack, and the top of the stack is implicitly outputted.

Length 7

.).
IEp

First off, ) pushes a 0 onto the stack, the argument to I, which retrieves the 0th line from STDIN. E evaluates it to an integer and finally p tests our integer for primality.

Length 17

..)..
.IE).
@IE+.

Adds any two valid inputs, either numbers or collections.

Length 31

...)...
..IE)..
.0>)@_.
^)IE/..

Computes the absolute value of a number, by multiplying by its sign, with a few tweaks.

Length 49

....)....
...2)1...
../D)IE..
.^is)@IE.
^i=......

Checks if the integer part of the square root of two numbers given as input is identical.

Length 71

..... .....
...."!"....
..."ld"+...
.." Wor"+..
."Hello,"+.
...........

Of course, we need a "Hello, World!" program! This can actually be golfed down to 49 bytes

.... ....
..."!"...
.."ld"+..
." Wor"+.
"Hello,"+

Try it online!

\$\endgroup\$
3
\$\begingroup\$

Integral

Integral is a stack-based golfing language I recently made. It uses code page 437.

An interpreter.

1 byte

V 

Integral has many built-in functions. V reverses the top of the stack. Integral pushes all input to the stack and implicitly outputs the stack seperated by newlines.

12 bytes

÷▓ll▄å▒▌«s»÷

You can compress strings in Integral. This ouputs hello there person. Compressed strings are started and ended by ÷.

37 bytes

♂⌡ ⌡♦⌡_⌡g►⌡/⌡•⌡ ⌡g►⌡\⌡►•⌡|⌡♦⌡ ⌡g►⌡|⌡►

This is an example program that takes an integer as input, and returns an ASCII-art rainbow with width n.

I do not think Integral is Turing-Complete yet.

\$\endgroup\$
3
  • \$\begingroup\$ You probably want to update the 12 byter to ÷▌lloª• pô┼÷ (12 bytes) \$\endgroup\$
    – user96495
    Commented Aug 7, 2020 at 1:25
  • \$\begingroup\$ @petStorm The interpreter needs to be fixed first. \$\endgroup\$
    – nph
    Commented Aug 7, 2020 at 11:39
  • 2
    \$\begingroup\$ Interpreter fixed. \$\endgroup\$
    – user96495
    Commented Aug 7, 2020 at 12:36
3
\$\begingroup\$

dotcomma

Dotcomma is a simple esolang I made, which uses only 4 instructions and is not Turing complete is now Turing complete, due to the addition of a queue for storage.

Factoid:

With only the instructions [.,], the . and , operators are heavily overloaded. For example, , can take input and output, manage the queue, test the number of times a code block was evaluated, and conditionally evaluate a code block. Which of these occur is decided by what characters precede and follow an operator.

Length 2 snippet:

All dotcomma programs are wrapped in code blocks ([]), so a length 1 snippet is impossible.

[]

This program does nothing.

Length 3 snippet:

[.]

This program sets its return value to 1. All operators and blocks have a return value, which can be used by other operators and blocks to nest expressions, create loops, or manage the programs's structure. If the . operator is preceded by [, it's return value is 1. If followed by a ], it uses its return value as the block's return value.

Length 3 snippet:

[,]

This program would previously take a value from input, and output it. The return value of the , operator would have been taken from input when preceded by [, and outputted if followed by ].

In "modern" dotcomma, this will take a value from the queue, and place it at the end of the queue. For example, given the input 6 7 8 (input is placed on the queue by default), this program would output 7 8 6 (final value of the queue is used as output by default).

Like the . operator, , will use its return value as a block's return value if followed by ].

Length 4 snippet:

[.,]

This program will output 1. As with the second snippet, the .'s return value is set to 1. However, because the , operator is preceded by an operator, it will use that operator's return value instead of taking a value from the queue.

Length 5 snippet:

[[,]]

This program will take a value from the queue, and place it back on the queue. However, it will have a return value of 0. This is because the , is wrapped in a nested block, and blocks default to a return value of 0 if an operator does not explicitly define one.

Length 6 snippet:

[[,].]

This program does the exact same thing as [,]. The . operator, if preceded by ], will set its return value to the sum of the return values of all previous un-separated blocks, which is only one in this case.

Length 9 snippet:

[[].[],.]

This will return the -1. The first empty block's return value will be read by ., which returns 0. As a result, the next block will be skipped (a loop that runs 0 times). Because the block preceding the , was never run, its return value will be -1.

Length 11 snippet:

[[,.][,.].]

This program uses the . operator's addition capabilities to take the sum of two inputs and use it as the program's exit code. Adding a . to the end of the , operators will prevent them from outputting, as they are no longer followed by ].

\$\endgroup\$
1
  • \$\begingroup\$ I already made a few answers using dotcomma, and for me it's a really interesting language. However, I'd like to suggest some improvements. I think the language would be more fun if you'd allow negative values on the queue. Of course that change would need a different option to determine if the queue is empty. My idea is to use .. and ,,, since those combinations aren't particularly useful in the current implementation. You could for example use ,, to return the length of the queue and .. to return the negative of the previous value, and then return 0 if you read from an empty queue. \$\endgroup\$
    – Dorian
    Commented Oct 5, 2020 at 7:21
2
\$\begingroup\$

NO!

Factoid

The only valid characters in NO! are NOno!?. This language was created 2 hours ago and I'm currently writing this with my 12th cup of coffee in my hand. This language is close to the antithesis of code golf as demonstrated by this answer to the Hello, World! challenge.

Snippets

Hello, World!

NOOOOOOOOO?Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooo Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Noooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo Nooooooooooooooooooooooooooooooooo
NOOOOOOOO?no

Add two numbers

NO?NOOOOOOOOOOO!NOOOOOOOOOOO
NOOOOOOOO?no

Prime Tester

NOOOOOOO?NOOOOOOOOOOO
NOOOOOOOO?no
\$\endgroup\$
2
\$\begingroup\$

CGL (CGL Golfing Language)

(or Code Golf Language, this was not intentional :)

Factoid

CGL uses the stack concept like a lot of other golfing languages, but unlike them it has an infinite number of stacks that it has. Most operators operate on the current stack except some that change the current stack or move things. Stacks have numerical indexes. 0 is the default stack. The -1th stack is where input is stored.

I am unsure how bytes are counted for some of this unicode, so feel free to correct me in comments.

1 byte

h

Outputs Hello, World!. Actually pushes Hello, World! to the current stack (default 0) and the first element in the current stack is outputted by default.

2 bytes

There are a lot of possible 2 byte programs, but I wanted to show a cool operator in this one: -. - decrements the current stack, in this case switching from 0 (default) to -1 (where input is stored). ² squares the current stack. The first item in the current stack is outputted by default, so this squares the input and returns it.

3 bytes (uses a combining character)

'҄҄낄䀀

This shows off the neat string compressing function. Normally, you wrap a string in "s and it is pushed to the current stack. 's enable you to use compressed strings. ҄낄䀀 is the compressed version of Hi! (note in this example, there is no compression savings, but with longer strings there often is. Also, you can use & to compress the current stack.) Quotes are auto-completed if you leave them off.

4 bytes

-#2➕

Adds 2 to the input. adds the second stack item to the first or 1 to the first if the second stack item is non-existent.

5 bytes

-#1+Ⓧ

The # pushes the following number to the stack. Note that technically numbers are wrapped in #s, but if you leave them off they will be added between the last digit and any non-number character. The (diffrent from +) adds the first 2 stack items and pushes that to the stack. outputs the last item from the stack and exits. This therefore adds 1 to the input.

\$\endgroup\$
2
\$\begingroup\$

Decimal

Decimal, also called 09D by some users, is an esoteric stack-based programming language I created that uses only the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, and D.

Factoids

  • Decimal is stringly typed. The PUSH code for STRING is 3.
  • Decimal was on tio.run from day 1 of its release.
  • Decimal is not based on the top of the stack. It's based on a Default Stack Index (DSI). All functions that write to the stack set this index.
  • While very obfuscated, Decimal can be easily translated into pseudo-stack code.
  • All characters other than 0-9 and D are simply printed as they appear in the source code. This excludes whitespace.
  • Decimal uses Assembly-like comment syntax, e.g. ;COMMENT.

The Decimal GitHub repo is here.

Length 1 snippet

2 is the command for POP. Simple enough. POP pops the DSI from the stack.

2

Length 1 snippet

5 is the command for IF/ENDIF.

5

If not in an if-statement, 5 will check the DSI value. If truthy, the interpreter will continue reading as normal. If falsy, it will ignore all commands until 5, except JUMP. JUMP will exit any if-statement.

If currently in an if-statement, 5 acts as ENDIF.

Length 3 snippet

Command 3 is the command for I/O. The first argument specifies where to read from (0 for stack, 1 for user input). The second argument specifies where to put the read value (0 for stack, 1 for output).

All I/O commands are 3 characters long.

Length 3 snippet

Command 9 is the command for JUMP. JUMP commands must end in the character D. JUMP 0 exits the program.

91D

If jump #1 has not been declared, 91D will declare it. If jump #1 has been declared, 91D will jump to it.

Length 4 snippet

Command 4 is the command for MATH. See the MATH section in the Decimal README for more information on MATH arguments. Each MATH command must end in D.

412D

This compares STACK[DSI-1] and STACK[DSI] for equality, pops both, and pushes the result.

\$\endgroup\$
2
\$\begingroup\$

MY

MY currently has no implemented codepage, so code will be listed in both bytes and the unimplemented codepage, one following the other. MY is stack based and "vector oriented" (like Jelly, some commands automatically "vecify" over their arguments). MY also has an "Object Subject Verb" visual order of commands.

1 byte

27
↵

This program outputs 0 with a trailing newline. MY does not have implicit input nor implicit output, if one pops from an empty stack, it pops 0.

2 bytes

1F 27
⍞↵

This program takes a line of raw input, then outputs it (with a trailing newline). MY can't do very much in 1 or 2 bytes due to lack of implicit IO.

3 bytes

1F 64 27
⍞h↵

Reads a line from STDIN, then converts it from hexadecimal (must be uppercase) to an integer. This beats Jelly.

4 bytes

01 02 81 26
12-←

This is where the quirk of MY comes in, for multiple argument commands, MY pops the amount of arguments needed, then applies them to a function in the order that they are popped. OSV, this resembles (hence, the Y standing for Yoda). Thus, the above code outputs 1 rather than -1 (without a trailing newline).

5 bytes

01 4D 02 80 26
1W2+←

This showcases MY's "vector orientation". This differs from APL and J, but is more like Jelly's concept of vectorizing ("vecifying" in MY). The program pushes 1 to the stack, wraps that in an array, pushes 2 to the stack, adds the top two elements, then displays with no newline (outputting [3] due to the "vecification" of commands).

\$\endgroup\$
2
\$\begingroup\$

Pain-Flak

Pain-flak is brain-flak's evil sibling, I would just read the docs here

6 Bytes:

))((}{

That pushes 1 to the stack (stack clean)

156 Bytes:

><))))))))))))()()()((}{(}{(}{)((((}{}{)((][][][][(][][(]][[)((]][][][][][[)(()‌​])][)][(][][}{([)()()()]][[))])()()([)])][][][([))))}{)((}{(((}{}{(((((}><{

The hello world program made by Dennis (run with -A)

\$\endgroup\$
2
\$\begingroup\$

평범한 한글(Unsuspected-Hangul)

Unsuspected-Hangul is functional esolang.

Factoid

Unsuspected-Hangul only uses 10 consonants of Korean character : ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅎ, and other consonants are replaced by them. Vowels and final consonants are dismissed. Non-hangul(alphabet, number, white spaces) are all same.

Rule of replacement

ㅊ -> ㅈ, ㅋ -> ㄱ, ㅌ -> ㄷ, ㅍ -> ㅂ
ㄲ -> ㄱ, ㄸ -> ㄷ, ㅃ -> ㅂ, ㅆ -> ㅅ, ㅉ -> ㅈ
ㄳ -> ㄱㅅ, ㄵ -> ㄴㅈ, ㄶ -> ㄴㅎ, ㄺ -> ㄹㄱ, ㄻ -> ㄹㅁ, ㄼ -> ㄹㅂ, ㄽ -> ㄹㅅ, ㄾ -> ㄹㄷ, ㄿ -> ㄹㅂ, ㅀ -> ㄹㅎ, ㅄ -> ㅂㅅ

You can try unsuspected-hangul here

Length 1

ㄱㄴㄷㄹㅁㅂㅅㅈ is number : From zero to seven.

Only initial consonant counts : so it is same as , So it returns 0.

강 means river.

Legnth 2

나무

Even-length number is negative, while odd-length number is positive. Every number is octal.

ㄴ is 1, and ㅁ is 7, and it is written backward, so ㄴㅁ is -71(octal), -33(decimal).

나무 means tree.

Length 3

코끼리

This is odd-length, so it is positive. It is equivalent of ㄱㄱㄹ, 300(octal), and 192(decimal).

코끼리 means elephant.

Length 4

집전화기

Now introducing : types. Unsuspected-hangul has 7 types : Number, Boolean, String, List, Closure, IO, Nil.

ㅈㅈ is built-in function that returns True. And ㅎㄱ calls function with 0 parameters. So ㅈㅈㅎㄱ returns True.

집전화기 means Home telephone.

Length 5

문자 한개

Non-hangul(like space) right before can be omitted. ㅁㅈ is built-in function that changes number to string (if given with parameter). If ㅁㅈ called with no parameter, it just returns empty string.

So ㅁㅈ ㅎㄱ returns ''

문자 한개 means One character.

Length 6

평범한 한글

Yes, It is name of the language. It is equivalent of ㅂㅂㅎ ㅎㄱ.

makes function. ㅂㅂ ㅎ( is ㅂㅂㅎ) is function that returns -45.

ㅎㄱ calls function with no parameters, so it returns -45.

평범한 한글 means Ordinary Korean character, or Unsuspected Hangul.

Length 7

또 또 신호등

ㄷ ㄷ ㅅㅎㄷ. is built-in function for power. ㅎㄷ calls function with two parameters. (Remember ㄷ means 2?)

So it calculates 2^2, and returns 4.

또 또 신호등 means Traffic light again again.

Length 8

나 과제 다했다

ㄴ ㄱㅈ ㄷㅎㄷ. is built-in function for addition. ㄱㅈ is -56, so it calculates 1 + (-56), and returns -55.

나 과제 다했다 means I'm done with my assignment.

From github readme.md file.

Length 9

그는 자는 척했다

ㄱㄴ ㅈㄴ ㅈㅎㄷ. is built-in function for comparison. If first parameter is smaller than second parameter, returns true. ㄱㄴ is -8, and ㅈㄴ is -15. So it returns False.

그는 자는 척했다 means He pretended to sleep.

\$\endgroup\$
2
\$\begingroup\$

ARM Thumb-2

Also applies to ThumbGolf, a direct superset of Thumb-2.

ARM Thumb-2 is a rather quirky RISC instruction set. It is a 32-bit architecture, but unlike most RISC instruction sets, it uses a mix of 16-bit and 32-bit instructions.

Thumb was originally a 16-bit only subset of the 32-bit ARM instruction set, created in 1998 with the ARM7TDMI. It was designed for embedded devices which either had a 16-bit memory bus or required more code density, and it was pretty impractical otherwise.

In 2003, with the release of the ARM1156T2, this was expanded to a whole new instruction set, named Thumb-2. Combining flexible 32-bit instructions with the existing 16-bit instructions, Thumb-2 was a faster, smaller, and more polished replacement for the old 32-bit ARM instruction set.

ARM is best known for its powerful addressing modes, barrel shifter, Absolutely Ridiculous Multiplier, load/store multiple, and conditional execution.

Small factoid: Thumb was a key factor in the Game Boy Advance's design. It significantly lowered the cost of Game Paks thanks to both the code density and the cheap memory bus.

Length: 4

0841 d3xx
        lsrs    r1, r0, #1
        bcc     .Lbit_not_set

lsls and lsrs are (likely) the most useful arithmetic instructions out of the original 16-bit instruction set. Many masking operations can be done in half the size with a simple shift right and testing the flags.

This tests if the low bit is set. You can also use this for bitmasks, as lsrs and lsls also set the zero flag.

Length: 6

fab0 f080 0940

Assembly:

        clz     r0, r0
        lsrs    r0, r0, #5

I learned this one from Clang.

This sets r0 to 0 if it was nonzero, or 1 if it was zero.

In C terms, it is r0 = !r0.

It does this by counting the leading zeros, which will return a value from 0-32 (with 32 meaning the register is all zero bits), then shifting right to turn 32 to 1 and everything else to 0.

Length: 4

b100 2001
        cbz     r0, 1f
        movs    r0, #1
1:

The same as above, but sets r0 to 1 if it is non-zero, or !!r0. This shows off the cbz (compare and branch if zero) instruction, and is quite literally this:

if (r0 != 0)
    r0 = 1;

Length: 6

push and pop are very useful.

b40f bc0e bc01
        push    {r0, r1, r2, r3}
        pop     {r1, r2, r3}
        pop     {r0}

This is a similar trick to the push rax; pop rdx trick in x86_64 to avoid REX prefixes, however, it is much better:

This rotates the registers r0-r3, so r0 will have r1's value, r1 will have r2's value, etc. You can do all sorts of tricks.

Length: 12

ea80 3040 ea80 4050 ea80 1040

Assembly:

        // XorShift32
        // in: state: r0
        // out: state: also r0
        // x ^= x << 13
        eor     r0, r0, r0, lsl #13
        // x ^= x >> 17
        eor     r0, r0, r0, lsr #17
        // x ^= x << 5
        eor     r0, r0, r0, lsl #5

XorShift32, with no temporary registers. This shows off the coolness of ARM's barrel shifter.

Length: 18

19e0 0269 4066 406f 4075 407c 404e ea4f
5777
        // A rather literal translation of xoshiro128+.
        // Input: r4-r7: state
        // Output: r0: result, r4-r7 modified

        // result = s[0] + s[3]
        adds    r0, r4, r7
        // t = s[1] << 9
        lsls    r1, r5, #9
        // xor all state lanes together
        eors    r6, r4
        eors    r7, r5
        eors    r5, r6
        eors    r4, r7
        // xor temp
        eors    r6, r1
        // rotl
        ror     r7, r7, #32 - 11

If Xorshift32 is too weak for your tastes, here is its cousin xoshiro128+. However, it uses most of your precious Lo registers, so it isn't practical as a sub-algorithm. 🤷‍♂️

It stores the state in r4-r7, and returns in r0. It clobbers r1.

Note: xorshiro64* is two bytes larger.

Length: 12

fba0 4502 fb00 5503 fb01 5502
        // Standard 64-bit to 64-bit long multiply:
        // input: x[0]: r0, x[1]: r1, y[0]: r2, y[1]: r3
        // output: product[0]: r4, product[1]: r5
        // {r4, r5} = (u64)x[0] * (u64)y[0]
        umull   r4, r5, r0, r2
        // {r4, r5} += (x[0] * y[1]) << 32
        mla     r5, r0, r3, r5
        // {r4, r5} += (x[1] * y[0]) << 32
        mla     r5, r1, r2, r5

A 64x64 multiply with a 64-bit result. This shows off the multiply and accumulate instruction, but it gets better:

Length: 16

fba2 4500 fba2 6201 fbe3 6560 fbe3 2561

Commented assembly:

        // Does an unsigned 64-bit to 128-bit long multiply
        // in: x[0]: r0, x[1]: r1, y[0]: r2, y[1]: r3
        // out: product[0]: r4, product[1]: r6, product[2]: r2, product[3]: r5
        // {r4, r5} = (u64)y[0] * (u64)x[0]
        umull   r4, r5, r2, r0
        // {r6, r2} = (u64)y[0] * (u64)x[1]
        umull   r6, r2, r2, r1
        // {r6, r5} = (u64)y[1] * (u64)x[0] + r6 + r5
        umaal   r6, r5, r3, r0
        // {r2, r5} = (u64)y[1] * (u64)x[1] + r2 + r5
        umaal   r2, r5, r3, r1

This is a 64-bit to 128-bit unsigned long multiply. On a 32-bit processor. In four instructions. x86 takes about 30.

See my comment in xxHash's source code of the C algorithm which explains this.

\$\endgroup\$
2
\$\begingroup\$

Pxem

Pxem is an esoteric language designed by "ぬこ" (now "nk."), published in 2008. Unlike many other languages, filename matters first and content is second; that is, a Pxem program consists of two strings.

0 bytes

If content is empty, calling .e is equivalent to duplicating entire stack.

1 byte

.

Every command has this prefix; this may be awkward when you want to push the character directly, on some problems.

3 bytes

\001.r

My favorite idiom to push zero on filename. As filename cannot contain NULL character (usually), this would be needed.

4 bytes

XX.z

My favorite idiom to begin pseudo comment.

6 bytes

.c.c.z

My idiom to check if stack is empty or not; goes inside if stack is empty; does not otherwise.

\$\endgroup\$
2
\$\begingroup\$

ErrLess

Factoid

ErrLess is a functional language where every command is one character long. Its defining feature is that it refuses to throw any errors, even if you divide by zero!

You can run ErrLess in your browser by inserting your code into the code section of this python program.

Length 1 snippet

.

Halts instantly. In ErrLess, when the instruction pointer reaches the end of the program, it loops back to the start. This means that you have to explicitly halt your programs.

Length 2 snippet

i?

A simple cat program that infinitely echoes stdin to stdout. i fetches one character of input, which is then outputted using ?, and then the instruction pointer loops back to the start.

Length 3 snippet

'A?

Prints the character A indefinitely. Why do you only need an opening quote, and not a closing quote? Simply because I thought that there is no need for a closing quote, since a character can only be, well, one character long.

Length 4 snippet

12#.

This program does not output 12, as one might expect, but only outputs 2. Remember: every command is a single character long. First one is pushed to the stack, then two, then the top value of the stack is printed as a number, then the program halts.

Length 5 snippet

e3*#.

The answer to life, the universe, and everything. This program outputs 42: a through f push 10 to 15 to the stack, and the * operator multiplies the top two elements of the stack.

\$\endgroup\$
1
\$\begingroup\$

W

Factoid

W is a simple stack-based golfing language that is surprisingly very concise. Its powerful iterator protocol and implicit input system is the cause for this.

Length 1

w

This is in fact a valid Truth-machine program (infinite 1 while 1). Let's explain it. The first step of the execution is to prepend all of the possible inputs to the stack:

aaw

Note that the input is used both as the condition and as the body of the while loop. Therefore this program decodes to the following pseudo code:

while the input:
    print the input

The print is implicit in every while iteration. So if the input is 1 (a truthy value), this prints the input 1 indefinitely.

You might want to ask, could this code snippet produce the right result for a 0 input? Yes; the while loop returns the condition onto the stack after the execution, therefore 0 is outputted onto the stack.

IMPORTANT NOTE. W's while loop is only for demonstration purposes. Never use this instruction, because W is designed to allow users to use for loops over while loops.

Length 2

+M

The W snippet that I am most proud of! It showcases more of W's powerful protocol.

So let us first try to make 'z' (the string) as an input. The program outputs:

aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz

Well, you might be confused by this odd output. Don't worry; I will explain it.

aaa+M

This transpiles to:

map(a,a+a)

Which means double every item in the string. If the string was 'ab' then the output would be 'aabb'.

So, why in the world would it return the doubled alphabet? Well, the Map instruction has an automatic range that allows users to iterate over a singleton. (Because it is pointless to do so)

In this context, this will return a range from lowercase a to z, hence the doubled alphabet.

\$\endgroup\$
1
\$\begingroup\$

rusty_deque

rusty_deque is a deque-based programming language that I created to learn the basics of Rust. Has a REPL and interpreter included. Each command has a "sigil" that's appended to show the side of the deque will execute on; this allows both stack-like and queue-like semantics.

Length 1:

!
~

These are the two sigils all instructions must have appended to run in rusty_deque. ! has instructions work on the left of the deque, and ~ on the right.

Length 2:

1~
1!

Pushes a 1 onto the deque, right side or left side.

Length 3:

"A"

Strings are not a separate type in rusty_deque, they are instead defined as lists of characters. Double quotes are merely syntactic sugar for strings,

Length 4:

dup~

Most of the standard stack and queue operations are implemented; dup in particular will duplicate the top of the deque.

Length 5:

loop!

There are a few control flow structures in rusty_deque, and loop is one of them. rusty_deque has a literal value called "blocks", which are just a bunch of instructions being treated as a value. loop will pop a block and endlessly execute the code inside.

Length 6:

reduce~

There are also some functional-like list operations. reduce pops off a list, an accumulator, and a block to apply on each element on the list and the accumulator; reduce leaves the final result on the deque.

Length 7:

1~3~l/!

l/ is one of the instructions that operate on lists; l/ stands for list slice, and takes a list, a starting index, and an ending index; it leaves a list being the elements between that range.

Length 8:

[1,2,3]~

A list of 3 integers pushed to the right of the deque.

Length 14:

{il~ol~}~loop~

A simple infinite cat program. Gets and prints a line forever.

\$\endgroup\$
1
\$\begingroup\$

[min]mod

Note: [min]mod is too difficult to use for most code challenges, and is a horrible golfing language too. Please tell me whether or not I can still keep this submission here.

Factoid:

[min]mod is a language where all data is possibly nested stacks of instructions. Variables storing such stacks can themselves be executed, in which case their contents are executed element by element.

Length 0 snippet

Try it step by step! (click on the program.[m]m file to see the contents, and the play button to execute)

The program is stored in a sub-stack in IS, the built-in instruction stack; so in this case IS stores [[]]. The sub-stack is popped since it doesn't contain any instructions, and the program then terminates since IS is empty.

Length 1 snippet

A

Try it!

This will attempt to execute the variable A, and will throw an error since A is uninitialized.

Length 2 snippet

IS

Try it!

This is the shortest infinite loop in [min]mod, and one of the shortest valid non-empty programs.

Since the instruction stack is a variable, it can be executed like any other. In this case, the value of the instruction stack will initially be [[IS]]. The program will try to execute the first instruction in IS, which is IS itself, by pushing its contents onto IS as a new sub-stack. At principally the same time, it pops that instruction from IS, making IS now contain [[[IS]] []]].

Since the first instruction in the first sub-stack in IS is now a stack, it will be popped. Simultaneously, its contents are pushed as a new sub-stack, making IS contain [[IS] [] []]. Now, IS will be executed again, grow, be executed again, grow, and so on forever (assuming the computer has infinite memory).

Length 3 snippet

A..

Try it!

Unlike the length 1 snippet, this won't throw an error since it won't actually execute A. The number of periods after an instruction determines its indirection level. An instruction or sub-stack with an indirection level of 0 will be executed, but with an indirection level of one or more, the instruction or sub-stack will instead be pushes onto the data stack, or the DS, which is another built-in variable.

The instruction pushed onto the data stack will have an indirection level one lower than the one executed, so A.. pushes A. onto the data stack.

Length 4 snippet

A.B.

Try it!

Since the program itself is a stack (or, rather, a sub-stack of the instruction stack), one might expect B to be pushed first, since it's presumably the top element of the stack. That's not true, however, since the program stack and its sub-stacks are reversed before being pushed onto IS for that exact reason: it's difficult to write code backwards. In other words, the above program pushes A, then B.

Length 5 snippet

[].IF

This program first [] is pushed onto the data stack. Then, the built-in variable IF is executed. IF contains a special magic instruction that pops once from the data stack, then once more if the first element was an empty stack (or a variable whose value is an empty stack). Here, the stack is empty, but there's no elements left to pop after it's gone, so the program will throw an error.

Try it!

Length 6 snippet

[A].IF

Try it!

Unlike the length 5 snippet, the IF instruction here is applied to a non-empty stack, so it'll only pop once and will therefore not throw an error.

Length 8 snippet

B.A.SET

Try it!

This program pushes B and A onto DS before executing the SET instruction, which sets the top element of DS to the second element from the top. Since both A and B are uninitialized, they'll retain their (nonexistent) values, so it would probably make more sense to set A to [] or something.

Length 9 snippet

IS.UNWRAP

Try it!

After pushing IS onto DS, the built-in UNWRAP instruction will replace IS with a reference to its value. This means that if the current value of IS changes, so will the stack reference in DS. If IS is reinitialized by the SET instruction, however, the stack reference in DS will still refer to the previous value.

Length 10 snippet

[].SET.SET

Try it!

The built-in variables that makes sense to execute aren't defined as magic instructions, but rather as stacks containing magic instructions. Therefore, they can be given a new value like any other instruction. This program sets SET to an empty stack, making SET a noop and [min]mod Turing-incomplete.

\$\endgroup\$
1
5 6 7
8
9

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.