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

226 Answers 226

7
\$\begingroup\$

haxe

Haxe is a neat language that lets you target a lot of major platforms with the same codebase - desktop, mobile, web, server, anything.

Finding good examples for the first couple of votes will be hard, so bear with me :)

1

.

Dot is the operator to access class fields and methods, object properties, or enum properties.

2

[]

This is an empty array. More on arrays (array comprehension) later.

3

3*9

Multiplication. The compiler is smart enough to change that into 27 in the resulting code, even in less strict languages (e.g. JS).

5

0...9

This is a shortcut to create an IntIterator, which will produce the numbers 0 to 8 (inclusive).

for (i in 42...45) Sys.println(i);

Produces

42
43
44
\$\endgroup\$
7
\$\begingroup\$

Cookie

Cookie is still in development, so these may not work!

Factoid: Cookie's name is inspired by @Dennis Jelly, and I wanted to keep with the sweet food thing. However, I forgot browser cookies, and you will be unable to find it on Github easily.

Cookie is stack oriented, and uses Javascript - specifically Node.js

1 byte snippet:

p

Checks if the number is prime, and outputs true or false.

I was really tempted to also add these two snippets:

c

and

C

Both do similar things. s converts a character to a ASCII number, while S does the reverse.

2 byte snippet:

))

Yup, it's a double increment. ) increments the stack value by one.

3 byte snippet

wJ"

Not much here. w starts a write and " closes it, so J is written.

A polite request, please don't ask me why I chose J. :P

\$\endgroup\$
  • \$\begingroup\$ An unbalanced parenthesis will stay with you all day... \$\endgroup\$ – Conor O'Brien Apr 6 '16 at 18:08
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ I have a lot of that in Cookie. :P \$\endgroup\$ – user51533 Apr 6 '16 at 18:58
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
    \$\begingroup\$ I can't wait for the 2 byte snippet! \$\endgroup\$ – CalculatorFeline Apr 25 '16 at 16:59
7
\$\begingroup\$

WireMod Expression 2

Length 1

#

This a comment in E2.

Length 2

?:

E2 supports a the ternary operator. Really useful.

Length 5

#[ ]#

E2's multiline comments are formatted as such

Factoid

Expression 2 is a programming language inside Lua, inside a game.
(Page takes a while to load)

\$\endgroup\$
  • 2
    \$\begingroup\$ (belated) Welcome to PPCG! \$\endgroup\$ – Cyoce Apr 5 '16 at 20:40
7
\$\begingroup\$

Racket

We have Clojure (the Java among LISPs), and Common Lisp (C), but where are Scheme (x86 asm) and more most importantly Racket (Python)?? :o

Racket is like the Python of LISPs. Common Lisp seems old (it's older than FORTRAN!), and Scheme seems boring, academic, and comes with a too-sparse standard library.

On the other hand, Racket is a batteries-included, industry-ready Scheme, that's fun to learn and use every day.

Factoid

In most other LISPs, () is the empty list. However, Racket's syntax is minorly deviant in that '() is the empty list and () is an illegal empty application (that is, the application of nothing to nothing, which makes no sense).

Length 1

λ

Other people have been counting chars not bytes so I'll use this two byte unicode glyph: U+03BB GREEK SMALL LETTER LAMBDA. This is synonymous with the lambda keyword for creating anonymous functions, which is excellent for golf because otherwise, you'd need to (define (name args...) exprs...) which is longer. (Of course, Racket isn't very golfy otherwise.)

Length 2

#f

False. #t is for true, and so is everything that's not #f, much like other functional languages, and much to the dismay of every imperative programmer ever.

Length 3

let

Another keyword. (Still no executable code.) This one is an integral part of any LISP; it lets us define local variables and procedures.

A let form looks like:

(let ([a 1]
      [b 2])
    (displayln a)  ;; 1
    (displayln b)) ;; 2
(displayln a)      ;; error, a is not defined

Or like:

(let loop ([a 1])
    (displayln a)
    (loop (+ 1 a)))

That counts up forever, and will not cause a stack overflow because Racket is tail-recursive, like any compliant Scheme.

Length 4

cadr

One of my favourite things about Racket is this:

enter image description here

Now, car is the LISPism for Current Address Register, or the first item of a pair. LISP lists are singly linked lists like so:

'(1 2 3)
;; is actually
(cons 1 (cons 2 (cons 3 null)))
(car cdr = (car cdr = (car cdr = null))) 
;; i.e.
struct Node { int data; Node* next; };

Each item in the list is actually some data, and (a pointer to)another list, which is (a pointer to)another list, which is a... yeah.

To get the cdr (Current Decrement Register) of a given cons cell you use... the cdr function.
How to get the second item in a list? (car (cdr xs)). Or: cadr.
How to get the third item in a list? (car (cdr (cdr xs))). Or: caddr.
How to get the fourth item in a list? (car (cdr (cdr (cdr xs)))). Or: cadddr.

See where this is going? Not often are these actually used over numeric indexing, but they are very handy.

\$\endgroup\$
  • \$\begingroup\$ I don't think you're allowed to contain code in your factoid. \$\endgroup\$ – Cyoce May 1 '16 at 1:30
  • \$\begingroup\$ @Cyo I don't think demonstrating how the empty list differs from the empty application is substantial code by this question's definition, but you're free to disagree \$\endgroup\$ – cat May 1 '16 at 1:47
  • \$\begingroup\$ Fair enough. Still something interesting that wouldn't fit well into the snippet format, so I can see why you put it there \$\endgroup\$ – Cyoce May 1 '16 at 7:23
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\$

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\$
  • \$\begingroup\$ Is this meant to be a golfing language? \$\endgroup\$ – Cyoce Apr 9 '16 at 21:50
  • \$\begingroup\$ @Cyoce This is a golfing language. \$\endgroup\$ – NoOneIsHere Apr 10 '16 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\$
  • \$\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 '16 at 11:15
  • \$\begingroup\$ Math.power don't exists; the correct function is Math.pow \$\endgroup\$ – TuxCrafting Sep 7 '16 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\$

Racket

Factoid : A programmable programming language: Racket is a full-spectrum programming language. It goes beyond Lisp and Scheme with dialects that support objects, types, laziness, and more. (https://racket-lang.org/)

(I am surprised no one has added Racket till now).

Functions or procedures need to be in parentheses. First term in parentheses is procedure name, rest are its arguments. If an argument is a procedure, it has to be in its own brackets. Values (non-procedures) are written without brackets.

Main syntax difference between Java and Racket is f(a, b) vs (f a b), x+y+z vs (+ x y z), x == y vs (eq? x y) and x=2 vs (define x 2), or if already defined, (set! x 2). There is no need to declare types like public static void or int char string etc.

Length 1

i

Prints value of i.

Also: + - / * are functions:

(+ 1 2 3 4)  

Output: 10 (all numbers are added together)

(* 1 2 3 4)

Output: 24 (product of all numbers)

(/ 20 5 2)

Output: 2 (20 is divided by 5 as well as 2)

(- 10 5 2)

Output: 3 (5 and 2 are subtracted from 10)

Length 2

pi

Prints value of pi:

3.141592653589793

Length 3

let 

For local binding as in:

(let ( (x 5)   (y 10) )
  (println  (* x y))
)
; x and y are not visible here; 

Also:

map

Subjects each item of a list to the sent function, e.g. to double every item of the list:

(map    (lambda(x) (* 2 x))    (list 1 2 3) )

Output:

'(2 4 6)

Also:

for 

Standard for loop as well as its extensions:

for* for/list for/sum for/product for/first for/last for/and for/or 

There are more extensions https://docs.racket-lang.org/reference/for.html !

Length 4

Conditionals:

cond 

For example (from https://docs.racket-lang.org/racket-cheat/index.html):

(cond 
  [(even? x) 0] 
  [(odd? x) 1] 
  [else "impossible!"]) 

Also

list

Being derived from Lisp & Scheme, list is very important data structure here:

(list 1 "a" #\a (list 1 2 3)) 

Length 5

match 

Match is like case-switch:

(match x
  [3 (displayln "x is 3")]
  [4 (displayln "x is 4")]
  [5 (displayln "x is 5")]
  [default (displayln "none of the above")])

Also:

apply 

This opens a list and provides all elements to the function, for example:

(apply + (list 1 2 3 4 5))

becomes:

(+ 1 2 3 4 5) ; => 15

Length 6

Define: a very basic function- to assign value to a variable:

(define s "A string")
(define n 10)

Also:
printf - the print function:

(printf "~a ; ~a ~n" s n)

Output:

A string ; 10 

Also: Filter - a function that filters a list for items which give true value to the specified function (sent as an argument):

> (filter string? (list "a" "b" 6))
'("a" "b")
> (filter positive? (list 1 -2 6 7 0))
'(1 6 7)

The test function can be specified:

> (filter 
    (lambda(x) (> x 2))    ; function to test each element
    '(1 2 3 4 5))          ; full input list to be filtered

Output:

'(3 4 5)                   ; output list of elements greater than 2

Length 7

println : one of most commonly used function. Prints out the sent string with a newline character at end:

(println "String to be printed")

(Note: examples are from various sources on the net).

\$\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\$
  • \$\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\$ – Kevin Cruijssen Sep 20 '16 at 14:42
  • \$\begingroup\$ To downvoters: Please do not downvote just because the language isn't awesome. It still has to be showcased. \$\endgroup\$ – Erik the Outgolfer Nov 13 '16 at 7:41
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\$

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\$
6
\$\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\$
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\$
  • \$\begingroup\$ Does StackyLogic fulfill our definition of programming language? \$\endgroup\$ – Luis Mendo Jul 26 '16 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\$ – Destructible Lemon Jul 27 '16 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\$
  • \$\begingroup\$ 2 byte snippet? \$\endgroup\$ – Conor O'Brien Jul 26 '16 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\$
5
\$\begingroup\$

Straw

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

Length 1

<

Take one line of input and exit.

Length 2

->

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

Length 3

9#>

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

Length 4

<<+>

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

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

Arithmescript

Making an entry for Arithmescript here.

Codes

Length 1 snippet

i

Prints the value of i in the console.

Factoids

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

Demos

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

\$\endgroup\$
  • 3
    \$\begingroup\$ Will you add snippets 2-4? \$\endgroup\$ – acrolith Sep 26 '16 at 0:05
5
\$\begingroup\$

FEU

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

0 bytes

Cat program. Yep.

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

1 byte

/

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

2 bytes

u/

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

3 bytes

s/a

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

Empty fields are optional.

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

Octopen-Baru

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

Length 1 Code

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

Length 2 Code

倍五

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

Length 3

5那}

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

Length 4

口同愛r

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

Factoid!

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

\$\endgroup\$
  • 2
    \$\begingroup\$ Noncompeting answers are allowed, as this is a catalog. \$\endgroup\$ – Conor O'Brien Oct 24 '16 at 20:54
5
\$\begingroup\$

FurryScript

Factoid

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

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

Test snippets here.

Length 1

1

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

1 +<>

Length 2

SU

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

6 5 SU +<>

outputs this:

1
\$\endgroup\$
5
\$\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\$
  • \$\begingroup\$ You aren't restricted by votes anymore, you know. \$\endgroup\$ – Pavel Jan 2 '17 at 4:58
4
\$\begingroup\$

PyCal

Factoid:

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

Length 1 snippet

!

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

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

Length 2 snippet

IP

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

Let me explain what this does:

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

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

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

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

Length 3 snippet

(7)

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

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

Length 4 snippet

(wip)

Length 5 snippet

(i)S!

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

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

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.