552
\$\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
    Jan 4, 2023 at 1:43

241 Answers 241

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

1+

I know the restriction is relaxed now but I "wanted" to follow the old rules, because 1. I'm lazy 2. I want people to care about it

And yes I do have more (currently hidden from the rest of the wrodl) snippets I'll post them if you upvote

Factoid

1+ is a fun deque-based language (although it's often referred to as a stack-based language). 1 is the only literal and, furthermore, we only have + and * but not - or /, which makes some 1+ programs fairly hard to write. (Or probably I'm just not particularly clever whatever) It's still, however, easier to use than most Turing tarpits.

1 byte

1

The only literal in 1+. Almost no program can be built without it.

2 bytes

1+

Yay, language name! It increments the top of the stack. This is where the name of the 1+ chatroom, "increment", come from. It's non-trivial to decrement the top of the stack, however.

3 bytes

"<*

Damn community wiki, I don't even know when I was upvoted... until now.

This snippet features the < operator. It's the only comparison operator in 1+, and returns the boolean value a <= b (where b is the stack top and a is the number behind it). Also, " duplicates the top of the stack and * multiplies the top two numbers.

This snippet pops the stack if the stack have at least 2 numbers. (It is impossible to get back to an empty stack without outputting.) Because a <= a is always true it replaces the stack top with 1. Then the multiply operator get rid of that 1 since a * 1 = a.

4 bytes

1+1<

Inverts the top of stack. (That is, if the stack top is 0 replace it with 1, otherwise replace it with 0.) This actually turned out to be quite useful in some places, for example dealing with 1+ control flow.

It works by computing a + 1 <= 1 and not a <= 0 since pushing a zero is 5 bytes 11+1<.

5 bytes

(|())

Infinite recursion. This is a function definition, but functions are executed once when they are declared in 1+ (very golfing-friendly).

The function declaration syntax in 1+ is (name|code) and it is called with (name). Here the name of the function is empty and it calls itself repeatedly.

7 bytes

(|"<##)

I don't have anything for 6 bytes, so here you go. This is a pop function that works anywhere (unless the stack is empty, of course). It's here to showcase the # instruction (The only other place I remember using this function is the input template) which is the only type of control flow. It pops a number n, and jumps to the instruction after the nth #. (It is 0-indexed, which is sometimes really annoying when golfing but sometimes, not so much.)

Functions creates "seperate lines of execution" according to original specs - this confuses lots of readers! Interpreter-wise, when executing a function, the interpreter calls itself. This means all # outside the function are ignored and the indexing starts from 0 again. (And all # inside the functions are ignored in the main line, that's what was meant by seperate lines of execution.)

This snippet creates a function with an empty name (because functions are executed once when they are declared, there are no need to call it). New function definitions overrides old definitions, so it will always work.

"< replaces the top number with 1, the original value doesn't matter, much like the 3 byte snippet. The following # pops a number, in this case it is 1, and jumps to the second # (don't forget it's 0-indexed!) so the 1 is gone. Then we reached the end of the function.

\$\endgroup\$
4
  • \$\begingroup\$ Explain downvote. \$\endgroup\$ Aug 19, 2020 at 4:26
  • 1
    \$\begingroup\$ Lyxal probably accidentally downvoted... \$\endgroup\$
    – user96495
    Aug 21, 2020 at 2:45
  • \$\begingroup\$ @petStorm Accidentally X Intentionally V \$\endgroup\$ Aug 21, 2020 at 3:07
  • \$\begingroup\$ Just a note: I ran out of ideas. \$\endgroup\$ Jan 29, 2022 at 15:19
8
\$\begingroup\$

zsh

1 byte

a

a is not (normally) a defined command in zsh, so why is it useful? Because it generates an error message (zsh: command not found: a). Errors are a key part of zsh golfing, because it (and other languages in the Bourne shell family) is unique among practical programming languages in their error handling - almost all errors are ignored by default, which is great for golfing. Also, since errors are so easily to generate, they are also essentially the best way to implement conditionals:

2 bytes

&&

The && operator chains two commands together, but only runs the second if the first succeeds. There is also ||, which does the opposite. They are pretty much the shortest way to implement conditional expressions, because if you can make your command generate an error in some circumstances, then you can use && instead of a bulky if statement.

3 bytes

>$1

This is probably one of the most used trigraphs in my zsh answers, but what does it do?

Well, the parts in isolation are $1 is the first command-line argument, and > redirects a command to a file. But there is no command? Ah, but when no command is provided, zsh uses the value of the NULLCMD environment variable, or cat by default. Therefore, it cats all of stdin to a file named the first command-line argument. stdin is generally not the optimal input method, and therefore I don't use it often, so it doesn't generally matter what goes into the file, but it matters that the file is created.[1]

Why does it matter that we create a file? Because the shortest way to do string pattern-matching in zsh is with so-called "globbing". A glob pattern-matches to a file. I've given an overview of globbing syntax here, but it's generally the easiest and shortest way to check if two strings are equal, or check for substrings or match all sorts of patterns (especially with the --extendedglob option). You can even create patterns dynamically, like I used in my Is it a lobster number? answer.

[1] If stdin is really needed, you can use :>$1 which pipes a no-op command, or enable the --shnullcmd option which changes that cat default to a no-op

4 bytes

echo

The echo builtin prints a string, like echo hello. Pretty simple, right? But we can actually do 2 bytes better, with the <<< syntax:

<<<hello

This is called "here-string" redirection, and it's equivalent to doing echo hello | command. Like before, there is no command, however, so it's passed to cat (see NULLCMD above) and hence to stdout.

The <<< syntax has some limitations, like:

  • it only expects a single word, so some expansion/word splitting techniques don't work
  • the expression on the right is evaluated in a subshell, so assigning variables there won't take effect outside the command
  • it's not a true command, so it can't be aliased and can't always be used in some complex statements
  • if you want to print only a newline, a bare echo is one byte shorter than <<<""

...but it can be chained without command separators, like <<<a<<<b, because multiple redirections are going to cat (thanks to multIOs). This is particurlarly useful in eval "loops" (see 7 bytes)

5 bytes

set -y

Unlike most shells, zsh does not perform field splitting by default, so variable expansions almost never need to be quoted. The -y option re-enables such splitting, which is useful in some circumstances.

zsh in fact has a plethora of command-line options, most of which can also be set dynamically with set, setopt, or unsetopt; some more interesting options include:

  • -e: errors are no longer ignored, and the shell exits immediately if one happens. If you can generate errors in some circumstances, this can act like a logical AND over the program which is useful for s
  • -n: disables all command execution. Who knows why...
  • --extendedglob: enables a whole load of extra syntax goodies for globbing
  • -F: globbing is disabled. This is useful if you don't need to do any pattern matching but want to include unquoted special characters like *. Particularly useful in
  • --forcefloat: changes division in arithemtic expansions to always produce a float, even if both operands are integers
  • --cprecedences: changes operator precedence of bitwise operators in arithmetic expansions. By default they are tighter-binding than even exponentiation, and this makes them exactly as they are in C[2]

You can find the full documentation for all of these in man zshoptions.

[2] although this still isn't the most sensible, as comparison operators are tighter than bitwise AND/XOR/OR, in what may go down in history as Dennis Ritchie's greatest mistake

6 bytes

hash -d

While not so useful in , but this provides a mechanism very handy for interactive command-prompt use of zsh. You may know that ~ refers to the home directory; well now you can define more directory aliases of the form ~a. For example, hash -d a=/usr/local means that echo ~a/bin/cat will print /usr/local/bin/cat.

It might be useful in , but I haven't actually found a use for it yet outside my dotfiles.

7 bytes

{1..$1}

{1..$1} constructs a range from 1 to the input, and expands them as separate words. This alone is not too interesting, but if you put some more string around it, like x{1..$1}y, then it can create a range with the string, like x1y x2y x3y .... If you replace x and y with partial snippets of zsh code, and then pass them to the eval builtin (which evaluates strings as zsh code), you can construct ugly-looking loops, which are often shorter than using for.

8 bytes

${a/w/} 

The ${...} construct introduces parameter expansion. In the above example we are doing a text replacement on variable $a, and removing any w characters from its contents. Zsh has a pretty reasonable regex engine. Parameter expansion also does tricky things with arrays and expansion flags. Example

9 bytes

alias A=B

alias defines token aliases (in the sense of C pre-processor macros), so in the example above, A will be replaced with B in parsing. If you're using a particular construct often, this can shorten it. For example, to output a lot of stuff, you can do[4]:

alias A=repeat\ 1000000
alias B='A A A A'
alias C='B B B B'
C C C C echo hi

With a little syntactic trickery, you can even alias operators:

alias X='&&'
(true)X echo hi
# => hi
(false)X echo hi
# no output

[3] Actually, for normal commands alone, it's shorter to define a function: A()command $@; [4] This is by far non-optimal for the most finite output, but what ever

10 bytes

emulate sh

zsh has a built-in command to make its behaviour much more closely mirror the POSIX shell standard (and it can also emulate csh and ksh). I don't think it will ever have a use in , except maybe or , but it's another reason that zsh should be the only shell installed on your system.

Factoid

Who needs awk, sed, or half of the other core unix utils when you can write simple Zsh code like the following from the Zsh User Guide?

This chapter will appeal above all to people who are excited by the fact that
print ${array[(r)${(l.${#${(O@)array//?/X}[1]}..?.)}]
prints out the longest element of the array $array [...] This is for advanced students only (nutcases, if you ask me).

\$\endgroup\$
1
  • \$\begingroup\$ Instead of hash -d I use zoxide (which is kinda like autojump or zsh-z). It allows you to navigate directories with a single z <dir> where dir is a recent directory, or partial match of its name. \$\endgroup\$
    – roblogic
    Nov 19, 2021 at 3:22
7
\$\begingroup\$

Stylus

Considering CSS is in here, I might as well add this in.

Stylus is a language which is compiled in to CSS3. It's easy to use and adds many features in to the language, like nesting, variables, functions, maths, and relaxed punctuation requirements.

Length 1

=

Unlike other CSS pre-processor syntaxes, Stylus allows a variable to be named by any Unicode character that isn't a whitespace, number, or used symbol, without using the $ symbol to denote variables. CSS does not have any concept of a variable.

Length 2

p
    a

Nesting allows you to stop repeating the names of the elements, and looks much prettier and easier for a person to read.

\$\endgroup\$
7
\$\begingroup\$

Simplex

Version is the latest, unless otherwise specified; interpreter is currently down; docs a little unupdated as of now.


6-vote

1(D)10
1      ~~ sets current byte to 1
 ( )10 ~~ repeat inner 100 times
  D    ~~ double current byte
       ~~ implicitly output byte

This outputs 2^10 in its exact form. Simplex has something I liked to call “Infinite Capacity Numerics®”. It can be a bit slow sometimes, but is/will be highly precise.

5-vote

"hi"g

Writes a string hi to the strip and outputs it.

4-vote

eRPE

Outputs eπ ≈ 23.1406926328. e is Euler's number, R goes right in the strip, P is π, and E is exponentiation. Output is implicit.

3-vote

i¢I

A little code that takes numeric input, terminates if input = zero, otherwise increments the byte. Implicitly outputs the result. (It's also French! (ish): ici => here)

2-vote

MO

Shortest way to create a bounds error; M decrements the byte and O goes to the current byteth position in the source code…maybe I should include negative source codes…nah, who'd go for it?

1-vote

5

Not very interesting, but writes 5 to the current strip's first cell. (Also implicitly outputs 5.)

0-vote

Simplex is a golfing language which functions similar to BrainF***, made by me. It is very much a work in progress, but has about 60 standard commands. It is composed of a singular field, which holds a bottom-closed, top-open, infinite amount of strips, each of which contains a right-open, left-closed, infinite amount of cells and a pointer. The field can be visualized as thus:

5: [0 0 0 0 0 0 0 ... ]
    ^
4: [0 0 0 0 0 0 0 ... ]
    ^
3: [0 0 0 0 0 0 0 ... ]
    ^
2: [0 0 0 0 0 0 0 ... ]
    ^
1: [0 0 0 0 0 0 0 ... ]
    ^
0: [0 0 0 0 0 0 0 ... ]
    ^

Each pointer moves independent of other pointers. Typically, only one or two strips are utilized in a single program.

\$\endgroup\$
4
  • \$\begingroup\$ ¢ is two bytes \$\endgroup\$ Nov 4, 2015 at 14:19
  • \$\begingroup\$ @SuperJedi224 no, it isn't. \$\endgroup\$ Nov 4, 2015 at 15:06
  • \$\begingroup\$ @SuperJedi224 And even if it was, this challenge is graded on characters, not bytes. \$\endgroup\$ Nov 4, 2015 at 15:11
  • \$\begingroup\$ in UTF-8, it is. I suppose you're right that it doesn't matter here though. \$\endgroup\$ Nov 4, 2015 at 20:09
7
\$\begingroup\$

Carrot

4-byte code

0^*2

(Prints 000)

I have chosen to use this snippet because of its weirdness. So the first bit of the code says that the stack is 0. Then the * is string multiplication. It multiplies "0" 2 times. One would expect the output to be 00, but no! 000 is outputted instead. So the stack is repeated 2+1=3 times, which gives 000. This trick is useful for golfing when you want to output the stack 10 times. Instead of going (stack)^*10, you will do (stack)^*9 because it saves one byte!

3-byte code

$^P

The $ is the alternative to # for taking input. In the future I hope to distinguish these two similar functions... Coming back to the topic, we see the caret ^ for the first time. This is to differentiate the stack from the commands. Then comes the P. This checks if the stack is a prime or not(works for the number 1). This primality checking works on the stack both as a string or as a number. This "special power" of P can make it more useful for code-golfing.

2-byte code

#A

Outputs inputA. If the input is C, then the output would be CA

This piece of code shows two interesting properties of Carrot:

  1. One is that the string "A" does not need to be enclosed in quotes in the stack.
  2. The other one is that the plus "+" sign for concatenation is not required in the stack. The two strings, the input and the "A", get joined together automatically.

1-byte code

#

This is a simple program that prints the output as it is. The # can be used in the commands or the stack section of the program. The caret ^ is not required because we do not wish to use commands.

Factoid: Carrot is a language made by me, Kritixi Lithos, based on this carrot meme of PPCG. Every Carrot program as of version ^2 must have a ^ in it. The structure of every program is as follows: stack^commands.

\$\endgroup\$
3
  • \$\begingroup\$ whaaat no carrot required? XD \$\endgroup\$ Nov 3, 2015 at 17:21
  • 1
    \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Carets are not required from Version ^3 and forth if we want to use no commands. \$\endgroup\$
    – user41805
    Nov 3, 2015 at 17:23
  • 1
    \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ There! The carrot is back again in the third byte! \$\endgroup\$
    – user41805
    Nov 3, 2015 at 17:41
7
\$\begingroup\$

JacobFck

JacobFck is a stack based esoteric language written in C#. It is capable of all basic operations as well as some more common operations. It is a slight mix of BrainFuck like syntax and Forth. The link above links to the JacobFck GitHub.

Length 1

>

This is one of the simplest instructions. It writes to the screen whatever is at the top of the stack.

Length 2

^5

The ^ instruction tells the interpreter that we are going to be pushing data (either number or register value) onto the stack. In this case, the number 5.

Length 3

"s"

Strings (encased in "") are automatically pushed to the top of the stack, and \n \t \r are all supported escape codes.

Length 4

^2<+

This code would push 2 to the stack with the ^ instruction, push user input to the stack with the < instruction, and add the two together by popping them off the stack and pushing the result to the top.

Length 5

:a<_a

This code is an example of an infinite loop. :a declared the label a. < is the instruction to prompt the user for input. _a goes to the label a.

\$\endgroup\$
7
\$\begingroup\$

Wierd

Factoid

Unlike other languages where the symbols in a program determine which instructions are executed, in Wierd, it is the bends in the chain of arbitrary symbols that determine which instructions are executed.

Chris Pressey created the angle-to-instruction mapping, and christened the entire mess "Wierd"--a cross between the words "weird" (which the language seemed to be) and "wired" (which would describe the appearance of programs written in the language)

You can try it online at http://catseye.tc/installation/Wierd_(John_Colagioia)

Length 1 Snippet

!

The actual character used doesn't matter - it can be any non whitespace character. This program doesn't do anything because there are no bends in the chain of characters - but there is a chain so at least it is a valid program.

Length 2 Snippet

++

Now we are going somewhere - we have a chain of characters. Still no bends so you wouldn't expect it to do anything but unintuitively this program does actually do something.

The current location starts in the top left corner facing "diagonally down and right". The current location always moves with inertia - it will move in the direction it is already moving until it can no longer do that and then will move in a direction closest to the current direction.

So the current location has to change 45 degrees so that it can continue to the right and that counts as a 45 degree bend so we push 1 onto the stack - exactly the same outcome as the Length 5 Snippet.

Length 3 Snippet

+
+

Same as the Length 2 Snippet this program does actually do something because the current location starts in the top left corner facing "diagonally down and right" and the current location has to change 315 degrees so that it can continue to the right and that counts as a 315 degree bend which will subtract the two items on the top of the stack. But there is nothing on the stack so the bend is a no-op and the program does nothing.

Length 4 Snippet

+
 +

The current location starts in the top left corner facing "diagonally down and right" so there are no bends in this chain of characters and so this program doesn't do anything.

Length 4 Snippet

+
++

Finally a program with a bend! But it doesn't do anything useful :(

The current location starts in the top left corner facing "diagonally down and right". The current location always moves with inertia - it will move in the direction it is already moving until it can no longer do that and then will move in a direction closest to the current direction.

So the current location moves "diagonally down and right" and arrives at the next bend. It is a 225 degree bend so if the stack were to contain a zero it would push one character of standard input onto the stack and if it were a nonzero value then a value from the stack would be written to standard output. But there is nothing on the stack so the bend is a no-op.

Now the current location moves around the bend without doing anything, the current direction is towards the left and we are at another bend. This one is a 270 degree bend so if the stack were to contain a nonzero value the current direction would reverse. But there is nothing on the stack so the bend is a no-op.

Now the current location moves around the bend without doing anything, the current direction is up and we are at another bend. It is a 270 degree bend so if the stack were to contain a nonzero value the current direction would reverse. But there is nothing on the stack so the bend is a no-op.

Now the current location moves around the bend without doing anything, and we are in an infinite loop.

Length 5 Snippet

+
 ++

Finally a program that does something!

The current location starts in the top left corner facing "diagonally down and right" so the current location moves "diagonally down and right" and arrives at the next bend. It is a 45 degree bend so we push 1 onto the stack.

There are only four ways to get values onto the stack:

  • Push a 1
  • Subtract two values already on the stack
  • Use a value on the stack to decide to read from standard input
  • Use corordinates on the stack to read a value embedded in the program

So the only way to get a value onto an empty stack is to push a 1.

\$\endgroup\$
7
\$\begingroup\$

GoLScript

Interpreter.

5-vote

HAAZW

This is another simple program.

Generation 0

H pushes 7, A pushes 0. Z is a fun command that pops Y, X and pushes the character at FIELD[Y][X], or (X,Y). In this case, the character at (0,0) is H, and so it's char code is pushed. W outputs this as a character.

The two outer-most cells die.

Generation 1

We are left with AAZ, another call to Z, pushing h's char code to the stack (as the former H is now dead and thus lowercase). However, since the W died, it can no longer function, and thus, this phase ends.

Once again, the two outermost cells die.

Generation 2

Now, only A is left, which carries out its duty in pushing a 0, and then dies. The program is effectively stopped.

4-vote

Bp
P

(newline counts as a character, iirc.) This does something rather simple:

  1. The program is first BpP. This pushes 1 (B), pops a value (1) and assumes it p => P, and does that again, popping a zero from the bottom of the stack P => p.
    1. Checking, only the new P survives, as it popped a value and lived. The rest of the characters died.
  2. After, only the P remains; it pops an empty value (0) and dies.

3-vote

JXJ

First multi-step program! Here's what happens:

Generation 0

The code is evaluated: J pushes 9 to the stack, X pops a number and prints it, and J again pushes 9 ot the stack.

The cells' live-states are updated. Both Js die, having only 1 neighbour. The X lives, as it has 2 neighbours.

Generation 1

All that remains is the X. This prints the remaining 9 off the stack.

The X dies, and the program terminates.

Final output

99

Hey, it's a start…

2-vote

@V

The shortest (?) still life in GoLScript. @ negates the top of the stack (effectively pushing true) and V reads the top of the stack, and dies if the value is falsey. Replacing @ with any of B-J would also produce a still life.

1-vote

X

Any 1-length program is valid. This one takes a zero of the stack (there is an infinite amount of zeroes atop the stack) and outputs it as a number.

0-vote (factoid)

GoLScript simulates Conway's Game of Life! Yay! Interpreter. You'll have to copy-paste the codes, and output is the bottom-most code block.


Language information

  • GoLScript is stack-based.
  • GoLScript has no native string quoting!
\$\endgroup\$
7
  • \$\begingroup\$ When will we run out of names beginning with Gol...? Gol><>, Golfscript, GoLScript, Golang (okay, not very golfy, but you get my point) :P \$\endgroup\$
    – cat
    Apr 27, 2016 at 22:43
  • \$\begingroup\$ @cat upvote it if you like it ;) it's "Game of Life"... \$\endgroup\$ Apr 27, 2016 at 22:44
  • \$\begingroup\$ I think you meant Game of Code Golf, since Code Golf is life... \$\endgroup\$
    – cat
    Apr 27, 2016 at 22:46
  • \$\begingroup\$ @cat GOCG doesn't have as nice of a ring to it ^_^ \$\endgroup\$ Apr 27, 2016 at 22:47
  • \$\begingroup\$ Add permalinks to the Interpreter \$\endgroup\$
    – Cyoce
    Apr 30, 2016 at 1:20
7
\$\begingroup\$

Reng

5-vote

1¶:+!

This uses an intersting feature: default stack pop override! pops n and sets n to the default value when popping from an empty stack. (This is 0 by default.) What this code does is initially lay down a 1, sets that as a default pop, : duplicates value (getting default pop) and adds it with the default pop, leaving twice the default pop on the stack. ! skips the 1 instruction, and sets the default pop to twice what it was.

4-vote

is~o

This is a cat program. It takes input (i), s jumps if the byte != -1, and o outputs. When reading EOF for input, -1 is put on the stack, and the program terminates.

3-vote

9#q

This stores the number 9 in the variable q.

2-vote

{}

Reng has codeblocks! This pushes an empty codeblock to the stack. Forever.

1-vote

~

This ends the program.

0-vote

Reng is like ><>, but with some more functionality. Not made for golfing, as you may come to see... ;)

\$\endgroup\$
7
\$\begingroup\$

Molecule

Factoid
Molecule is the descendent of Pylongolf2, a descendent of Pylongolf which was based on CJam.

0 byte snippet:

 

This does not do anything as it is empty.

1 byte snippet:

I

I read the input.
As Molecule outputs everything in the stack once the program shuts down, this makes a decent cat program.

2 byte snippet:

()

Anything between ( and ) is looped until ! is called.

3 byte snippet:

Inh

Read the input, convert it into a number.
The h converts numbers into characters.
So you can get some funky characters by using this.

4 byte snippet:

`q`n

Now here's where you could break the program.
Molecule has a built-in reflections system that allows you to modify the source code at runtime.
`q Push the source code, `n sets the source code to itself.
From v5.5, this snippet forces the interpreter to read from the start, creating a loop.

5 byte snippet:

0(1+~)

Have your program count until it reaches Infinity.. then it crashes.
(On my computer takes about 2 minutes to crash :P)

6 byte snippet:

u10000

Print 10000. What is so interesting about this?
It's interesting because putting a simple 10000 will push 1 and 5 zeroes to the stack, while the u keyword pushes the entire number after it.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ I can't wait for the 2 byte snippet! \$\endgroup\$ Apr 25, 2016 at 16:59
7
\$\begingroup\$

Poslin

Factoid

Poslin is a concatenative language with strict postfix notation and a metacircular interpreter.

It is similar to the language described in EWD28 in principle but is not inspired by it.

Unlike the language described in the linked paper, the immediateness of a symbol is definable in code, allowing the programmer to define almost arbitrary new syntax. Things like the symbol table and lexical environments exist as first class objects.

Every token in Poslin is surrounded by whitespace.

Length 1 snippet

!

This is actually not a working program. Executing it in a fresh session gives a stack-bottom-error. This operation is immediate and executes the operation on top of the current stack. Without it, nothing would ever happen.

Length 2 snippet

&+

This also isn't a working program. & is an immediate operation to compile something into a thread. &+ also is an immediate operation, but after compiling it executes the operation stored at a place accessible via HOOK compilation-hook slot-sub-get.

This way users can define their own optimization passes.

Length 3 snippet

[ ]

This creates an empty stack. [] also creates an empty stack ad does so much more efficiently. That's because Poslin works with something which is called the path. The path is a stack of environments, where environments are kind of like prototyped objects, that is, they are mappings (from symbols to bindings) which can have parent-environments. When some object is found by the reader which is not an immediate symbol, it is put onto a stack which is saved in a binding (besides the path, the return stack and arguably streams the only mutable data structures in poslin) which is found under the symbol STACK in the environment on top of the path.

[ puts a new environment onto the path which contains a fresh binding containing an empty stack for it's STACK. ] pops the topmost environment off the path and then extracts the stack saved in the binding in its STACK slot.

[] just constantly returns an empty stack.

[], [ and ] are all immediate.

Length 4 snippet

'& &

There is no single operation in poslin which defines a new operation. Well, actually there are several, but they're all defined in the standard library, which is written in a subset of poslin called "poslin0".

& has the purpose of transforming a given object into a thread.

For threads it's just an identity operation.

Symbols are looked up in an environment saved in a binding in the OP slot of the environment on top of the path.

Stacks are converted by turning everything but threads into constant functions returning that object and then concatenating together the resulting objects into one thread. At least, that's roughly how it works. This means, of course, that any operation which should be called inside a thread created this way needs to be turned into a thread via & before the calling thread is constructed.

Every other object is turned into a constant thread returning that exact object.

'& is special syntax: The leading ' tells the reader that this is a quotation, that is, everything after the ' is interpreted as a symbol (including any other 's) and then just put onto the current stack without checking for immediateness.

So the given snippet returns the thread of our poslin compiler. It is used in the operation ]o, which defines a new operation. With the knowledge given up to this point, you might be able to figure out how defining an operation works conceptually, even if you are missing some important operations.

Length 5 snippet

$:
":

This is the string you'd normally see as "\"" in most other languages, that is, the string containing exactly the double-quote character.

The character $ starts a delimited string. A delimited string has a delimiter, which is given between the $ and the next newline. The string contains all characters between that newline and the next occurence of the delimiter followed by some kind of whitespace.

If the delimiter occurs and is not followed by whitespace, it is a part of the string and does not function as delimiter. Remember: Every token in Poslin is surrounded by whitespace.

So, the given string could also be written as

$"
""

or even """, as Poslin recognizes the usual syntax for strings, too. It does not recognize any escape sequences.

Length 6 snippet

+ call

This is almost equivalent to + &. The important difference is that + & returns the thread of + while + call returns a thread which reads the binding which holds the definition of + and then calls the content of that binding. So, if you expect that the definition of + might change and you need to call the new definition instead of the old one, use + call.

This is necessary for defining recursive operations. There is no way to insert a thread into itself, so the binding which is later intended to contain the thread is inserted instead via call and after the thread is constructed it is written into that binding.

Length 7 snippet

. ? ! !

? consumes the top three elements off the stack. The third from the top needs to be a boolean value. If it is true, the second from top is put back onto the stack, if it is false the first from top is put back onto the stack.

. is simply the no-op.

So this is an immediate when. Imagine the following stack:

[ 2 TRUE P{negation} ]

This proceeds as follows with the above sequence:

[ 2 TRUE P{negation} . ]
[ 2 TRUE P{negation} . ? ]
[ 2 P{negation} ]
[ -2 ]

Whereas if the stack is

[ 2 FALSE P{negation} ]

It proceeds thus:

[ 2 FALSE P{negation} . ]
[ 2 FALSE P{negation} . ? ]
[ 2 . ]
[ 2 ]
\$\endgroup\$
7
\$\begingroup\$

Desmos

Factoid: The Desmos community has a wealth of programs that use many math equations to make them work. Take, for example, this 3D visualizer.

1 byte

x

One of my favorite things about Desmos is that you can write out equations like this without having to put y= before it, as Desmos automatically does it for you.

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

Quetzalcoatl

6 snippet:

{c.I?}.

Makes a block with Code Snippet 4.

5 snippet:

{c.I}

Makes a code block, containing the code c.I. On snippet 8, we will use this.

4 snippet:

c.I?

Same as before, but also does power. Result is xth root of x.

3 snippet:

c.I

Outputs (input, 1/input) because I in 1/.

2 snippet:

c (or any token) + -q compiler flag

Proper quine. -q outputs source instead of running code.

1 snippet:

1 or (no code) + -n (1 byte).

Like in GolfScript, numbers just push their value. This outputs 1 because Quetzalcoatl implicitly prints the stack. This works for any digit 0-9. Second snippet outputs Quetzalcoatl, because -n outputs Quetzalcoatl.

Interesting fact:

Quetzalcoatl got its name from the Aztec snake god (I wrote it).

\$\endgroup\$
2
  • \$\begingroup\$ Is this meant to be a golfing language? \$\endgroup\$
    – Cyoce
    Apr 9, 2016 at 21:50
  • \$\begingroup\$ @Cyoce This is a golfing language. \$\endgroup\$ Apr 10, 2016 at 15:37
7
\$\begingroup\$

Coffeescript

Description:

Coffeescript is a language that compiles into Javascript. It's much less verbose than JS (and about the same as ES6), which makes it friendlier for ing.

Factoid:

Coffeescript doesn't require brackets with function calls.

Length 1 Snippet:

=

The = sign means a lot of things in Coffeescript - it can assign both functions and variables in one fell swoop, much like Javascript.

Length 2 Snippet:

**

This is the power sign, which is used like this: a**b. It replaces JS's Math.pow(a,b), which saves 11 bytes.

Length 3 Snippet:

(n)

This is an argument in CoffeeScript, and is used like so:

{function name} = (arg1, arg2...) ->

(This is basically the same as JS, but I just wanted to show off functions - because they're so different).

Length 4 Snippet:

0..5

For-loops are different in CoffeeScript. This snippet, when put into this context:

for a in[0..5]

Is the same as JavaScript's

for (a=0, a<5, a++)

and Python's

for a in range(5)

As you can see, this snippet shows the byte-saving powers of CS.

Length 5 Snippet:

n=->1

Yay, a full function!

This snippet creates a function, n, with no arguments, which outputs 1.

Length 6 Snippet:

if n<1

This is an if statement, in CS. Notice the lack of a colon, or curly brackets (yes, no curly brackets!). This compares n, and checks if it's less than 1.

Simple enough.

Length 7 Snippet:

class A

This is a class declaration in CoffeeScript. Despite there being no support for classes in JavaScript, there's classes in CS - and they work exactly the way you expect them to.

\$\endgroup\$
2
  • \$\begingroup\$ That = declaring functions sounds bad to me. I would say, it is another case when a value is assigned to a variable, just the value is not number or string, but an anonymous function. \$\endgroup\$
    – manatwork
    Aug 11, 2016 at 11:15
  • \$\begingroup\$ Math.power don't exists; the correct function is Math.pow \$\endgroup\$ Sep 7, 2016 at 8:48
7
\$\begingroup\$

Pip

An imperative golfing language with infix operators, with commands in printable ASCII. While these design decisions mean that Pip will probably never beat Jelly in a golf contest, they also make the language much easier to learn and use.

Factoid

To my knowledge, Pip was the first golfing language to have built-in regex support.

The header of each snippet is a TryItOnline link.

Length 1

a

Pip's default method of getting input is by command-line arguments (hereinafter "cmdline args"). The first five args are assigned to the variables a through e, and the whole list is assigned to g.

Since it is at the end of the program, the expression a is auto-printed. So this program outputs the first cmdline arg.

Length 2

/q

To get input from stdin, use the q special variable. Every time it is referenced, it reads a line of input.

Many operators have both binary and unary versions. This is expected behavior for operators like -, and makes good sense for others like ^ split and J join. Here we have a somewhat unusual example: unary / inverts its argument. Inputting 4 will give 0.25 as output, and vice versa.

This snippet also demonstrates a feature that Pip shares with Perl and PHP: numbers are strings and strings are numbers. Both are represented by a data type called Scalar. Upshot: you don't have to convert q's line of input to a number before doing math with it.

But what happens if you input something that's not a number, like Hello world? In a numeric context, it's treated as 0. Dividing by 0, like most error conditions, returns the special nil value, which produces no output when printed. If you want to see what went wrong, you can use the -w flag to enable warnings, in which case Pip will tell you:

Inverting zero

Length 3

Uses the -p flag (+1 byte).

^g

As mentioned above, g is a list of all cmdline args. Many operators work itemwise on lists, and ^ (split) is one of them. This code splits the items of g into lists of characters.

If you ran this 2-byte code without the flag, it wouldn't be obvious what the program did, because Pip's default way of outputting lists is to concatenate the items together. To demonstrate that the split operation worked, we need to change the output format. About half of Pip's command-line flags have to do with list formatting. The -p flag applies RP (analogous to Python's repr) to the list before outputting it, making it easy to see the structure:

> python pip.py -pe "^g" 42 Hello
[[4;2];["H";"e";"l";"l";"o"]]

Use the TIO link above to play around with the other list flags (-s, -n, -l, -P, -S) and see how the output changes.

Length 4

z@<h

Lowercase letters h through z are global variables, preinitialized to different values. z is the lowercase alphabet; h is 100.

The @< "left-of" operator returns a slice from the left end of an iterable (scalar, list, or range). It's equivalent to Python iterable[:index]--except that the Pip version works even when the index is greater than the length of the iterable. In that case it repeats the iterable until it's longer than the index, then takes the slice (like take + cycle in Haskell). So z@<h gives the first 100 characters of the lowercase alphabet:

abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv

Length 5

2>1>0

Comparison operators chain, as in Python. This program returns 1 (true).

\$\endgroup\$
7
\$\begingroup\$

hansl

hansl is a programming language that is used in the statistical software project gretl since 2001. It resembles a mixture of R, Stata, and C. It operates with datasets, time series, vectors, matrices, and functions. Just as in R, there are dozens of user-written packages for econometrics and data analysis. It is a matrix-oriented interpreted language that is Turing-complete (!). Its fortes are econometric estimation and numerical maximisation, and it can be integrated with R, Ox, Octave, Stata, Python, Julia, and gnuplot.

Length 1 snippet

~

You know how difficult it can be to build matrices from vectors? One can attain the effect by reading the input row-wise, column-wise, or through assembling the mess into a dataset? In hansl, you do not hassle: just write ~ between the two vectors, and voila, you get them bound in tight leather together vertically: A~B. Do you have two matrices you want to assemble? X~Y, easy as pie.

Length 2 snippet

$h

This neat accessor returns the series of estimated conditional heteroskedasticity from the last GARCH model. Doesn’t it amaze you that esoteric programming languages have abbreviations for everything? Take that, MATL!

Length 3 snippet

ols

This is probably the most frequently used estimation method in all of econometrics. This command estimates a linear regression model describing the relationship between the dependent variable and predictors (like ols wage 0 age education married), returns the full model and generates many useful accessors (like $uhat for residuals, $aic for Akaike information criterion etc.)

Factoid: Its name comes from the famous fairy tale “Hansel and Gretel” by the Grimm brothers, with a modern twist (like Flick-r, Tumbl-r, and similar names, but gret-l omitted the penultimate vowel long before it became mainstream!).

\$\endgroup\$
7
\$\begingroup\$

Logicode

Factoid:

Logicode has a very limited amount of built-ins (7 built-ins, of which 6 are single-char), which makes it pretty difficult to program anything meaningful in.

Also, it's built on logic gates, as the name suggests, and that's it - which makes it doubly hard to code stuff in.

You can try it online here.

Length 1 Snippet:

+

The + is not addition, as that can be achieved easily. It's concatenation between two "numbers" (which are binary): So, something like 11+1 is not 100, as with regular binary addition, but 111.

Length 2 Snippet:

->

-> is used in two main things: circuits (which are Logicode's version of functions) and conditionals (if statements). It is used to separate the executed code from the arguments (in the case of circuits) or the condition (in the case of conditionals).

Length 3 Snippet:

out

This is a declarer, kinda like var in Javascript to declare a new variable. Logicode has a declarer for anything: out for output, var for variables, circ for circuits (which are basically functions in Logicode), cond for conditionals.

Length 4 Snippet:

!100

The ! is a logical NOT, which is operated on every digit of the binary string that follows. In this case, the snippet evaluates to 011.

Length 5 Snippet:

1&1&1

In Logicode, you're allowed to stack multiple two-arg (dyadic) operators together, as seen here. The & is a logical AND, and the snippet evaluates to 1.

Length 6 Snippet:

@11011

Yay, ASCII support! Because the default "type" of Logicode is binary strings, the @ converts binary to ASCII codes (mod 256). In this case, the character generated is ESC (ASCII character code 27).

Length 7 Snippet:

1000<<<

This program takes the tail of 1000 three times. A tail is essentially every character but the first, so repeating this three times gives us:

1000 -> 000 -> 00 -> 0

So this evaluates to 0.

\$\endgroup\$
7
\$\begingroup\$

MiniStringFuck

MSF- is a way to compress the unique characters of any 0-255 ASCII string to just two characters; and it does pretty well! Although code might just be long.

Length 1 snippet

.

Outputs 0x00.

Length 2 snippet

+.

Outputs 0x01. This does not only demonstrate the . (output), but also the + (accumulator). + essentially changes the accumulator's value (acc) to (acc + 1) % 256.

Length 3 snippet

,+.

It does not really output the next character; it's the same as above, because non-+. characters are ignored.

Length 4 snippet

+.+.

Yay multiple chars!! This outputs \1\2 (escaped chars).

Length 5 snippet

+.+..

This prints \1\2\2. Yes, we need too much upvotes yet to get to a reasonable program.

Length 6 snippet

+.+.+.

Prints \1\2\3. Finally something that looks a little bit more interesting than just some random sequence of unprintables.

\$\endgroup\$
2
  • \$\begingroup\$ A language with just two commands? Isn't this basically similar to the 0s and 1s of Binary? ;p Ah well, +1, looking forward to see what it got in store for us. \$\endgroup\$ Sep 20, 2016 at 14:42
  • \$\begingroup\$ To downvoters: Please do not downvote just because the language isn't awesome. It still has to be showcased. \$\endgroup\$ Nov 13, 2016 at 7:41
7
\$\begingroup\$

Processing

Factoid:

Processing is kind of like the nicer brother/cousin of Java with its syntactic sugar, which introduces a lot of golfing opportunities, as well as GUI stuff which is built-in (because Processing is made for designers to get into programming). See the snippets for its golfing power (especially for graphics stuff).

18 bytes:

size(400,400,P3D);

This snippet not only sets the dimensions of the window to 400x400, but also enables 3D rendering (in just 18 bytes!).

7 bytes:

println

Yup, it's just println, not System.out.println. It's as simple as that.

3 bytes:

str

There's a builtin for converting to Strings from other types (e.g. int, float, long, etc.) in Processing!

\$\endgroup\$
1
  • \$\begingroup\$ You aren't restricted by votes anymore, you know. \$\endgroup\$
    – Pavel
    Jan 2, 2017 at 4:58
7
\$\begingroup\$

Stax

Stax is a stack-based golf-oriented language. That's a pretty crowded space, but stax has a few novel properties. There's an online interpreter.

Two stacks

There are two data stacks, "main" and "input". The language name is inspired by this. Normally standard input starts on the input stack, split into lines. Most operations operate on the main stack. However, if the main stack is empty, read operations fall back to the input stack instead.

Types

Falsy values are numeric zeroes and empty arrays. All other values are truthy.

  • Integer Aribitrary size
  • Float Standard double precision
  • Rational Fractions of integers
  • Block Reference to unexecuted code for map/filter/etc
  • Array Heterogeneous lists of any values

Compressed string literals

Stax has a variant of string literals suitable for compressing English-like text with no special characters. It is compressed using Huffman codes. It uses a different set of Huffman codes for every pair of preceding characters. The character weights were derived from a large corpus of English-like text. "Hello, World!" could be written as `jaH1"jS3!`. The language comes with a compression utility.

Crammed integer arrays

Similarly to compressed string literals, stax also has a special feature for efficiently representing arrays of arbitrary integers. It uses almost all the printable ascii characters. It uses the information in each character efficiently to embed how long each integer is, and their values. This feature is new in Stax 1.0.6.

Debugger

Stax has a web-based development and execution environment. It runs entirely client-side with no ajax calls. It features a step-through debugger that shows the current state, including all registers, stacks, and current instruction. |` is a programmatic break instruction. There is also a C# GUI and CLI for Stax.

PackedStax

PackedStax is an alternative representation for Stax code. It is never ambiguous with Stax, since PackedStax always has the leading bit of the first byte set. That means the same interpreter can be used for both representations with no extra information. For ease of clipboard use, PackedStax can be represented using a modified CP437 character encoding. It yields ~18% savings over ASCII.

Rationals

Stax supports fraction arithmetic. You can use u to turn an integer upside down. So 3u yields 1/3. Fractions are always in reduced terms. 3u 6* multiplies 1/3 by 6, but the result will be 2/1.

Implicit input eval

Normally the text in the input starts in the input stack. The stax runtime can parse input into stax data structures. This is rather convenient for many PPCG posts, where input formats are flexible. This happens only when certain conditions are met.

  • Input contains no newlines
  • Parsing input succeeded. Support types are integers, floats, rationals, strings, and arrays.

For example, this input would be parsed into corresponding values on the input stack.

1 2.3 [4/5, "foo"]

Examples

Snippet: Length 0

An empty program in stax will reduce a fraction. This is the result of automatically evaluated input, and a built-in rational type. Rational values are always in reduced terms. And since there's no explicit output in the program, the top of the stack is implicitly printed.

Run and debug it

Snippet: Length 1

A one character stax program can filter out the blank lines from standard input. f is generally used to use a block to filter an array, but when it's the first character of a program, it uses the remainder of the program to filter the input lines. The rest of the program is blank, so the filter is an identity filter, and blank lines are falsey.

f

Run and debug it

Snippet: Length 2

This program iterates over the positive integers from 1 to n and adds them.

F+

Run and debug it

Snippet: Length 3

This program gets the first n letters of the alphabet. Va is the lowercase alphabet. ( truncates to the specified input length.

Va(

Run and debug it

Snippet: Length 4

In 4 bytes, you can use a block to map each character to its ascii code in hexadecimal. There aren't strings per se in stax, but arrays of character codepoints are treated as strings in many contexts. {...m establishes a block and maps every element in an array using the contents. |H converts a number to hexadecimal.

{|Hm

Run and debug it

There is also a length-4 proper quine in Stax, which is quite different from how most proper quines are constructed.

..SS

Run and debug it

. is the leading character for a two-character literal and ..S is the string literal ".S". S builds the powerset of the array, excluding the empty set, i.e. [".",".S","S"]. The result is then implicitly flattened and output.

\$\endgroup\$
6
\$\begingroup\$

Sonic Pi

Code Snippet 4:

dice

You don't see anything on the output, but if you show it with puts, it's a random number. Don't worry if your number is always the same, Sonic Pi uses the same random seed for every run, but that's good because else your songs would sound different every time.

Code Snippet 3:

:e1

This equals the MIDI-Note 52 and the frequency 164.81377845643496 hz. It must start with a : so Sonic Pi knows it's an integrated constant.

Code Snippet 2:

[]

Empty list. Sorry, nothing else except comments can be written in two bytes.

Code Snippet 1:

#

Starts a comment.

Factoid: Sonic Pi is a sound coding language and is a full valued programming language.

\$\endgroup\$
6
\$\begingroup\$

StackyLogic

Factoid:

StackyLogic is originially from a codegolf challenge, as seen in the link. It consists of a series of "stacks", however there are no "push" operations.

Length 1 Snippet

<

This is not a full program at all. This is just the pointer symbol. This symbol denotes where the pointer starts

Length 2 Snippet

?<

This program takes a bit of input, and outputs it. It would be a cat program, if it looped, however Stackylogic possesses no loops.

First, the program will substitute the ? for either a 1 or 0, depending on input. Then, it will execute this command. 1 will make the pointer move down one, 0 will make it move up one. Then, upon discovering the empty stack (which are always implicitly exist), it will halt, and output the last executed command, either a 1, or 0

Length 3 Snippet

?1<

This program always outputs one, the ? is never used. This is because, as stated in the previous snippet, 1 will move the pointer down one, and the implicit empty stack will cause the last executed command to be printed. the ? isn't used, because the pointer is never directed to it.

Length 4 Snippet

?
?<

Our first program with multiple non-empty stacks.

This program outputs the result of an OR operation on two bits.

How it works:

It first substitutes the ? under the pointer with a bit from input, and executes it. If it is a 1, it will go forward, find the empty stack, halt and print 1.

?<

If it is a zero, it will go up one, and act like the above code: it will substitute the ? for a bit, execute it, and then move onto an empty stack and output it.

Note how the code after the first ? is executed is the same as snippet 2

Length 5 snippet

1
??<

This program, like the last program, outputs the OR of two bits. However, the ?s are on the same line. if the first bit is one, it will move forward on to an empty stack, output 1, if it is a 0, it will move back one, on to the one, and then move forward back on to the second ?, again being identical to the length 2 snippet. This illustrates how multiple programs can have the same effect. You might have noticed that no new language features have been introduced this time. This is because they have all been introduced.

Length 6 Snippet

1
?<
0

This program outputs the not of one bit (the opposite of snippet 2). You might, by now, think that StackyLogic is really boring, and can't do anything interesting. This isn't (entirely) true. It can be used for more interesting things, it just takes A LOT of characters. However, even after these lots of characters, it is not capable of much computation, it cannot even store the input, most challenges are closed out to it (in fact, the linked example actually checks which year it is, if it divisible by 4, to see if it is a special case (not a leap year))

Length 7 Snippet

?<
?1
?

This program "nests" an OR in a surrounding program. I say it nests it, because if the first bit is 1, it changes to be the exact same as the OR, and executes the same things. This program is (x AND (y OR z))


I don't really know anymore decent snippets, there isn't much more to show. I plan on making another answer with my derivative, Eseljik, after I actually make the interpreter, but before that decide on the final part of the spec. Anyway, there are a lot more commands in Eseljik, so I shouldn't easily run out of things to show, like I have here.

\$\endgroup\$
2
  • \$\begingroup\$ Does StackyLogic fulfill our definition of programming language? \$\endgroup\$
    – Luis Mendo
    Jul 26, 2016 at 15:03
  • \$\begingroup\$ No. If this is an issue, maybe you'd prefer HQ9AddPrimality+? Seriously though, perhaps we should not judge on these arbitrary requirements, that try to regulate boring languages, but using common sense to determine what should and shouldn't be allowed. Though this lacks many abilities of normal languages, it is not abusive, like the language HQ9+, and is kind of fun to answer questions with. \$\endgroup\$ Jul 27, 2016 at 1:11
6
\$\begingroup\$

ListSharp

factoid: ListSharp is an interpeted langauge for list manipulation and web scraping, still in development yet it can already do some neat stuff!

  • syntax is heavily word based so a good amount of votes will be needed for functional snipplets

Length 4 snipplet:

SHOW

SHOW is the standard STDOUT of ListSharp and lets you display a variable in complete disregard to its type

Ex:

SHOW = "Hello world"
SHOW = {"1","2"} + "3"
SHOW = variable_name
\$\endgroup\$
6
\$\begingroup\$

Golisp

Factoid

Golisp is a very simple programming language, but despite it's name it's not a Lisp dialect.

Length 1 snippet

0

Return 0, but since this value isn't used this is a no-op.

Length 2 snippet

""

Return a empty string, but since this value isn't used this is a no-op.

Length 3 snippet

(0)

Create a list with 1 element, 0

Length 4 snippet

+[1]

Call the function + with one argument, 1. The returned value is 1.

Length 5 snippet

chr@5

Use the shorthand notation function@argument. Return the ASCII character ENQ (5), but as always, nothing is printed :/

Length 6 snippet

+[3 5]

Simply add 3 and 5.

\$\endgroup\$
6
\$\begingroup\$

Woefully

Now with TIO!

Factoid:

Woefully is a 2d language with no traditional conditionals (ooh, that rhyme). The closest thing it has to conditionals is the boolean/not_zero command, which pushes int(stack_A.pop()!=0). It's also pretty weird in other ways.

It isn't really possible to even write a program in less than 7 characters, unless you count printing the "error" message as a program, or immediately halting as a program, so perhaps I'll multiply the votes by 4 to get the amount of bytes I can have, if that's allowable (context: it takes 266 bytes to write a truth machine, unless it could be golfed more,)

1*4 bytes

boom

this program technically doesn't error, but just prints "confuse :(", the "error" message of the language, which counts as regular output as it goes to STDOUT, not STDERR. This program doesn't conform to the program composition requirements (needs to have no characters that aren't pipes, spaces and newlines, needs to have at least one space, needs to have no spaces at the start and end of lines), and so automatically prints the message "confuse :("

BTW it is going to be a while before anything really interesting, like even a program that just takes input, or pushes a number, so you might want to look at my truth machine to see what Woefully looks like

2*4 bytes

| |
|| |

Ooh, we have the first program that doesn't just print "confuse :(" and die. This program does... nothing. It is in an infinite loop of nops

Why it nops forever

diagram!

v
|\|
||\|
  X

The char pointer, the first of two pointers, starts at the character pointed to by v. The instruction pointer will find the first space after this char, and execute the path of spaces it is a part of. The \ shows the path. the instruction pointer goes down this path, but does nothing, since lines that are two-long are nops. Once it finishes the path, (symbolised by the X), the instruction pointer returns to the char pointer, which has not moved, and executes it again, forever.

3*4 bytes

| |
| |
| ||

This program terminates in an error (not confuse, but an actual error), but why?

three down executes the A to B command, popping the top of the A stack, and pushing it to the B stack. (there are two stacks). However, the program does not immediately fail, because the stacks start with values already on them: one zero each, it runs once normally, then fails the next iteration of the loop.

4*4 bytes

||| |
|| ||
| ||

This program pushes zero to stack A infinitely. this is because all diagonally down left commands push the length of the command, minus three. minus three because a command that is two long is a nop, so the shortest push command is three long, and the smallest push-able value is zero.

5*4 bytes

| || |
||| ||
|| |||

I didn't really have anything interesting (apart from some more erroring commands) to show this time, but I realised none of the snippets halt, though some error, so this snippet just halts, without doing anything (including the push at the right)

diagram!

v       char pointer starts pointing here
|X||a|   X has the first space after that character, so it's path is executed
|||a|| X halts the program
||a|||   a - never executed
\$\endgroup\$
6
\$\begingroup\$

Majc (formely hashmap)

Factoid
hashmap is not necessarily a golfing language, although it's commands can make it so. (Also it's spelled hashmap, not Hashmap).
It was renamed in June 11, 2016 to Majc.

0 byte snippet:

 

This does nothing.

1 byte snippet:

.

Clear the stack... now.. there's nothing in the stack.. so...

2 byte snippet:

id

Convert input to a number, this is also the long version of h.

3 byte snippet:

h2^

h is short for id, so we're taking the input as a number and get it's squared.

4 byte snippet:

{}:a

5 byte snippet:

isrsr

Kind of lost ideas here, but i takes an input, sr reverses it.

I'm not sure if this still works but this created a code block (based on CJam) and assigns it to variable a. Code blocks are like anonymous functions (unless assigned to a variable).

\$\endgroup\$
1
  • \$\begingroup\$ 2 byte snippet? \$\endgroup\$ Jul 26, 2016 at 0:32
6
\$\begingroup\$

SX

Length 1 Code

Compiles to: pass

Length 3 Code

10才

returns 11. 才 is equivelant to C's ++.

Length 4 Code

品*30

returns the circumference of a circle with a diameter. Assuming math was importing.

Length 5 Code

送我(@)

compiles to def __init__(self):print(self) and will work if put inside a class.

Factoid: sorry pass isn't really that interesting. Sorta interesting, SX is one of the first golfing langauges (I made it when I was in 7th or 8th grade. It also compiles to python.

\$\endgroup\$
0
6
\$\begingroup\$

Dotsplit

(whoops I forgot the link before :p)

(pair of) Factoid(s):

Dotsplit is a mostly syntax free language, with odd builtins (kind of like mathematica), but is currently in it's infancy. Dotsplit is named after the tokeniser used in the interpreter: str.split(). This is a weak tokeniser, but it fulfills all needs of the language, so far anyway.

1 byte:

D

D does

...

nothing. it isn't a tiny builtin, unless you count a nop as a builtin, and it's only a nop because it isn't a defined command. Dotsplit has relatively long command names for most things. Note that the shortest happens to be three long. anything that isn't a defined command is ignored. also note commands are case insensitive, so if it were a command, d would be the same as D

2 bytes:

still not much interesting

 b

b with a leading space. This program functions identically to b, as well as D, because nops, but if b was a command, b and D would not be the same, but b and [space]b would. Spaces are used to separate commands, but otherwise are ignored. Next upvote, and we get an actual command!

3 bytes

First command!

aDd

This will pop a and b, and push a+b. Popping from an empty stack yields 0. hence, this program will leave one 0 on the stack. add is case insensitive, and will function regardless of case (AdD will also work)

4 bytes

There are a fair amount more commands with 4 bytes, not many still. I chose this one

derp

This program will wait for input by the user. If input is "derp" (case-sensitive), it prints "Derp". Otherwise, "Nope"

\$\endgroup\$
1
  • \$\begingroup\$ That derp though... \$\endgroup\$
    – clismique
    Oct 30, 2016 at 8:10
6
\$\begingroup\$

Attache

Factoid: This language originally started out as a joke, based on the "Mathematica has builtins for everything"; this can be seen by the residual Rot command, made for Rot13 and similar challenges.

Length 0 snippet

The empty program is valid in Attache. Try it online!

Length 1 snippet

V

Try it online! The V function was one of the first implemented. It represents a Vector of values, and used to be the only way to create array literals.

Length 2 snippet

`+

Try it online!

This is a quoted operator; it acts just as a function which performs addition. It can be assigned like so:

f := `+
Print[ f[1, 2] ]
?? prints 3

Length 3 snippet

1:9

Try it online! This is a demonstration fo the range operator in Attache. Attache's main focus resides in generation and selection, as is common with functional languages.

Length 4 snippet

Bond

Try it online! Bond is a function used to partially call functions. In this case, Bond[f, n] returns a function which takes arguments ...x and calls f[...x, n]. In the link, this is shown by example:

f := Bond[`/, 1]

This function returns a function which returns the reciprocal of the input. This is roughly equivalent to the lambda:

{ _ / 1 }

…but we'll get to that next.

Length 5 snippet

{_2-_}

Try it online! This is a lambda function, which can be called with any amount of arguments. These arguments are accessible using blanks, with _N referring to the Nth argument, starting at _1. _ is short from _1. So, this function can be written as:

{ _2 - _1 }

This is the 1st argument subtracted from the 2nd. In the example, we assign this function to f. Then, f[3, 6] is 6 - 3, which evaluates to 3.

Length 7 snippet

Print!7

Try it online! This shows the operator form of !, which takes a function on the left and an argument on the right. It's equivalent to function calling. This calls the inbuilt Print function with input 7, which outputs 7.

Length 8 snippet

~{-_'_2}

Try it online! This demonstrates a few more operators in Attache. First, ~, when used functionally, reverses the operands given to a function. So, for example, (~V)[1, 2, 3] would be called as V[3, 2, 1], which gives [3, 2, 1]. ~ has the effect of reversing the order in which abstracts are called. The above function could be rewritten as:

{-_2'_}

Now, the ' operator, when used on data, concatenates them. Since - is unary, it negates _2. This is equivalent to:

{ [ -_2, _1 ] }

Assign it as f, and f[1, 2] becomes [-2, 1].

Length 9 snippet

{Sum!_&_}

Try it online!

& when using data, a&b, creates an array of a copies of b. So, _&_ creates _ copies of _. 4&4 is, for example, [4, 4, 4, 4]. Then, Sum is called on that array. Thus, this squares a number.

\$\endgroup\$
6
\$\begingroup\$

International Phonetic Esoteric Language

Factoid

The International Phonetic Esoteric Language, or IPEL, is a stack-based esolang where the instruction set mostly consists of characters from the International Phonetic Alphabet, and some ASCII.

IPEL is an attempt to apply stuff I've learned from some CS courses since starting college, as well as to create a language for myself for code golf.

Length 1

1

IPEL has 3 types: numbers, strings, and lists. Numbers from 0-9 can be pushed in by using the digit.

Length 2

io

A simple cat program. i takes a string from STDIN, then outputs it with o.

Length 3

"a"

Pushes the string a.

Length 4

1esø

This code increments the loop index by 1. In IPEL, loops are not handled by the interpreter; the programmer has to manually set the loop index. Loops also only check for when \$index \lt end\$, where when true, jumps back to the start of the loop.

Length 5

<f>/\

An empty function definition.

Length 6

{12.34}

This is how you push a float and any numbers larger than 9. Surround it in curly brackets.

Length 7

|a|ɔ|a|

Labels also exist in IPEL. When execution hits ɔ, it will jump to the label specified right after the ɔ. This is also the shortest infinite loop you can do in IPEL.

Length 8

"C"ʁ2zχo

This is my answer to the "A Without A" challenge. It pushes C, converts it to a number, subtracts 2, converts it back to a string, and prints.

Length 9

{zzzzzzz}

IPEL since v1.4.0 includes the ability to push base 36 numbers. zzzzzzz is equivalent to 78364164095 in base 36.

Length 17

<f>/1ue2sø\<f>2u3u

This is the shortest program that demonstrates changing the return pointer of a function call. Without e2sø, this would print 123. With it would print 13 instead, completely skipping the 2 instructions 2u. I'm not sure if there's any practical use for this, but it's a thing you can do.

\$\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.