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

229 Answers 229

13
\$\begingroup\$

Retina

Factoid:

Retina is based on regular expressions, and supports various stages like match, replace, split, grep, antigrep, transliteration, and sort.

0 bytes:

Counts chars in input...+1!

1 byte:

1

Counts the number of 1s in the input. Pretty boring, but can make quick unary to decimal conversion.

2 bytes:

.+

Outputs the number of lines in the input.

3 bytes:

\d

Deletes numbers. (Tip: If you want empty lines to show in code, use <pre> tags.)

4 bytes:

1
$_

Computes squares. (Unary in, unary out)

5 bytes:

T`l`L

UPPERCASES YOUR TEXT.

6 bytes:

G`cats

Finds the [cats]

7 bytes:

\d
$*
1

Sums digits in input.

8 bytes:

^
1
1
$'

Computes triangular numbers. (Unary in, unary out)

9 bytes:

(.)\1+
$1

Dereplicates chars.

10 bytes:

S`.
¶+
$.0

Counts chars in a slightly weird way. (The shortest way is 3 characters.)

11 bytes:

(^x|\1xx)+$

Matches squares.

14 bytes:


\(*S1`
\(*S1`

The shortest Retina quine.

15 bytes:

1
$`$'2
2
$_1
1

Computes cubes. (Unary in, decimal out)

\$\endgroup\$
  • \$\begingroup\$ A few corrections: O`. sorts all the non-linefeed characters of the input, even across lines. S.+` is a split stage which means it doesn't count anything but gives you a string of M + N - 1 linefeeds, where M is the number of non-empty lines and N is the number of lines in total. Also I'm not sure what you mean by "dereplicating chars" but the last snippet just replaces each line with its last character. \$\endgroup\$ – Martin Ender Apr 25 '16 at 10:08
  • \$\begingroup\$ The last example will actually find a match in any input, because it can simply match the end of the string as an empty match. (Of course that still sort of helps to distinguish non-squares from squares.) This could be fixed by either matching positive squares with + instead of * or by prepending ^ to ensure the entire string is matched. \$\endgroup\$ – Martin Ender Jun 24 '16 at 12:26
  • \$\begingroup\$ Your 9 byte program can be written in 3 bytes: D`. \$\endgroup\$ – mbomb007 Sep 20 '16 at 19:32
  • \$\begingroup\$ Nope. xxyyxx. \$\endgroup\$ – CalculatorFeline Oct 15 '16 at 15:32
12
\$\begingroup\$

Burlesque

Burlesque is a stack-based, lazy, concatenative esoteric programming language. It was designed as a utility for students of computer science but it has become a language used for golfing. Since Burlesque has two character built-ins programs obviously grow twice as fast as programs in golfing languages with one character built-ins do. Burlesque is more like a command line utility tool for easy homework or related things like when you need to know what that number in base 4 is or what are the subsequences of this set or what are the permutations of this string and the like.

Burlesque has 400+ built-ins and growing. This also means that Burlesque's power stems from two main factors: The laziness and the amount of built-ins. The drawback is that the language is not very verbose and you can't infer what a code is doing by simply looking at the syntax and control structures since those don't really exist in Burlesque. The only way to understand Burlesque programs is by either looking everything up all the time or by memorizing a lot of built-ins.

Website: http://mroman.ch/burlesque/

Length 1

Cat program:

# Q
$ echo -n "123" | ./blsq --stdin "Q"

Length 2

Reverse a list:

# <-
$ ./blsq --no-stdin "{1 2 3}<-"
{3 2 1}

Length 3

Reverse STDIN:

# <-Q
$ echo -n "123" | ./blsq --stdin "<-Q"
321

Length 4

Add two numbers read from STDIN:

# ps++
$ echo "12 13" | ./blsq --stdin "ps++"
25

Length 5

Show all reversed substrings:

# su)<-
$ echo -n "1234" | ./blsq --stdin "su)<-"
{"1" "2" "3" "4" "21" "32" "43" "321" "432" "4321"}

Length 6

Read integer from STDIN and calculate sum[1..N]:

# riro++
$ echo -n "5" | ./blsq --stdin "riro++"
15

Length 7

Read integer from STDIN and calculate 10^n:

# ri10j^?
$ echo -n "5" | ./blsq --stdin "ri10j?^"
100000

Length 8

Repeat a line from STDIN length(line) times (trailing newline required):

# ~]sa.*uN
$ echo "abcd" | blsq --stdin "~]sa.*uN"
abcd
abcd
abcd
abcd
$ echo "abc" | blsq --stdin "~]sa.*uN"
abc
abc
abc

Length 9

Chance that we have exactly 0 successes within 8 tries where p=0.1 (binomial distribution):

blsq ) 8 0.1 0Bp
0.4304672100000001

Length 10

Convert from RGB to hex (challenge on codegolf):

blsq ) "72 61 139"psb6\['#+]
"#483d8b"
\$\endgroup\$
12
\$\begingroup\$

05AB1E

Length 7 snippet:

Code [Try it online!]:

”Ÿ™,‚ï!

This is using a dictionary compression method. This will result into Hello, World!. Every ASCII character is interpreted as a normal character and every character with a code point above 127 is used for the decompression itself:

”       # Start a compressed string with all words titlecased
 Ÿ      # In Info.txt, you can see that this has index 24
  ™     # Index 19
        # These two indexes combined is 2419, in the dictionary you can see that the
          2419th word is hello
   ,    # Since this has no index, this will be interpreted as a normal character
    ‚ï  # Index 0118, which is the word "world". An extra space before this word is
        # implicitly added.
      ! # Regular exclamation mark
        # All the compressed words are automatically title cased.
          resulting in: "Hello, World!"

Length 6 snippet:

Code [Try it online!]

D=gGÁ=

This creates a square with a rotating string. For example, the input Hello would result into:

Hello
oHell
loHel
lloHe
elloH

The input is first Duplicated, then printed with a newline without popping (using =). We take the length of the string, and create a for loop with G and each time we rotate the string 1 to the right using Á and print it again without popping. This is done length - 1 times, so in total this is done in length times.

Length 5 snippet:

Code [Try it online!]:

žnžo‡

This does the Atbash cipher. The ž command contains all kind of shortcuts to constants. Right now, the list of constants is:

ž 23  > ža           push current hours
        žb           push current minutes
        žc           push current seconds
        žd           push current microseconds
        že           push current day
        žf           push current month
        žg           push current year
        žh           push [0-9]
        ži           push [a-zA-Z]
        žj           push [a-zA-Z0-9_]
        žk           push [z-aZ-A]
        žl           push [z-aZ-A9-0_]
        žm           push [9-0]
        žn           push [A-Za-z]
        žo           push [Z-Az-a]
        žp           push [Z-A]

So, we can conclude that žn is equal to [A-Za-z] and žo is equal to [Z-Az-a]. After this, we just perform a transliteration using .

Length 4 snippet:

Code [Try it online!]:

Œvy,

This is maybe not a very tricky one, but certainly interesting. The Πcommand computes all substring that can be made with the string. Then, we map over the array containing all the substrings using v. y is the variable which holds the string and , prints that with a newline.

Length 3 snippet:

Code [Try it online!]:

³¹²

This is using a pretty neat feature of 05AB1E. What this does is pushing the third input, then the first and then the second. You can see this best with the debug mode on.

Length 2 snippet:

Code [Try it online!]:

LO

This calculates (n × (n - 1)) / 2, which is also the formula for triangular numbers. What this does it make a List in the range [1 .. input] and then calculates the sum using O.

Length 1 snippet:

Code [Try it online!]:

!

Well, this isn't particularly interesting except the fact that input is implicit. When the length of the stack is smaller than the arity of a function, input is used instead. This just calculates the factorial of the input.

Factoid

05AB1E is a language I, (Adnan), have made. It can be pronounced in several ways, like Osabie, Osable, Zero-five A B one E. They are all correct since there is no actual way to pronounce the language. The name itself has a deeper meaning. When interpreted as a hexadecimal number, converting this number to Base64 would result into: Base.

\$\endgroup\$
  • \$\begingroup\$ You forgot to mention O 5 A B 1 E. \$\endgroup\$ – CalculatorFeline May 7 '16 at 0:17
  • 2
    \$\begingroup\$ @CatsAreFluffy Ayy Lmao or Ayy LeMeow? \$\endgroup\$ – Adnan May 7 '16 at 0:30
  • \$\begingroup\$ Also, 05AB1E contains BA5E. \$\endgroup\$ – CalculatorFeline Jan 4 '17 at 19:55
12
\$\begingroup\$

LiveScript

Factoid: LiveScript was on of the early names of JavaScript (mocha is another one), before the need to "make it feel entreprise-y" came up. The language offers features that spans in different paradigms (mostly functional and object-oriented).

1 vote

@

This is simply a shortcut for "this", or property access into "this".

2 votes

->

We can define a function! Albeit empty for now.

3 votes

(+)

The language allows you to use binary operators as functions. They're also curried!

4 votes

v|>f

The pipe is, like in F#, a "reversed" function application: the above is equivalent to f(v).

As a bonus, the opposite operator also exists: (like $ in Haskell)

f<|v

which is equivalent to f(v) (this is useful for precedence).

(of the two, <| has lowest precedence).

5 votes

class

Yes, this actually works as a standalone anonymous classes. They're values, and very powerful – they have executable bodies (a bit like Ruby). This allows to declare method on-the-fly, but that's going to be a bit later :).

6 votes

"#{3}"

String interpolation! It's particularly powerful in LiveScript, where there's even a shortcut for interpolation variables – the braces aren't needed: "#x"

7 votes

->|_=>1

This is a bit useless as-is... but in LiveScript, switches are implicit right after a function declaration (->), and a case can also be spelled | (ML-style). The => is an alias for then (but doesn't require spaces around it), and _ is a catch-all.

This is basically the sugar-y syntax for (a topic-less switch will switch on truthiness):

->
 switch
 # case ...
 otherwise
   1

8 votes

@a{}b[]c

@a is simply @.a, which is... this.a! The language inserts dot for you in my places.

In LiveScript, [] and {} used as infix operators (they're actually infix dot operators, the real spelling is .{} and .[], but those dots can be inferred) are (semi)autovivification (like in Perl)/shaping member access.

(contrarily to perl, you need to use {} and [], hence the semiautovivification)

It means a{}b (or a.{}b) tries to access a.b, but if that key doesn't exist (or is == null), it creates it as an empty object ({}). For a[]b, it does the same, but initializes an empty array ([]) instead.

The postfix ! is actually simply (), an argumentless call. Here again, the language will insert dot as needed:

a!b
a()b
# both mean
a().b
# and equally...
a()['b']
\$\endgroup\$
  • \$\begingroup\$ What's f<|v|>g do in terms of precedence? \$\endgroup\$ – cat Apr 25 '16 at 10:50
  • \$\begingroup\$ @cat <| has the lowest precedence (it used to have an even lower precedence than =, which was a bit of an issue) \$\endgroup\$ – Ven Apr 25 '16 at 12:17
  • \$\begingroup\$ So it's equivalent to f <| (v |> g). Interesting. \$\endgroup\$ – cat Apr 25 '16 at 12:18
12
\$\begingroup\$

Cubix

Click on any snippet's header to try it in the online interpreter!

For reference, the text in bold tells you the important stuff.

Factoid

Cubix is a stack-based language, created by me, which runs like a 2D language such as Befunge. The main difference? The code is run on the outside of a cube.

Length 1

@

This is pretty much the character most commonly used. Why? Because it immediately ends execution of the program. In fact, it's the only way to end the program.

This is useless as a program, though, because it gets turned into this cube:

   @
>. . . .
   .

Where the IP (instruction pointer) is started at the arrow, and . is a no-op. This just loops around forever. Take a good look and you'll see why every possible 1-byte program never ends (or does anything at all).

Length 2

.O

Now that we've gotten over the length-1 barrier, we can finally see some output! Here's the cube net:

   .
>O . . .
   .

where the IP starts at the arrow. O takes the TOS (top-of-stack) and outputs it as a number. If the stack is empty (e.g. at the beginning of the program), this prints 0.

When the IP gets over to the right edge of the above cube-net, it wraps back around to the left edge, onto the O again. Thus, this program prints 0 forever.

Length 3

@O/

Our first cheerleader program that terminates! This gets mapped to the following net:

   @
>O / . .
   .

where the IP starts at the arrow. As we've seen before, the O prints the TOS, which is currently 0, as a number. Next comes a new character: /. This is a mirror. There are five different mirrors: /, \, |, _, and T. Mirrors reflect the IP from one direction to another.

When the IP hits this mirror, it is redirected to the north. This puts it on the top face, which is @. Thus, the program is terminated, and the output is 0.

Length 4

@Io^

This expands into the following cube net:

   @
>I o ^ .
   .

A bunch of new characters here:

  • The first character is I, which inputs an integer from STDIN.
  • Next comes o. This is like O, but outputs a char-code instead of an integer.
  • After that, we see ^. This is one of four arrows: ^, >, v, and <. Arrows point the IP in a specific direction. ^ points the IP north, where it hits the @ and terminates.

Length 5

@i?o_

Finally a (somewhat) useful program. This expands into the following cube net:

   @
>i ? o _
   .

This is a cat program: it prints the entirety of the input, one char at a time.

The first character is i, which inputs a char-code from STDIN. If there's nothing in STDIN, it pushes -1.

Next comes ?. This is one of the most useful chars: it redirects the IP based on the sign of the TOS. If the TOS is negative, the IP turns left; if the TOS is positive, the IP turns right; if the TOS is zero, the IP continues in the same direction.

The combination of these chars does the following:

  • If the input is a null byte, the IP continues straight, outputting with o and wrapping back around to the i. (The _ is a mirror which does nothing when the IP is traveling east-west.)
  • If the input is anything else, the IP turns right, wrapping around to the bottom and hitting the _. This turns it around; it goes back across the bottom and hits the ? again, turning right. This time, though, it's sent through the o and back around to the i.
  • If there is no more input, the IP turns left, hits @, and ends the program.

Length 6

9O/;)o

Our first happy program! ;) This expands into the following cube net:

   9
>O / ; )
   o

The first character is O, which prints the TOS (currently 0). Then the IP hits a mirror / which redirects it over the top face onto the 9. Digits push themselves to the stack. Note that they do not concatenate; 12 pushes a 1 and a 2.

So now the TOS is 9. The IP comes down on the other side of the cube and hits the ), which increments the TOS by 1. Now the TOS is 10, which tells the o on the bottom face to output a newline.

The IP comes up and hits the mirror again, turning to the east. The next character it hits is the ;, which pops the TOS (removes it). The stack is now back to its natural state with infinite 0s.

Next is the ), which increments the TOS to 1. Now the IP is back at the start of the program, except the TOS is now 1 instead of 0. Can you figure out what this program does?


Feel free to add more interesting snippets!

\$\endgroup\$
  • \$\begingroup\$ nice to see you back \$\endgroup\$ – MickyT Sep 7 '16 at 2:41
  • \$\begingroup\$ ... and you've implemented the additional stack operations :) \$\endgroup\$ – MickyT Sep 7 '16 at 3:17
  • \$\begingroup\$ @MickyT Thanks :) Indeed I have, have fun with them! \$\endgroup\$ – ETHproductions Sep 7 '16 at 3:19
  • \$\begingroup\$ +1 from me. I recently saw your print all integers answer and was intrigued by your language and looking forward to see more. In addition, it reminds me of an unfolded Rubik's Cube, and as a twisty puzzle collector I can really appreciate that from a personal view. :) Hexagony and Cubix are currently my top two languages to learn one day, as soon as I have a bit more free time on my hands. \$\endgroup\$ – Kevin Cruijssen Sep 20 '16 at 13:25
  • 2
    \$\begingroup\$ @KevinCruijssen Thank you very much! I like Hexagony very much as well; it was the main inspiration for Cubix. Seeing as you like twisty puzzles, I should tell you that I'm planning to add commands to actually manipulate the program as if twisting a Rubik's cube, which you may find interesting. :) \$\endgroup\$ – ETHproductions Sep 20 '16 at 13:51
11
\$\begingroup\$

Python 3

Factoid
Python 3 has many major syntax changes from Python 2. Because of this, Python 3 is not always directly backwards-compatible with Python 2 (although a couple of edits could make it that way). Currently, Python 3 is at version 3.4. I will be using this version.
1-length code
1
Numbers above 0 and strings containing characters themselves count as True.
2-length code
''
This is the empty string. It counts as False.
3-length code
l=3
This assigns the variable l with the value 3.
4-length code
1+45
If you're running this in Python's interactive shell, you'll get 46. Why? Because in Python's shell, doing math will automatically print it. Don't believe me? Install and run Python 3 without a file, then type the snippet.
Length 5
l=[1]
This is a list with one item - 1. That's all you need to make a list - but there are some other ways.

\$\endgroup\$
  • \$\begingroup\$ But Python 2 IS forward compatible with Python 3. \$\endgroup\$ – mbomb007 Apr 6 '15 at 16:34
  • \$\begingroup\$ Nope. In Python 3 (at least 3.3), print has been changed from a statement to a function. That's the big one that affects all non-version-neutral code. The rest of the changes are found here. \$\endgroup\$ – ASCIIThenANSI Apr 6 '15 at 16:43
  • \$\begingroup\$ I already included the print statement/function in my showcase of Python. \$\endgroup\$ – mbomb007 Apr 6 '15 at 16:46
  • 1
    \$\begingroup\$ Also, there's from __future__ import print_function \$\endgroup\$ – mbomb007 Apr 6 '15 at 16:48
  • 1
    \$\begingroup\$ Probably, since there's already 2 Python showcases, not including this one. Feel free to suggest some Python 3 snippets to Sp3000, since his has fewer snippets. \$\endgroup\$ – mbomb007 Apr 6 '15 at 18:07
11
\$\begingroup\$

Treehugger

Treehugger is an interesting Brainf*** variant which operates on a downwards-infinite binary tree of byte values instead of on a rightwards-infinite tape. In addition to Brainf***'s 8 commands (two of which have been slightly redefined), it adds a ninth command, which will serve as my length 1 snippet.

A web interpreter can be found here.

Length 1 snippet: ^

The new command (although, in a literal Brainf***-to-Treehugger translation, it can be treated as equivalent to Brainf*** < instruction). Moves one position up the tree.

Length 2 snippet: <>

< moves one position down the current node's left branch, > moves one position down the current node's right branch. Thus, this will move the data pointer as shown here:

enter image description here

Length 3 snippet: +[]

An infinite loop, exactly like in Brainf***.

Length 5 snippet: ,[.,]

Another loaner from Brainf***: a cat program.

\$\endgroup\$
11
\$\begingroup\$

Snap!

Snap! is a language based off of Scratch. Scratch answer: here
Note: These are things specific to Snap.

Factoid

Snap!'s old name was BYOB, for Build Your Own Blocks. The creators were forced to change it because some teachers at Berkeley, where it was based, had no sense of humor.

Length 1 Snippet

unicode65asletter

Unicode support is available!

Length 2 Snippet

This one only works if you load the toolblocks (the smaller button on the page). IMO, you should always load the toolblocks.

b2r

You can convert blocks to reporters (things that contain numbers). This way, whenever a reporter would be needed, you can use a block!

Length 3 Snippet

Ternary operators and writing to the screen! This will print hi because an empty boolean slot is FALSE.

\$\endgroup\$
11
\$\begingroup\$

Octave

Note:

I got to say hello to a little earthling in the delivery room a few weeks back. Although she's lighter than a ball, she takes up quite a lot of my time. I'll redirect my focus to more important things (for instance showing of the awesomeness of Octave) when I have some spare time. Until then, please have some patience =)


Octave and MATLAB are very similar, and many of the nice features flawr has showcased would be good showcases for Octave as well. I will try to avoid reusing any of the material flawr has already used.

Snippet 1:

.

A full stop punctuation is a very versatile operator, and helps solve a lot of tasks very elegant:

Snippet 2:

++

Increment operators are one of the great features in Octave, that doesn't exist in MATLAB. It's known to most programmers as languages such as C++, Java, JavaScript, PHP and Perl all support it. Nevertheless, it's awesome when golfing, and often makes Octave submissions a bit more competitive than MATLAB. x++ is 2 bytes shorter than x=x+1.

Snippets 3:

Edit: 02.05.2016 - I'll get to this ASAP!

Snippet 4:

a+a'

This is a great way to create a grid of values, similar to meshgrid in MATLAB.

a = 0:3;
a+a'
ans =    
   0   1   2   3
   1   2   3   4
   2   3   4   5
   3   4   5   6

You can of course use this with vectors of different lengths. a+b' produces the same result as:

bsxfun(@plus,a,b')

Snippet 5:

a=b=1

In Octave, you assign a value to several variables at the same time. The MATLAB equivalent is 7 bytes: a=1;b=1

Snippet 6:

Edit: 02.05.2016: Octave is way better than MATLAB for golfing. More snippets = More possibilities to demonstrate. I'll get to this ASAP!

Factoid:

Octave is known to most as a free alternative to Mathwork's MATLAB. Octave was originally conceived (in about 1988) to be companion software for an undergraduate-level textbook on chemical reactor design1

The name has nothing to do with music, but is actually the name of one of the author's former professors who wrote a famous textbook on chemical reaction engineering, and who was also well known for his ability to do quick "back of the envelope" calculations.2.

\$\endgroup\$
11
\$\begingroup\$

TI-99/4 GPL byte codes

Factoid:

GPL stands for Graphics Programming Language. It is a byte-wise interpreted language that is found in GROMs in both the console and cartridges. GROMs are 6k ROMs with an internal 16-bit address counter. The upper three bits determine which GROM will respond. Most instructions can access CPU memory or video memory with ease. Which is important as the console only has 256 bytes of CPU RAM. It was introduced on the TI-99/4 in 1979 and also used on the TI-99/4A.

Note: All bytes and addresses are in hexadecimal.

Length 1:

03   ; SCAN

This will scan the keyboard and/or joysticks using the mode found in CPU byte 8374 and place the scan code in 8375. Joystick displacements may be placed in 8376 (x) and 8377 (y), depending on the mode.

Length 2:

07 20    ; ALL ' '

This will fill the first 768 (32x24) bytes of video memory with spaces. In the default video memory layout, this fills the entire screen with the given character. No provisions are made for different layouts or 40 column mode which uses 960 (40x24) bytes. The TMS9918A Video Display Processor (vdp) can place the screen on 1K boundaries and the character definitions on 2K boundaries. To maximize space for tokens and variables, BASIC places both of these overlapping at the beginning of the 16K video memory. This makes the first 96 character definitions unusable, so BASIC has a bias added to the ascii values on the screen. Provisions are made in several rom routines to accommodate this bias.

Length 3:

95 A1 23    ; DINCT V@0123

This adds 2 to video memory word 0123. A word on the TI is 2 bytes, msb first. Most instructions can operate on a byte or word, in video and/or CPU memory. For video memory addresses from 0F00 to 3FFF, the encoding takes one more byte. Address encoding can get quite involved, including indirection and indexing.

Length 4:

A0 A1 23 10    ; ADD @8310, V@0123

This adds CPU byte 8310 to video memory byte 0123. For CPU addresses 8300 to 837F, the encoding only takes 1 byte. Also, all CPU addresses have a bias of 8300 added to the encoded value. This is because the fast 256 bytes of CPU ram is at 83xx. For two operand instructions, like this, the destination is encoded first.

Length 5:

08       ; FMT
21 48 49 ; VTEX 'HI'
FB       ; FEND

This will draw the string 'HI' vertically at the current display location, stored in CPU byte 837E (row) and 837F (col). GPL has an alternate interpreter known as the format sub-interpreter. The first and last lines enter and exit the sub-interpreter, respectively. Most of the FMT commands use the lower 5 bits of the opcode as a count, 1 to 32, encoded as one less than the count.

Length 6:

30 10 A0 00 80 00    ; MOVE @8310, G@8000, V@0000

This will move the number of bytes in CPU word 8310 from GROM address 8000 to the beginning of video memory. Move is possibly the most powerful GPL command. It can use GROM address space as source or destination, in addition to using the usual address encoding. It can also use the read only video controller registers as a destination.

Length 7:

06 00 34 ; CALL BEEP
03       ; L1: SCAN
40 13    ; BR L1
0B       ; EXIT

Now we have a real program that beeps once, waits for a key, and then resets the console. TI defined several fixed entry points for GPL calls such as BEEP, which plays a 1397 Hz tone for 200 ms. SCAN was used in the length 1 snippet. It also returns the condition (cnd) bit set if a new key was detected. BR Branches to the label if the cnd bit is Reset. Individual GROMs are 6K bytes on 8K boundaries and the BR and BS (Branch if cnd is Set) instructions are limited to targets in the current GROM. Cartridges are given complete control over the console, so an EXIT resets back to the power on screen.

Length 8:

0F 17    ; COSX2: XML VPUSH
0F 0D    ; XML SMUL
06 00 2C ; CALL COS
00       ; RTN

This makes a subroutine that returns cos(x2). Where the input and output are the floating point value in CPU ram 834A. XML is eXecute Machine Language procedure. The second byte of the XML instruction defines the table (upper nibble) and index in that table (lower nibble) to get the address to execute. The first two tables (0x and 1x) are predefined in rom. VPUSH pushes the float at 834A onto the floating point stack in video memory. SMUL multiplies the float at 834A with the top of the floating point stack. COS calculates the cosine of the float at 834A (in radians). RTN returns back to the caller. The TI floating point format is 8 bytes with the first byte the exponent and the remaining 7 bytes are base 100 digits. This yields 14 decimal digits of precision. Not bad for 1979.

Length 9:

07 20                 ; ALL ' '
35 00 C0 A3 00 A2 FF  ; MOVE 192, V@02FF, V@0300

This is what is needed to clear the screen in 40 column mode as noted in the length 2 snippet. This assumes that the screen is at the beginning of the video memory. The move copies the last byte filled by ALL to the remainder of the screen. This trick to fill memory by setting the move destination one more than the source is used in the TI GROMs quite a bit. Here we see move with an immediate count showing how flexible this instruction can be. Also, note that the built-in BASIC cannot use 40 column mode because of the video memory layout mentioned in the length 2 snippet. Extended BASIC with the expansion ram can use all of the video memory for video.

Length 10:

0E C2     ; PARS >C2
83 4A     ; DNEG @834A
C6 4C 63  ; CH 99, @834C
76 71     ; BS 5671
10        ; CONT

This is an actual snippet from the built-in BASIC GROM called when an unary minus token is encountered. PARS and CONT are GPL commands that are only used by BASIC. PARS parses BASIC tokens until it reaches a token that is smaller than the value given. CONT continues the BASIC interpreter. The TI floating point format indicates a negative value by negating the first word. CPU address 834A is the current floating point value as mentioned in the length 8 snippet. CH sets the cnd bit if the destination is larger (unsigned comparison) than the source. BS jumps to GROM address 5671 to display an error message if the byte at CPU address 834C is greater than 99. This is the second base 100 digit of the floating point value. Since BASIC is written in GPL and GPL is also interpreted, the BASIC interpreter is painfully slow.

Length 11:

02 FF       ; RAND 255
BC B0 00 78 ; ST @8378, V*8300
91 00       ; DINC @8300
90 78       ; INC @8378
01          ; RTNC

This is a routine that places a random byte at video memory pointed to by CPU word 8300, increments the pointer, then returns the cnd bit set if the number was 255. RAND n puts a random number between 0 and n into CPU byte 8378. ST copies that byte to video memory. V*8300 indicates indirection into video memory, but all pointers can only be in CPU memory. DINC increments a word. INC increments a byte and sets the cnd bit if the result is zero. RTNC returns from the routine without clearing the cnd bit. Normally, calls, returns, and branches clear the cnd bit. This feature can be used to create a fixed entry point table using BR which is a byte smaller than B (unconditional branch). This was used by TI as mentioned in the length 7 snippet.

\$\endgroup\$
11
\$\begingroup\$

Your Mom

Factoid

Your Mom is a stack-based golfing language created because of a mbomb007's chat message on TNB:

I think someone should create a language called "Your Mom", just so that during an argument over which language is a better one, they can interject that "Your mom is a better language"

Source

Since Your Mom use Unicode, the length of the snippets are in characters, not bytes

Length 1

+

+ pop two values and return their sum. Since there is nothing on the stack, the two values are read from stdin.

Length 2

()

Define a empty function. ) is not needed since it's the end of the program.

Length 3

#II

# push a zero, I pop the last value, multiply it by 24 and add 18, because Your Mom use base 24. The state of the stack at the end is [ 450 ]

Length 4

¥()@

This snippet create a infinite loop.
¥ push 1 to the stack, () define a empty function and @ pop a function and call it while the element on the top of the stack is true (but don't pop it)

Length 5

çç#,.

This snippet create 2 array (ç), push 0 in the last array (,) and concatenate the two arrays (.)

Length 6

çÐ,€²Ç

This snippet create a array, push to it the user input (Ð), define a 1 character function that process the sqare of it's input (€²), and map it to the array.

Length 7

Ð(:_⊟)@

This snippet read the user input and print it, and decrement it while it's not 0

Length 8

##21®€²Ç

This snippet create a range from 0 to 20, create a one character function that square it's argument, and map on the range.

\$\endgroup\$
11
\$\begingroup\$

Ouroboros

Each line of an Ouroboros program represents a snake eating its own tail, with the beginning of the line being the head and the end being the tail. The only control flow operations are commands to eat or regurgitate characters of the tail. When the instruction pointer reaches the last part of the line that hasn't been eaten, it loops back to the beginning. To stop execution, simply swallow the instruction pointer.

Factoid

Ouroboros has a Stack Snippet interpreter.

Length 1

n

Outputs the top of the stack as a number. An empty stack is treated as if it contained infinite zeros, so this outputs 0. No characters are ever eaten, so the program loops (and prints) infinitely.

Length 2

1(

Pushes a 1 and then uses ( to eat that many characters from the end of the snake. This means eating the last character. However, since that's where the instruction pointer currently is, the snake dies and the program terminates.

The program would also terminate if the number were 2, or indeed any larger number; in that case the entire snake would be swallowed. (Physically impossible, but hey--this is a metaphor.)

Length 3

32n

Although Ouroboros processes one character per tick, it still supports multi-digit numbers in the expected way. This program will push and output 32 infinitely (rather than, for instance, pushing 3, pushing 2, and outputting only the 2).

One interesting side effect: a multi-digit number is recognized as such even when it bridges the end of the snake. The code 2n3 will first output 2, but thereafter will output 32 infinitely.

Length 4

rnao

r reads a positive integer from input, grabbing all contiguous digits until it finds a non-digit. n outputs as a number. a pushes 10, and o outputs this as a character (newline). Thus, an input of 1 2.3 -4abc55 will yield

1
2
3
4
55

However, because this snippet doesn't terminate the loop when the input is used up, the program will continue: r will start giving -1s to signal end-of-input, and n will keep outputting them indefinitely.

Length 5

n?2*(

Prints one or more 0s, with the exact count depending on random numbers.

n behaves as in snippet 1, outputting a 0 from the empty stack. ?2* generates a random floating-point number between 0 and 1 and doubles it. Then ( eats that many characters (rounded down). Thus, if ? generated a number >= 0.5, the program halts; if not, it loops, prints another 0, etc.

Length 6

"oooo(

" toggles between executing characters and treating them as a string. As in other 2D languages, you can define a string using only one quote mark because the instruction pointer wraps around. A key difference with Ouroboros, however, is that the string is pushed in reverse order, so that the first character is on the top of the stack. This means we don't need to write strings backwards or have a stack-reverse operator like ><> does.

The above code pushes "oooo(" and outputs the first four characters (the os). It then uses the last number remaining on the stack (40, the charcode of () as the argument to the ( command. Eating 40 characters definitely swallows the IP, and the program halts.

Length 7

r.*.n!(

Truth machine program.

r reads a number from input, or -1 for EOF. .* multiplies it by itself, keeping 0 and 1 the same but mapping -1 to 1. .n dups and outputs the number. Finally, !( logically negates and eats that many characters of the end of the snake. If the number was 0, this eats the ( and dies. If the number was 1, this eats zero characters, and execution loops back to the beginning of the snake, printing 1 indefinitely.

Length 8

i.0<2*(o

Cat program.

i reads a single character from input, pushing its charcode (or -1 on EOF). .0< duplicates and tests if the value was less than 0; i.e., pushes 1 on EOF and 0 otherwise. 2*( multiplies by 2 and swallows that many characters. On EOF, this eats (o and ends the program; otherwise, nothing is eaten, and o outputs the character from input. The snake then loops back to the beginning.

In writing this snippet, I realized that cat can actually be done in four characters: i.)o. Go read the explanation on that answer for some crazy abuse of undefined behavior.

(Length 9 snippet pending)

Length 10

.!+.@.nao+

Outputs the Fibonacci sequence, starting from 0 and continuing indefinitely.

First, we need to initialize the stack by pushing a 1. The trouble is that any initialization code at the head of a snake will run every time through (since it's at the head, we have no way of eating it). Therefore .!+ is designed to turn the top of the stack into a 1 iff it was previously 0 (which is the case when the stack is empty). .! dups and logically negates (1 if the value was 0, otherwise 0), and + adds that result to the top value.

(For a version that uses a second snake to perform the initialization, see the GitHub readme.)

Now the bulk of the program. Call the two numbers on the stack x and y, where x is smaller and y is on the top of the stack. .@.n copies y, rotates x to the top, and outputs a copy of it. ao outputs a newline (as in snippet 4), and + adds x to a copy of y. Now the stack contains y and x+y, and we proceed to the next iteration.

\$\endgroup\$
11
\$\begingroup\$

Oasis

Factoid

Oasis is a language made by Adnan specialized in number sequences.

You can try it online here.

Length 1

n

Not very interesting, just push n (The current argument) and print it because implicit output.

Length 2

n1

Same as the previous snippet, but give 1 for the argument 0.

Oasis programs can have a list of hardcoded definitions for special cases.

So n1 can be described in pseudocode as:

A(n) = n
A(0) = 1

Special cases and indexes are reversed, so to make

A(0) = 1
A(1) = 4

The correct special cases definition is 41

As @Adnan pointed it out, another interesting snippet is the fibonnaci sequence:

+T

Because T is replaced with 10, so this is expanded to

+10

Which mean

A(n) = A(n - 1) + A(n - 2)
A(0) = 0
A(1) = 1

Length 3

n*1

Finally, an useful snippet!

This calculate a factorial.

     A(n) = n * A(n - 1)
n    Push n
 *   Multiply two items on the stack
     Because there is only one item on the stack, A(n-1) is pushed
  1  A(0) = 1

Length 4

n*x1

Showcase the command x (Double a number).

This is basically a factorial, but double the number returned by n*A(n-1).

A(n) = n * A(n - 1) * 2
A(0) = 1

Length 5

Tnm>1

Calculate A000533

       A(n) = 10^n + 1
T      Push 10
 n     Push n
  m    Power
   >   Increment
    1  A(0) = 1

Length 6

Tnm<9÷

A002275 aka repunits

        A(n) = (10^n - 1) / 9
T       Push 10
 n      Push n
  m     Power
   <    Decrement
    9   Push 9
     ÷  Floor divide
\$\endgroup\$
  • \$\begingroup\$ Another interesting 2 byte submission is +T, which is the Fibonacci sequence :). \$\endgroup\$ – Adnan Nov 12 '16 at 18:46
  • \$\begingroup\$ You can also add a Length 6 snippet. \$\endgroup\$ – Erik the Outgolfer Nov 13 '16 at 10:45
11
\$\begingroup\$

Golfical

Golfical is a shiny, brand-new graphical programming language I made over the past few days, and published earlier today.

It uses a stack, a tape, and a register as memory. But primarily the tape.

The included encoder utility can be used to compress programs into a raw binary form, which can then be converted back to the original image or run directly by adding the -x flag. This requires from one to three bytes for each pixel, plus three bytes extra for encoding the dimensions (length and width are encoded as twelve bits each, just in case 8 isn't enough for some reason.)

Of course, the encoding is somewhat lossy, as all other colors that don't have instructions assigned to them are changed to white (both to save space and because the specs guarantee that no instruction will ever be assigned to white.)

One pixel example:

enter image description here

Magnified 200x, with color labels:

enter image description here

When the red channel is zero, Golfical interprets the green and blue channels as an integer literal and stores it in the target of the pointer. Thus, this stores the value 255*256+255=65535 into the target of the pointer. This is the largest number that can be stored directly in this way, though cells can be set in longer ways to values as large as 231-1.

In the binary encoding generated by the included Encoder utility, this would represented by three bytes; the encoding includes an optimization that allows only two bytes to be used for this instruction when the green channel is zero.

Two pixel example:

enter image description here

Magnified 160x with color labels:

enter image description here

(10,0,0) inputs a number and (10,1,1) outputs it as a character. In the compressed binary encoding, these two instructions add one byte each.

Three pixel example:

enter image description here

Magnified 160x, with color labels:

enter image description here

(10,0,1) is like (10,0,0), except it reads a character instead of a number. (12,0,0) pushes the target of the pointer to the stack. (The binary encoding represents these instructions as 1 byte each.)

Therefore, this snippet reads a character, pushes it to the stack, and then reads another character.

Four pixel example:

enter image description here

Magnified 125x, with color labels:

enter image description here

Simulates the rolling of a d100. The two new instructions here are 02xxxx (which works like 00xxxx but as an increment instead of an assignment) and 0D0001 (13,0,1) which sets the target of the pointer to a random integer between 0, inclusive, and its previous value, exclusive. Like 00xxxx, 02xxxx is represented in the encoding using two bytes if the green channel is zero or three otherwise. 0D0001 is represented as one byte.

Five pixel example:

It took me a while to decide what to do with this one, but eventually I decided to go with this:

enter image description here

Magnified 125x, with color labels:

enter image description here

(11,0,0) through (11,0,3) are absolute turn instructions (relative turn instructions, as well as many of the conditional relative turns, are later in the 11 block). (11,0,1) is East and (11,0,3) is West.

This program prints lolololololololololololololololololo ad infininum.

Six Pixel Example

enter image description here

Magnified 200x, with color labels:

enter image description here

An infinite counter (limited, of course, by the 32-bit two's complement integer range; a proper infinite counter would be much harder to implement.) Also our first properly 2-dimensional example here.

Eight pixel example:

Magnified 100x with color labels:

A primality tester using the language's prime testing builtin (14,3,0), which makes a relative right turn if and only if the target of the pointer is prime. The official encoder program encodes this program in 13 bytes.

\$\endgroup\$
  • 1
    \$\begingroup\$ Example one, please? \$\endgroup\$ – Conor O'Brien Dec 14 '15 at 19:21
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Here you go. \$\endgroup\$ – SuperJedi224 Dec 14 '15 at 20:43
11
\$\begingroup\$

Batch

Factoid

Batch uses commands that the Windows command line uses. A bunch of these were inherited from the (ancient) MS-DOS.

Length 1

:

This creates an empty label. In Batch, empty labels are perfectly legal, even if they don't do anything.

Length 2

at

This command schedules commands and programs to be run at a specified time. The batch file must be granted elevated administrator privileges for this to work.

Length 3

rem

A command that discards parameters supplied after it. This essentially comments out text.

Length 4

echo

With four characters, we can finally print text! This will print out whatever comes after it.

Length 5

start

As one of the most simple commands, this just opens up a separate command-prompt window. Nothing too complicated about this at all.

Length 6

chkdsk

This command also requires elevated administrator privileges. This command is short for "check disk". It does what it says; it checks a disk and provides a status report.

Length 7

replace

This command is used to replace one file with another. The file names are passed as parameters to the command.

Length 8

shutdown

This command can shutdown your computer. It has a variety of parameters, and like setting shutdown time, a shutdown comment, or aborting the shutdown.

\$\endgroup\$
  • \$\begingroup\$ Length 9: BITSADMIN... \$\endgroup\$ – stevefestl Jun 24 '17 at 1:04
11
\$\begingroup\$

ForceLang

ForceLang (name proposed by TanMath) is a programming language I published on January 12.

Functionality includes arbitrary-precision rational numbers, both console and GUI IO, and file input (file output has not yet been added, but will likely be added later)

Control flow is currently handled using gotoes, evaluated gotoes, and conditionals.

Length 1 snippet: 0

A number literal for the rational number 0/1.

Length 2 snippet: io

The io namespace contains the language's console and file IO functionality. GUI IO is located in a separate namespace.

Length 3 snippet: nil

A constant field containing the null reference.

Length 4 snippet: 0xFF

A hexadecimal number literal for the rational number 255/1 (hexadecimal literals can only be used for integers).

Hex literals are useful as color codes for the language's (currently somewhat limited) graphics library.

Length 5 snippet: 11/13

A number literal for the rational number 11/13, which is stored exactly as a BigRational.

Length 6 snippet: !!TRUE

Obviously, this returns TRUE.

Length 7 snippet: def a a

An abuse of the def instruction that causes any successive attempts to evaluate the expression a to result in an infinite loop.

Length 8 snippet: gui.show

A method that produces a simple gui alert.

Length 9 snippet: math.sqrt

Estimates the square root of a number as another BigRational. It does this by doing some math to find a BigInteger which approximates this value, then applying four iterations of the Babylonian Method.

Length 11 snippet: random.rand

The function random.rand can be used to produce random numbers on [0, (2^m-1)/(2^m)] for arbitrary positive integer values of m (effectively on [0,1) as m becomes large). When called with no arguments (random.rand()) it uses m=80.


Some other answers in this language:

\$\endgroup\$
  • \$\begingroup\$ We need two more snippets :) \$\endgroup\$ – Nic Hartley May 5 '16 at 17:20
10
\$\begingroup\$

KSFTgolf

I've finally finished at least a very early version of an interpreter for my golfing language KSFTgolf. It probably doesn't work very well, but I'm hoping to make it better by adding instructions that would help to solve problems here. I'll probably be updating it several times while this is posted. I'll try not to break the examples I've already posted. The interpreter is here:

https://github.com/KSFTmh/KSFTgolf

I'm pretty sure there's something wrong with nested loops in the current version of the interpreter. I'll try to fix it, but for now, some of these might not work.

Length 4

r2eu

This takes a list of numbers as input and prints the sum of the squares of those numbers. Single-digit numerical literals like 2 push their value, e is the exponentiation function, and u pops a list and pushes the sum of its elements.

Length 3

trm

This prints all of the primes up to 1000. t pushes 1000, and r is like a for loop.

Length 2

on

This takes a character as input* and prints the ASCII value of it in binary. o calls Python's ord() function on the top element of the stack, and n converts the top element of the stack to binary.

Length 1

m

This takes a number as input and prints 1 if the number is prime and 0 otherwise. Input is pushed onto the stack at the beginning of the program and the entire stack is printed at the end.

*It uses Python 2's input() function, so string inputs have to be in quotes.

Factoid

Objects in KSFTgolf don't have types. They're converted whenever they're used.

\$\endgroup\$
  • \$\begingroup\$ I don't know if this is a valid language, but I'm curious about it. \$\endgroup\$ – Ismael Miguel Jan 23 '15 at 15:45
  • \$\begingroup\$ @IsmaelMiguel What do you mean by "valid"? \$\endgroup\$ – KSFT Jan 23 '15 at 15:49
  • \$\begingroup\$ Well, there is no documentation. There is only your implementation in python. That is what I meant. But still, I'm curious about it! (Btw, I'm trying to write my own language too (I just get too lazy to write any code). Not a 100% golfing one but can be easily addapted.) \$\endgroup\$ – Ismael Miguel Jan 23 '15 at 15:55
  • \$\begingroup\$ It will. Also, the documentation will help you to keep track of your progress and goals with the language. A basic documentation might take 2-3 hours to write. But it will be worth it! \$\endgroup\$ – Ismael Miguel Jan 23 '15 at 16:00
  • \$\begingroup\$ You can write a sloppy documentation, which will take considerably less. But it will look terrible. It's always better to write a good documentation. It shows professionalism and enthusiasm! But yeah, it can take that time. Try it and you'll see I'm right. \$\endgroup\$ – Ismael Miguel Jan 23 '15 at 16:23
10
\$\begingroup\$

Rebol 2

Note: There is already an answer for Rebol, but it is specific to Rebol 3, which has some significant differences. I wanted to highlight some of the features that are unique to Rebol 2 as these deserve a mention.

Factoid: Rebol stands for "Relative Expression Based Object Language". It is a homoiconic language (that is, code and data are expressed the same way).

1

?

This brings up the built-in help in the command-line interpreter. It is a mezzanine function.

2

[]

Evaluates to an empty block (type block!) which groups together values and functions and is a container for data until it is evaluated, in which case it is treated as code. Elements of blocks, even nested blocks, can be accessed via a path.

3

pwd

Evaluates to a value of type file! that is the current working directory, just like in the shell! Rebol provides some familiar shell commands, like cd, ls pwd and rm as mezzanine functions which behave like they would in the shell, so you can navigate around, and work with the file-system and forget that you are actually in the Rebol interpreter!

4

12x3

Pairs. They are everywhere, right? In spatial co-ordinates, screen dimensions, on the park bench. pair! is another built-in type that consists of two integers separated by an x, just like you write it and would like to read it. But there's more: You can slice them, dice them, add and subtract them, get at their values with /x and /y (/ being the refinement modifier that allows you to access things like values in objects or entries in arrays using a very natural, path-like syntax).

5

2 + 2

The + here is in fact an operator function, or infix function, taking two arguments: one on the left and one on the right. Typing ? op! at the Rebol console will give us a list of all these operators (type op!) which includes the usual suspects, like != and <> (both meaning not equal), ** (power-raiser) and xor (exclusive XOR) among others.

\$\endgroup\$
10
\$\begingroup\$

ChucK

Factoid

ChucK is a time-based programming language that handles sound synthesis. It has most standard functions, as well as multiple sound generators and ways to modify waveforms.

Length 2 snippet

=>

This is the ChucK symbol. It requires a "chucker" to the right of the symbol and a "chuckee" to the left. What it does depends on the syntax: If it's given an integer as the chucker and a initialized integer variable as the chuckee, it will store the integer in the variable. If it's given a sound unit as the chucker and a modifier/output as the chuckee, it will send the sound through the modifier/output.

Length 3 snippet

dur

When initializing a variable, you can make the variable type a duration by using this command. In doing so, durations in time can be stored in the variable (useful for allowing sounds to end before moving on in code).

Length 5 snippet

5::ms

This is another snippet to do with time. ms means milliseconds, and the 5 is literal. This is the format for a duration in ChucK, and can be assigned to a dur variable.

\$\endgroup\$
10
\$\begingroup\$

Joe

Factoid

Joe is a language I've been working on for some time. It was designed to make list mappings and interactions with functions and other lists implicit and powerful.

Length 1

In Joe, the result of the last expression of every line that isn't a function, is printed. Thus, the following program prints 1 and exits. Note: the code is indented by 3, output by 0.

   1
1

Length 2

Functions can take one or two arguments. If called with one argument, the argument appears on the right side of the function. Monadic R gives range from 0 to y, excluding.

   R5
0 1 2 3 4

Length 3

If a function is called with two arguments, they surround the function. Here we call R with arguments 2 and 7. Dyadic R gives range from x to y, inclusive.

   2R7
2 3 4 5 6 7
   7R2
7 6 5 4 3 2

Length 4

Joe does have higher-order functions, but they cannot be defined by the user. Not that you would want to.

:/>c

Here, >c ("greater choose") is a function that returns the greater one of it's parameters (1>c4 returns 4). / takes it and returns a function that applies the >c between the items of it's arguments (think of rfold1). So, />c is a max function! : then saves it to name F. Let's test this out.

   F1 2 3
3
   F1 3 2
3

Length 5

Joe has some handy ways to control data flow. Let's see one of them.

   O$rMH"Shelly""Leo""Mike"
Leo
Mike
Shelly

   O$rME"Shelly""Leo""Mike"
Mike
Leo
Shelly

Here you see two versions of a simple sorting function O$rM<rule>. The rule can basically be replaced by any function you want to. I'll use the H-rule (head) in the following explanation, which shows the steps taken to achieve this result.

To get the first letters from the strings for the sorting, we map head to them.

   MH"Shelly""Leo""Mike"
SLM

We then want to pass this as the left parameter to the sorting function O and the original list as the right parameter. We can do this using tacit composition (you can find more on the matter in Joe's quick reference).

   {MHOA)"Shelly""Leo""Mike"
Leo
Mike
Shelly

Because this is so common pattern, I've created a shorthand $r for it. O$rMH is equal to {MHOA).

Length 6

Function composition is vital in Joe. It is the only way to create any kind of data flow. See, for example, a factorial function.

/*-l1R

How does it work? The arguments are always passed to the rightmost function, from where they're cascaded back in the chain. 1R gives a list from 1 to the argument (inclusive). -l removes all zeroes ("minus list"). This allows the function to work correctly when passed a zero. Lastly, /* multiplies all values together to create the result. Now, at this point the implicit looping capabilities of Joe start to pop in. Observe.

   F:/*-l1R
   F5
120
   FR10
1 1 2 6 24 120 720 5040 40320 362880

Note: the function definition could be inlined and left unassigned.

Edit: Joe received backwards uncompatible update. All examples updated.

\$\endgroup\$
10
\$\begingroup\$

Axe Parser (Ti-83/84)

Axe is an extremely low level and loose syntax third party programming language for the ti83/84+ (z80) graphing calculators. Albeit its name, programs are compiled into z80 and not interpreted. Programs are usually written in the default ti-basic editor, so code is messured in tokens. Someting like "L6" or "End" take up only one byte, despite being more then one characters long.

Site, Doc/tutorial (outdated), and commands list for my convince. I've not used the language since I got a laptop and learned Java. I'm not big into axe so please leave a comment for something cool or edit the answer if I've not touched it in a while.

Factoid If your source isn't 'archived' or backed up, a crash will delete it along with the rest of the ram such as all your basic programs you actually use for class.

Length 1:

.

A comment. Placed on the first line of a program file it will cause an error in ti-basic. To the Axe compiler (a calculator 'application') and Axe aware shells, it means that the program (the only kind of file you can edit on the calculator) is an Axe source file. Characters that follow the . until a space are the name of the compiled program or application. After the space comes an optional description of the program that some shells will show. In the basic editor, the text of some basic tokens will now be changed to Axe commands if the 'help' option was enabled in the compiler application.

Length 2:

L6

A single token and Pointer to a 768 bytes block of memory that is "highly volatile". Drawing to the buffer will corrupt it. An experienced user will be able to use the L6 token to draw directly to the buffer, bypassing the drawing commands. It is NOT the ti-basic data token and has no relation to a basic list. When the programs ends it won't even be accessible like with basic variables. L1-5 also point to special free spaces of different sizes that are much more usable. Feel free to fill them up.

Length 3:

End

Ends a block of code. Unlike in Basic, every If needs an End because Then is not used.

Length 4:

→A→B

Store multiple values at once. Ans is implied. Could be 0→A→B. This is actually optimized compared to 0→A:0→B. 0→A+2→B also works and is optimized when 1 or 2 is added. The documentation provides many optimizations. In my experience they don't matter but I never pushed the calculator too much. I'm sure people have met the limits of the z80 though.

Length 5:

Lbl F

Defines label F. Labels are jumped to by goto and sub(. When the label is not a number, F() works like sub(F).

Length 6

Return

"Returns from a subroutine. If not in a subroutine, the program will end." If a subroutine calls another subroutine on its tail, it does not need a return (though you may still want it for readability).

Length 7

Returnʳ

"Emergency exits the program from within any number of nested calls." The r is used to modify a lot of functions.

\$\endgroup\$
  • \$\begingroup\$ Is this the tokenized TI-basic, or another language? \$\endgroup\$ – jimmy23013 Feb 21 '15 at 15:22
  • \$\begingroup\$ @user23013, sorry I was a bit unclear. Axe is its own language that can use the tibasic editor. Basic tokens are redefined and the text of some are even changed \$\endgroup\$ – Old Badman Grey Feb 21 '15 at 22:27
10
\$\begingroup\$

EGSHEL (the Extensible Golfing Scripting High Efficiency Language) v0.1

Currently in development, EGSHEL is a highly extensible turing-complete object-oriented stack-aware scripting language intended mostly for golfing but which, especially due to a Pythonic module-importing structure, is designed to be useful in other ways, as a general purpose language. It's influenced by Pyth, LOLCODE, GolfScript, Python, BrainFuck, and more.
Incidentally, its error-allowing parser and ignorance of unused or explicitly undefined characters make it very useful for polyglots with other, "real" languages like C, Python and Javascript.

Factoid: LOLScript EGSHEL has two basic parser modes: Concise, which binds builtins to lowercase letters and makes everything tiny, and Verbose, the default, which can can parse Concise code but, as the name suggests, is less tiny and more readable. The name EGSHEL is both a backronym and intended to convey that due to implicit, inferential types and other such features.

Originally designated LOLGolf LOLScript, it's clear from where LOLScript gets its name (which will probably change soon): LOLCODE. I was trying to make a meaningful program for Mystery String Printer in less than 128 bytes but LC has more than that in boilerplate just to make a loop.
(In practice, however, LS does not look or work at all remotely like LC. The first spec isn't even done but all we've copied from LC into LS so far is "vsb" to print strings (from LC's VISIBLE builtin.))


1 Char:

;

A semicolon is not so interesting but extremely useful. It can turn lines that would otherwise need to end in a newline, into a continuous line, and when found after a statement within either the first or last 3 lines of the file, sets some interesting mode-related options.
On its own line, though, it denotes the respective beginning or end of a readable file and if only one is found near either the top or bottom of the file, it gives execute precedence to that "side" of the file.
Execute precedence is something more easily explained with more chars but basically, it sets the initial reading direction: up or down the file.
In Concise mode, since Concise programs are almost always one line, an otherwise unecessary leading or trailing semicolon denotes the left/right reading direction on a per-character basis. But, I need more votes to explain further.

2 Chars:

-|

A hyphen directly followed by a vertical bar is, at least for now, a single line comment initiator in Verbose mode.
In Concise mode, unless the Concise code is embedded within a Verbose function or block, there are no comments and this denotes something nothing, yet.

If a -| is found more two or more spaces after a valid grouping of characters on a line in a Concise block in an otherwise Verbose script, it is a single line comment.

3 Chars:

1~B

Finally something unique! Take a guess as to what this does... If you guessed that it results in the second last (zero-indexed) history index of B, then you would be right!
History indicies allow direct access to a given variable's given 0 (represented by a solo tilde preceding a var) - Fh-th previous value.
What, you may ask, is the point? Well, as an example, when you use a similar statement ~1B, the result is the two (0 & 1) previous variables and B's current value concatenated based on their types. EGSHEL is dynamically typed and object-oriented thus it's up to the programmer to explicitly cast otherwise implicit types when needed. ~*B results in all previous values of B concatenated, incidentally.

4 Chars

#0(y

Calls the first defined anonymous function in a file with y as an argument. functions are defined like $foo(args{body} but if you leave out the function name foo, it becomes anonymous, is put into a numbered list, and you must call it as above. normal functions are called with their name as expected: foo(args.

5 Chars:

{:x:y}

Simple for loop, for i (that's i for Implied Imaginary) in x do y. More colons can expand this into a first, second, third C-style loop.

\$\endgroup\$
  • \$\begingroup\$ Note that when I say this language is "currently in development," I mean I just started writing the spec for v0.1 yesterday and I'm less than a quarter done. I wonder how long it will be before we've got an interpreter or I can use LS on PPCG... \$\endgroup\$ – cat Oct 17 '15 at 16:43
  • \$\begingroup\$ I really want to write a program in this now. :( Too bad there's no interpreter \$\endgroup\$ – ev3commander Dec 19 '15 at 23:17
  • \$\begingroup\$ @ev3commander oh, dear... I had abandoned this project... if you're interested (in helping?), I'll finish the spec and prototype something (because I currently have no idea how to write an interpreter, and I'm also working on mouse15) \$\endgroup\$ – cat Dec 19 '15 at 23:32
  • \$\begingroup\$ @ev3commander the syntax in its current form is gonna be a pain to parse, so I need to work on that. \$\endgroup\$ – cat Dec 19 '15 at 23:34
10
\$\begingroup\$

Beam

Factoid

Beam is a 2-dimensional language designed in 2010 by an Esolangs Wiki user named Feuermonster, and was originally implemented in 2012. It was re-discovered by me while looking for an interesting language with which to answer the famous "Hello, World!" catalog. The official interpreter has been lost, but PPCG user MickyT has developed a Stack Snippet interpreter.

Beam is based off of three storage values:

  • the beam, the primary storage; holds one unsigned 8-bit integer.
  • the store, the secondary storage; holds one unsigned 32-bit integer.
  • the memory, a (theoretically) infinite tape of unsigned 8-bit integers.

Length 1 snippet

H

Yay, our first full program! Unfortunately, we can hardly do anything in just 1 byte. H simply halts execution of the program, so from this, we get no output at all.

Length 2 snippet

:H

Now we get a chance to see some output. : prints the value of the beam as a number, so this program outputs 0. If we were to drop the H, it would still print 0, but it would also give us the error message Beam is lost in space. This error occurs anytime the beam travels beyond the bounds of the program.

Length 3 snippet

r@H

First lessons in inputting: r sets the beam to the char code of the next character in STDIN. @ is like :, except that it outputs as a character instead of a number. All in all, this program outputs the next character from the input. Not that useful, but pretty decent for 3 bytes. ;)

Length 4 snippet

++:H

Here we have the new character +. Can you guess what it does? (Hint: this program outputs the number 2.)

Length 5 snippet

v
\:H

Finally, a chance to use Beam's 2D instruction plane! Beam has four arrows ^v<>, which set the direction of the beam, and four mirrors \/|_, which reflect the beam in another direction. It also has several conditional direction changers, which we'll get into in a little bit.

Length 6 snippet

)n+!
 H

Here we demonstrate a few of the conditional statements. ) and ( change direction to left or right if the store <> 0. ! and ? reverse the flow direction depending of the value of the beam. n and u change the flow direction to up or down if the beam != the store.
So in the snippet above, ) does not change the direction since the store is 0, the flow continues through n as the beam and store are both 0. + increments the beam. ! reverses the flow since the beam is now 1. + the beam again. n now changes the flow direction down since the beam is 2 while the store is still 0. Halt the program.

Length 7 snippet

+P+:p:H

Bit of a boring snippet, but it demonstrates the setting and retrieving of memory values. P will set the memory at store position to the beam value. p will set the beam to the value at the stores memory position. In this example the beam is incremented to one. Memory location 0(store) is set to 1(beam). The beam is incremented and the value printed. Memory location 0 is retrieved into the beam and printed. The output is 21

More to come as this answer recieves more votes!

\$\endgroup\$
  • \$\begingroup\$ :D awesome. Yeah, I cleaned-up my vServer a while ago and most of the eso stuff got lost :(. Thanks for keeping it alive. \$\endgroup\$ – mroman Oct 23 '15 at 16:35
  • \$\begingroup\$ @mroman Thanks for a fun little language to play with. I hope the snippet does what it should. \$\endgroup\$ – MickyT Oct 24 '15 at 1:36
  • \$\begingroup\$ I wrote an interpreter in python for it today: gist.github.com/FMNSSun/3cc9c08e69a98eb0ae01 I hope I didn't make any mistakes. \$\endgroup\$ – mroman Oct 24 '15 at 13:16
10
\$\begingroup\$

TeaScript

Length 6 Snippet

r×ߥl©

This looks like gibberish so here's the ungolfed version: r(x)m(#$P(l)).

This returns a list of first n numbers and if they are prime. An output for the input 5 would be: false,false,true,true,false

Length 4 Snippet

£lc)

Now we're getting somewhere. This loops through each character of the input and replaces the character with it's character code.

Length 3 Snippet

¥x)

Checks if the input is prime. Returns true or false respectively.

Length 2 Snippet

xv

x is the input, v is a function which will reverse x. This essentially reverses the input.

Length 1 Snippet

M

The M character is preset to return a random number


Try any of these online

Factoid:

TeaScript was born after I got fed up with JavaScript's incredibly long String.fromCharCode function. It was originally made to have just shortened property names but TeaScript has grown quickly.

\$\endgroup\$
10
\$\begingroup\$

Mouse-2002


Length 6

&GMSUN

Pushes on the stack 1.32712438E+20 (in scientific notation!), or the gravitational mass of the sun.2

Length 5

&SWAP

Swaps the top two things on the stack. Concisely, ( x y -- y x ). Again, not that interesting; most mouse programs have to be somewhat longer to be interesting.

Length 4

&DUP

Duplicates the thing on the top of the stack. That is, makes a copy, and pushes that copy. Unfortunately expensive in terms of bytes. I think it was not the first thing on Simpson's list of easy-to-access functions.

Not particularly interesting.

If you've ever seen or written False (or, for that matter, False!) or, indeed, Forth, you'll notice a lot of Mouse is shockingly similar. I love Forth, and my guess is False's creator had perhaps heard of Mouse (because Mouse far predates False, but is predated by Forth by 9 years).

Length 3

&AU

Pushes "the value of one astronomical unit of distance"1 to the stack. The guy who reimplemented and updated this language had a hand on programming spaceships at NASA for the Apollo missions, so it figures he'd include a whole bunch of physics and maths related constants.

My reboot of the language will also contain these constants, because they're cool.

Length 2

A:

Takes the thing on the top of the stack and puts it in A. e.g, 1A: puts 1 into A, and 3 5/A: puts 3/5 into A. (oh yeah, Mouse uses Reverse-Polish-Notation!)

Length 1

?

Prompts for a number to be input, and puts it on the stack.

Factoid:

Mouse-2002 is an updated reimplementation of Mouse-83 by David Simpson. Mouse-83 was described in the book Mouse: A Language for Microcomputers by Peter Grogono. It includes a number of enhancements over the earlier version, Mouse-79, which was described in an article by Grogono in Byte magazine in July 1979.

Mouse is a rather ancient, yet turing-complete stack based language, which, while no instruction uses more than a byte, is still likely less golfy than CJam or Pyth.

Fixed interpreter here.

I'm planning to update it and reboot it with even more concise syntax and better features; no interpreter yet, though. It will be almost as golfy as CJam (though that isn't the main intent) while being far more readable and usable outside codegolf.

\$\endgroup\$
10
\$\begingroup\$

LabVIEW

LabVIEW is a graphical programming language mainly used for measurement technology.

Factoid:

LabVIEW used to store Bools in 2 Bytes

Note: since LabVIEW is strictly graphical the sizes are in Labview Primitives

Lenght 1 Snippet

LabVIEW is used in 2 windows, the left one (Block Diagramm) where the programming happens and the right one (Front Panel) for in and output. Putting a control on the Block Diagramm automatically puts the input on the Front Panel

Lenght 2 Snippet

there is actually no working programm of size 2 apart from just putting 2 controls or constants, so ill add another fact.

LabVIEW works exceptionally well with Arrays. They can be automatically indexed when put into a for loop and you can easily use basic arithmetic and binary operations on arrays and numerics of different dimensions.

Lenght 3 Snippet

I just realized i could use express VIs but that feels like cheating. They are basically full written out programms that get compressed into 1 VI. I might put one in if anyone wants to see it, so leave a comment.

Lenght 5 Snippet

This is one of the array operations one can do.

Lenght 6 Snippet

Another fact:

The size of a full LabVIEW installation can be well over 20 GB.

\$\endgroup\$
10
\$\begingroup\$

PoGo

Factoid

PoGo is an esoteric programming language that consists only of two letter commands with one vowel and one consonant each, designed to make the source code read funny. It operates on a two dimensional memory grid and three different stacks.

2 Characters

qi

Output:

poqigo

qi is one of the special purpose output commands, just for fun (others include wo wich outputs "Hello, world!"). What's special about poqigo? Wait for the 6 characters program!

4 Characers

isis

Output (example):

What is my purpose?
What is my purpose?

is is another special purpose output command, specified as "have an existentialist crisis". The message is choosen randomly, but at least in the official implementation it is memoized so that calling is twice gives the same output twice.

6 Characters

poqigo

Output:

poqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigopoqigo[...]

In the documentation, poqigo is mentioned as an example for a quine and obviously that's the only purpose of the qi command, but it actually isn't a real quine since it outputs itself infinitely, not just once.

With this example we learn the basics of flow control in PoGo. You use a call stack (the "po" stack):

  • po - add current position in code to the top of the po stack
  • go - pop the most recent po location off the stack and jump there

So po ... go produces a loop and if you don't use any conditions to break out of it, it's an endless loop

\$\endgroup\$
  • \$\begingroup\$ Six votes. What on earth is poqigo? :) \$\endgroup\$ – Conor O'Brien Feb 21 '16 at 17:57
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ There you go :) \$\endgroup\$ – Fabian Schmengler Feb 21 '16 at 21:37
10
\$\begingroup\$

Math++

The latest addition to my arsenal of custom languages. Also the first to include a mathematical expression parser. Operates exclusively on 64-bit IEEE754 floats.

Control flow consists exclusively of evaluated gotoes.

Length 1 snippet: ?

A special expression that returns a number taken from the input.

Length 2 snippet: !0

Returns NOT 0, which obviously equals 1.

(If you call the ! operator on any value other than 0, it returns 0)

Length 3 snippet: 0>$

This is the first snippet here to show the > symbol, which, in this language, is not a greater than operator but rather a symbol to separate an expression from its (optional) target designator. (The target designator out, meaning that the result should be printed to the output, is the default.) In this case, the target designator $ indicates that the result should be floored and then stored to the instruction pointer (thereby going to that number line.) Going to line 0 is considered an exit statement, going to any other out-of-bounds line number triggers an exception.

Length 4 snippet: _a>a

Floors the value stored in a, then stores the result back to a.

Length 5 snippet: 1>{0}

Associates the value 1 to the key 0 in the map.

Length 6 snippet: cbrt$e

An expression that yields enter image description here

($e is Euler's constant, just plain e is a variable; the language also supports pi ($pi) and the golden ratio ($phi))

Length 7 snippet: 9*$rand

$rand returns a random floating-point value greater than or equal to 0 but less then 1. Therefore, this expression returns a random floating-point value greater than or equal to 0 but less then 9.

Length 8 snippet: sin$pi|1

We've got logical operators, too!

This should return 1, but because of a rounding error in the evaluation of sin$pi, it yields 1.2246467991473532E-16. Darn you, IEEE.

\$\endgroup\$
10
\$\begingroup\$

Clip

Factoid

The empty program in Clip copies its input to the output (i.e. the cat program). This is because an incomplete expression takes the missing part as a string from stdin. Here, the whole thing is missing, so that is used. Each program just prints the result of an expression, here a simple string.

Length 1 snippet

A

I've seen obsolete features, but this... A is a supplier which returns the alphabet in upper case. This therefore outputs it.

Length 2 snippet

1A

If you have more than one expression at the root, only the first is evaluated and printed. Therefore, this program prints 1.

Length 3 snippet

\{`

Lists use the syntax {elem1elem2..elemn<backtick> (can't actually put a backtick there for formatting issues). There is no separator, as Clip can figure out how many expressions there are. The reason for this weird syntax is that { initialises a ListBuilder, which consumes all expressions it receives and shoves them on its list. Backticks escape things, for example +<backtick> is the plus function in a format that can pass it to other functions. However, ListBuilders happen to become a list when escaped, so that's what happens.

Finally, the \ function converts a list to a human-readable string i.e. {1 2 3 4 5<backtick> becomes {1, 2, 3, 4, 5} instead of the default 12345. The output of my length 3 snippet is not {}, however, as the default formatting for empty lists is as strings (lists of numbers with ischar: true). It is therefore "".

Length 4 snippet

bW42

W is a supplier that always returns 2 (this allows for no spaces between 2 and 42 here; just 242 would be interpreted as the number 242). bxy supposedly converts y to base x and returns a list of digits. So, what should this snippet return? 101010, for 42 in base 2. But it actually returns 21010. I don't know why, but that is not base 2. If you replace the 2 with 10, however, this function will always give the right answer (because in base x, 10 = x).

Edit: Turns out this was a bug in the v2 interpreter I was using; v5 seems to handle it correctly and print 101010.

Length 5 snippet

"..."

You expect this to print ... (though the second quote would be unneeded), but . is Clip's escape character - like most languages' \. If you imagine this as "\\\", it becomes clearer that the first escape escapes the second to make a literal ., and the last escape escapes the second quote to make it literally ". There is no closing quote, as these are unneeded, so this snippet prints .".

\$\endgroup\$
10
\$\begingroup\$

MIPS

Factoid: Though many see MIPS's heyday is in the past with ARM taking over the market, the classic RISC design often taught in universities continues to be widely used in embedded devices and newer small devices in Asian markets.

Length 1

Being assembly, not much can be done in one instruction. That being said, MIPS does offer an interesting native (not psuedo-) instruction: BGEZAL, Branch on greater than or equal to zero and link.

Hex code      Syntax
0x05110000    bgezal $t0, label
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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