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

10
\$\begingroup\$

𝔼𝕊𝕄𝕚𝕟

Length 10 Snippet

ɟ⍞#rœэ¡²Ĩċ

Here's a really nasty infinite loop. It uses jQuery to press the "Run" button, which will execute the code that presses the "Run" button, which will execute... You get the idea. Even worse, it's impossible to stop without force-quitting Firefox itself, so be careful when running.

Also, this snippet uses compression: э¡²Ĩċ decompresses to \click`.

Length 9 Snippet

ᵭꞒ↷+⬭+ᶑꞒ㘯

This is a fancy way of outputting Hello world. It uses the builtin Scrabble dictionary.

Length 8 Snippet

ʗć⁽ḊḞĒ`X

This outputs X to the canvas. Yes, 𝔼𝕊𝕄𝕚𝕟 has a canvas.

Length 7 Snippet

ⓑᴙą1

Determines how even ï is. Notice that the ï at the end is missing (which is allowed through implicit input behavior).

Length 6 Snippet

⟮ɕṡ+ᶈ0

This is a quine. (copy block) stores any code after it into an array, ɕṡ is the character, and ᶈ0 gets the stored code.

Length 5 Snippet

ɟ⍘*Ĭ)

This removes all of the interpreter's HTML using jQuery. It's an example of how manipulative 𝔼𝕊𝕄𝕚𝕟 can get with the interpreter's code.

Length 4 Snippet

¡МĂï

This calculates the factorial of ï. One difference: this uses a bignumber function to calculate values greater than 171 (JS's ordinary limit) accurately and quickly.

Length 3 Snippet

Мȫï

This outputs the ïth Fibonacci number. Мȫ is a math lib builtin.

Length 2 Snippet

⩤Ṥ

This outputs from 0 to 100. is the inclusive range function, and is the alias for 100. There are variables for numbers from 0 to 256.

Length 1 Snippet

ï

Here's a cat program! Quite simply, it gets user input and implicitly outputs it. Note that a 0-byte program would also be a cat program because of implicit input behavior.

Factoid

𝔼𝕊𝕄𝕚𝕟 (or ESMin for any of y'all who can't see the doublestruck chars) is a code-golfing language (sort of) based on Javascript ES6. Its code page contains almost 1024 chars to account for the various aliases present.

\$\endgroup\$
  • 1
    \$\begingroup\$ I just discovered that your title actually renders properly in firefox (it doesn't here in chrome) \$\endgroup\$ – SuperJedi224 Nov 15 '15 at 20:55
  • \$\begingroup\$ For me, it renders fine on my Mac and in ChromeOS, but not in Windows 7. \$\endgroup\$ – Mama Fun Roll Nov 16 '15 at 22:35
  • \$\begingroup\$ I really should learn this. \$\endgroup\$ – DJgamer98 Nov 17 '15 at 8:24
  • \$\begingroup\$ I'm currently working on updating the docs... Perhaps you should look at the source code of the interpreter for now (if you are familiar with Javascript ES6). \$\endgroup\$ – Mama Fun Roll Nov 17 '15 at 14:20
  • 1
    \$\begingroup\$ @SuperJedi224 For the first time ever, I can see the title in all browsers! \$\endgroup\$ – mbomb007 Dec 16 '15 at 23:06
10
\$\begingroup\$

Factor

Factor is a concatenative, stack-oriented and object-functional programming language first developed by Slava Pestov in 2003 as a scripting language for a game engine. Factor unites the simplicity and durability of Forth's stack-procedural paradigm and extensible word-based syntax, with the applicative, point-free and functional styles of Joy and Lisp.

In Factor, whitespace is the apply operator, the default operation. All words are first class objects; in fact, almost everything is a first-class object which means tons of possibility for extensible syntax, new types and literals, and all the other awesomeness introduced by Homoiconicity.

Unlike Forth, Factor prefers to use the many, many different higher-order words at its disposal over shuffle words, which should be avoided for the sake of readability and idiomaticity.

You can download a Factor binary, or find Factor in active development on GitHub.

Oh, its documentation is amazing, and the Listener UI / IDE (written in pure Factor) has the documentation offline and searchable. :D

I mentioned above that Factor was a scripting language -- that was back when it ran on the JVM, too. Factor, its runtime and its optimising native-code compiler are 97% pure Factor, with just 3% being low-level C++ for the VM and bootstrap.

I guess we'll go top-to-bottom, Iunno.

Link to this answer, Link to Edit.

Length 1

For length 1, let's start at the most basic building block of Factor: the word that lets us make more words.

Factor's pretty verbose so there's not much to do with one byte, because the "words" are literally words, and there's a lot of whitespace everywhere.

This means the fun in golfing comes not from shortening identifiers, but from re-Factoring, which is where Factor gets its name. :D

Factor gets a lot of its pleasant syntax from Forth. The simplest flavour of word-definition word, : is an example.

Use it like:

: word-name ( input -- output ) word-body ;

The word will then be callable by word-name, and word-body will execute, taking and putting things to and from the stack. word-name's stack effect must match its actual effect on the stack. If add takes two numbers from the stack and adds them together, leaving the result on the stack,

: add ( a b -- x ) + ;

Then its stack effect is that of the only word in its body (part of the power of concatenative languages). The identifiers in the effect don't matter, just that they are a proper representation.

Length 2

Another word-definition word, ::, allows the use of the :> lexical-variable-binding word, and causes inputs to be bound to the names in the stack effect.

:: join-strings ( a b -- x ) a b suffix! ;

To bind a value to a name:

:: var-demo ( a b c -- ) a c + b * sqrt :> val ;

val goes out of scope when the word is done executing.

Length 3

[ ]

Here, I'll let you have a guess at what this is. Hint: It's not an array.


You don't know? It's a quotation -- it allows putting an executable block of literal code on the stack, that the higher-order functional and applicative words can manipulate.

Brackets for blocks come from Smalltalk syntax (with the locals vocabulary you also get [| param | code ] which kind of resembles Smalltalk's [ :param | code ]).

Length 4

I'll try to do something more interesting this time, as fede s. suggested in the comments:

2bi@

Before I explain what this is, I should probably first explain something about Factor identifiers.

A valid Factor identifier is any string which matches the following:

^[^"][^\s]+$

Yes, that's it. Any identifier can contain any character that isn't whitespace, and it can't begin with one or more "s, because strings are special to the lexer. It can have " elsewhere within it, though.

The NUL byte, the character at UTF8 888 and the byte at 127, ASCII DEL are all valid identifiers. For portability, sometimes SYMBOLs may be stripped of their non-ASCII bytes (Windows, for instance).

This may be rather shocking to the C people and the Python people (and even the Lisp people, who allow some nice stuff in names), but fear not, for you will come to like it.

So 2bi@ is just one identifier, one name for one function. But what does it do? Well, the bi@ function applies one quotation to two items on the stack:

"5" "10" [ string>number ] bi@

--- Data stack:
5 
10

(bi stands for bifurcate, if you were curious.)

"5" "10" "15" "20" [ append string>number ] 2bi@

--- Data stack:
510
1520

2bi@, like 2map, takes a quotation with stack effect ( obj1 obj2 -- ... ), which gets applied first to w and x, then y and z in pairs.

Length 5

Finally, a word for working with sequences. Factor is no APL / J / K / Octave / what have you, but its array processing skills are... close... kinda.

union

If you're familar with Python (like I am), then you may recognise this better as the | operator on sets:

{ 1 2 3 } { 2 3 4 } union

--- Data stack:
{ 1 2 3 4 }

Removes duplicates while performing element-wise OR. Technically, the union word is from the sets vocabulary and not the sequences vocab. This is because, like Python, sets are special, super-fast immutable sequences that don't allow duplicate entries.

Also much like Python, any sequence (byte vector, hashtable, set, etc) that implements the Sequence protocol (__iter__ being the equivalent in Python) is considered fair game and supports a well-defined set (hah) of operations, so any word that works on a generic sequence A will also work on a generic set B if both have the right method dispatch.

Length 6

Ooh, more arrays! (Note that arrays are immutable; all operations on them yield new arrays and the old ones are GC'd. Vectors are mutable and slower, but we'll cross that bridge when we get there.)

2array

This is a highly useful word. Any guess at what it does? Here:

IN: scratchpad 1 2 2array

--- Data stack:
{ 1 2 } 

IN: scratchpad { 3 4 } 2array

--- Data stack:
{ { 1 2 } { 3 4 } }

Well shucks, it takes two things off the stack and makes a new array from them. 1array, 3array and 4array all do exactly what you'd expect, and narray takes an arbitrary n argument, to avoid messy concatenation code.

If I may digress yet again about naming...

In Java or Python, one might call this function values2array or valuesToArray or even values2Array. However, here in Factor-land, we have some conventions.

Remember my spiel about identifiers? Numeric digits in names should only be used for indicating real numbers or counts of things; in particular, this means 2array should not be read as to-array but as two-array.

The word which does to-array is called >array. The word which turns a number to a string is number>string, and the word which turns an object's slots to an array is tuple>array. See a pattern? Hmm.

Users of Racket will feel right at home with these sorts of names, since Racket uses stuff like number->string.

\$\endgroup\$
  • \$\begingroup\$ @fedes. Done! Have a suggestion for #5? You can even edit it in yourself; I'll make sure to accept it :P \$\endgroup\$ – cat Apr 27 '16 at 22:36
  • 1
    \$\begingroup\$ On the naming conventions and Racket (actually from scheme), there's also - for separating words (map-index), ! for mutators (union!) and ? for predicates and tests (odd?)! Good choice IMHO :D \$\endgroup\$ – fede s. Apr 28 '16 at 2:29
  • 2
    \$\begingroup\$ Why did someone just downvote this?? \$\endgroup\$ – cat Apr 28 '16 at 17:11
  • 4
    \$\begingroup\$ Also WTF w/downvote? Someone pushing another language higher? ಠ~ಠ \$\endgroup\$ – fede s. May 1 '16 at 4:24
  • 1
    \$\begingroup\$ You owe us a few more snippets! \$\endgroup\$ – bkul Jun 27 '16 at 0:11
10
\$\begingroup\$

The Hexadecimal Stacking Pseudo-Assembly Language

Alright, this is one of the several languages I've designed myself, and one of the only two three that has been implemented thus far. The program is represented as a list of 6-digit base-16 unsigned integers. Line breaks between them are optional, but not required. All other whitespace is forbidden.

It is intended to resemble a form of bytecode, even though, in reality, it isn't one. Its lack of readability may well make it a Turing Tarpit, despite the fact that it has more features than most Turing Tarpits.

Edit: It has been suggested that I score each hexit/nybble as half a byte. I think this is reasonable, so I'll go with it.

Therefore:

Length 1 snippet: 11

A command that takes a number from input. Another four hexits are required to make it syntactically valid, the next two provide a stack address and the last two are ignored.

Length 3 snippet: 110000

Takes a number from the input and pushes it to stack 00, the last two hexits are ignored but are required for the command to be syntactically valid.

Length 6 snippet: 400000400100

Pushes a zero to stack 00, and then another zero to 01. When using the first two stacks as a tape (and the third for scratch work) this is how you would initialize it at the beginning of the program, pushing a zero to stack 00, then another zero to stack 01.

Length 9 snippet: 200001400000210000

In the Brainf*** equivalence described in the documentation, this is the substitution given for the + instruction. It creates the constant 1, pushes it to stack 00, then pops the top two values of stack 00 and pushes their sum.

+, ., and , have the three shortest substitutions given.

\$\endgroup\$
  • \$\begingroup\$ Not sure if this applies, but if we're going by entropy, we would score a length-6 hex entry as 3 bytes as in meta.codegolf.stackexchange.com/questions/546/… \$\endgroup\$ – lirtosiast Jun 6 '15 at 23:43
  • \$\begingroup\$ So... should we do that for this? \$\endgroup\$ – SuperJedi224 Jun 7 '15 at 1:47
  • \$\begingroup\$ It's your choice I think; the brainfuck answer scores by characters but since this is literally hex you could score by entropy. \$\endgroup\$ – lirtosiast Jun 7 '15 at 2:29
10
\$\begingroup\$

Thue

Thue (the correct pronounciation is either "TOO-eh" or "TOO-ay", I've heard both) is a language based on nondeterministic string rewriting. It is presumably named after Norwegian mathematitcian Axel Thue. A program consists of a list of zero or more substitution rules (terminated by the null rule), followed by a string indicating the initial state.

Length 1: ~

Prepending a tilde to the right side of a rule is the language's only way to produce output. Basically, when that rule is applied, the target substring, instead of being replaced with the string on the right side of the rule, is removed and the remainder of the string (everything after the ~) on the right side of the rule is printed to the output. (A rule may be applied to any substring of the state which matches the rule's left side.)

When used in this way, a tilde is often read as "print".

Length 3: ::=

These three characters (typically read as "can mean") are used to separate the left side of a rule from the right side.

When both sides of a rule are empty, it serves as the null rule, which terminates the rule list (what should happen when only the left side is empty is undefined, most implementations treat it as equivalent to both sides being empty. It is, however, perfectly valid for only the right side to be empty.)

Length 4: 0::=

This is a complete rule dictating that instances of the substring "0" may be removed and discarded.

Length 5: 0::=0

This is a complete rule dictating that instances of the substring "0" may be replaced with... itself. This can be used to construct a simple infinite loop, as seen here.

Length 6: ab::=~

This is a complete rule dictating that instances of the substring "ab" may be removed, printing the empty string. As the specs don't actually provide any way of printing a newline, some implementations will do this when the empty string is printed.

Length 7: a::=:::

When three colons are used as the right side of a rule, this means the replacement string should be taken from STDIN. Thus, this rule dictates that instances of the substring "a" can be replaced with strings from STDIN.

Triple colons used in this way are read as "input".

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

Tcl

See also this answer.

Factoid

In Tcl eval is not evil in most cases. And you can implement your own control structures using eval.

Length 1

h

If you run tclsh interactively, you need only to write the initial characters of a command, if it is not ambiguous. In this case, there is only one command history beginning with h. So it will print the command history, which is like this:

     1  h

If you try a instead, it will print something like this:

ambiguous command name "a": after append apply array auto_execok auto_import auto_load auto_load_index auto_qualify

Length 2

[]

It's the empty string, just like "" and {}, but works differently. It executes the commands in the brackets, which are nothing, and substitute the result of the last command, which is empty.

The empty string is also a prefix of every command. So if you type [] directly in tclsh, you can get a list of all available commands while it complains that the empty string is ambiguous.

Length 3

end

Used in lindex, lrange, string index, string range, etc. While most languages require an extra operation to get the length of a string/list to specify a position at the end of the string, Tcl simply uses end. You can also use end-k where k is an integer, to make it more useful.

Length 4

"\{"

The string {. You can also use "{", but that will cause you some trouble. The bodies of control structures in Tcl are parsed as strings, and the closing brace in the following code:

if 1 {puts "{"}

will match the opening brace in the "{". So this code is an incomplete statement. You have to add another } to end the if statement.

You can escape the { to get rid of this problem. But of course, if your braces in the string are matched, you don't have to do anything. You can also make braces in different strings matched, which is still valid but may make the code less maintainable.

Length 5

{a b}

A list. Or just a whitespace-separated string. In case an element contains whitespaces or other special characters, they could be quoted using {} (which cannot contain unbalanced braces) or "" (for whitespaces) or escaped using \. "" and \ can be combined together.

There are many commands working with lists. Basic ones are list, to generate a list from elements, and lindex, to get an element from a list.

Length 6

\{{}\}

Well, I can't think of a good one with length 6. So here is something random. Apparently Tcl checks only the first character in a word to decide whether it is the beginning of a {} quoted string. So you only have to escape the first { if it is not. Better also escape a matching } to make it matched for the reason described in the length 4 snippet.

Length 7

$a(a b)

Tcl also supports arrays, which are faster for random access than lists. The grammar for accessing an array is $name(index). So there isn't such a thing as multidimensional array. What would you do if you need it to be multidimensional? Well, one way is to use a list as its index, as shown in this example. Note that the braces in {a b} are quotes of a string and not a part of the list itself, which are not used in the array access grammar. And make sure the list is in the canonical form generated using the list command if you do it this way.

It's not only for array indices. Variable names and even procedure names could also contain spaces or be empty.

After writing this I realized that it isn't as perfect as I thought. Normal variable names cannot both contain any ( and end with a ). And array names cannot contain any (. It's also a bit more difficult to access a variable with } in its name, or an array with special characters in its name and also use lists as its index.

Length 8

if 0 [a]

a is executed before the if condition. If the condition is true, the result of a is parsed as commands and executed afterward. But a is always executed. I think I saw this used some times in the old underhanded or popcon questions.

\$\endgroup\$
  • \$\begingroup\$ 'eval is not evil' :) nice pun! \$\endgroup\$ – sergiol Mar 12 '17 at 22:54
10
\$\begingroup\$

Cy

Cy is a postfix language that operates on a stack. Cy is meant to be somewhat-practical, meaning I do things like use actual words and have insignificant white space, in sharp contrast with my previous languages.


If I explain things poorly or you want to try it yourself, feel free to install the Ruby interpreter


I will be using the following format in examples (this is the format used by the Ruby interpreter's REPL (accessible via the -r parameter (ooh nested parentheticals! I should try lisp next!))):

>>> 
:: [initial stack]

>>> some code
:: [resulting stack]

>>> some more code
:: [resulting stack]

Factoid

The order in which operands are expected on the stack is based not on what makes sense, but the order in which it would be most convenient to pass on arguments in a tacit style, i.e. taking arguments in the same order as they would most likely be passed to a user-defined function. More on this later.

Length 1 Snippet

1

This pushes the number 1 to the stack.

Example:

>>>    
:: []

>>> 1
:: [1]

Length 2 Snippet

$x

This pushes the value stored in the variable x to the stack. Assigning values to variables is covered below.

Length 3 Snippet

"a"

This pushes the string "a" to the stack. Pretty self-explanatory. Note that single quotes ' cannot be used for this purpose.

Example:

>>> "a" # string 
:: ["a"]

>>> 'a' # error
Error
  @ `'a'`

Length 4 Snippet

tran

tran is an incredibly useful built-in I just implemented. This operator is used to define a stack transformation. It takes two arrays describing the old and new state of the stack. The second array should be a shuffled version of the first, and the stack will be modified accordingly.

Example:

>>>
:: [1, 2, 3, 4]

>>> [.a, .b] [.b, .a] tran
:: [1, 2, 4, 3]

>>> [1, 2] [2, 1, 2] tran
:: [1, 2, 3, 4, 3]

Length 5 Snippet

10 =x

This is the syntax for setting variable x. Note that the = sign has to be touching the identifier; 10 = x would do something different.

Length 6 Snippet

&print

Now we get into the interesting stuff. print is a function that pops something from the stack and outputs it. & is a prefix that makes its function peek from the stack instead of popping it. This means that the top of the stack will be outputted, but still left on the stack.

Length 7 Snippet

{10} if

This showcases two things - blocks and if-statements. A block holds a piece of code. The block {10} is a block that pushes 10 to the stack. The if command pops a value from the stack, and if it is truthy, executes the given block. In this case, it would push 10 to the stack.

Example

>>>
:: [0]

>>> {10} if
:: []


>>>
:: [1]

>>> {10} if
:: [10]

Length 8 Snippet

{3 2 ^-}

This demonstrates another modifier, related to &. Without the ^, the block {3 2 -} would just push the difference of 3 and 2 (1). However, the ^ in front of - makes it do something special. If the block is called with an &, it will execute &- (peek for operands); if not, it will execute - (pop the operands).

Example

>>> {3 2 ^-} =f
:: []

>>> f
:: [1]

>>> &f
:: [1, 3, 2, 1]
\$\endgroup\$
  • 1
    \$\begingroup\$ 5 votes--how to assign a variable? :3 \$\endgroup\$ – Conor O'Brien May 4 '16 at 13:43
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ read on and find out! \$\endgroup\$ – Cyoce May 4 '16 at 15:25
  • \$\begingroup\$ What would 0=x do? \$\endgroup\$ – Conor O'Brien May 4 '16 at 15:30
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ that would push 0 to the stack, but that's just a quirk of Ruby number parsing. \$\endgroup\$ – Cyoce May 4 '16 at 16:21
10
\$\begingroup\$

Pascal

Factoid : Pascal programming language is a very old programming language which is invented in 1970 (2 years older than C) by Professor Niklaus Wirth . Original Pascal is procedural .

Because of its easy syntax and perfect efficiency , many programs have been made using Pascal . some examples are :TeX - Apple Lisa - Total Commender - Skype

Major Implementations are : Gnu Pascal - Free Pascal - Turbo Pascal - Borland Pascal


Length 1 snippet :

.

This is a dot ! Any pascal program must end with "." even if it is possible to be terminated in the middle . This dot is usually written after an end . To terminate the program somewhere at the middle of execution , you need to use halt command

;

This is not a snippet , I've just mentioned it for its importance . this is an empty statement . It is so important to use it in right place . You must put this at the end of almost "every" command . but there are some execptions too . for example :

...
IF (x<=y) THEN HALT
...

is different from :

...
IF (x<=y) THEN HALT ;
...

We'll see this difference later .


Length 3 snippet :

END

This is a reserved word in Pascal . Pascal is a block-structured language - like C - which means a program is separated to blocks , and each block may be separated to some smaller blocks and so on . each block contains some statements . In Pascal , Blocks start with BEGIN and end with END (like { and } in C) . Main program is ended with END. and all the sub-programs (like functions , programmer-made procedure etc) are ended with END;.


Length 7 snippet:

PROGRAM

Sorry for the delay, fans! So, this is a PROGRAM! Every program must start with PROGRAM <name>;, where <name> is your program's name. Every program must have a "main block", which is a part of code between BEGIN & END which is not related to any other parts of code (e.g. it's not a function's definition) & program's execution starts from there.

\$\endgroup\$
  • \$\begingroup\$ “Any pascal program must end with "."” – Not only programs, but units too. “This dot is usually followed by an end.” Never seen a . followed by end, only the reverse. Then end. can be followed by any blah-blah, as it is ignored by compiler. \$\endgroup\$ – manatwork Jun 24 '16 at 12:56
  • \$\begingroup\$ @manatwork units are not in original pascal and it was first intented in turbo pascal . Also thanks for mentioning that mistake , i'll fix it now \$\endgroup\$ – user55673 Jun 24 '16 at 13:14
  • \$\begingroup\$ Oh, so the modern implementations are only mentioned without being compatible with the snippets/explanations. My mistake. (BTW, you misspelled “Borland”.) \$\endgroup\$ – manatwork Jun 24 '16 at 13:37
10
\$\begingroup\$

eacal

0-vote

eacal is a language made by me in 2016. It's very extremely verbose, but, as I hope, is capable. There is one command per line, and each data entry is separated by spaces. It is meant to be classified under a lot of programming paradigms, which includes right now, imperative, structured, stack-based, object oriented, event-driven, and a tad of functional.

Fun fact: the empty program errors.

1-vote

v

This prints:

eacal is currently running.

This tells you if eacal is still alive. Helpful!

2-vote

on

This is the event-driven portion of eacal. It's syntax is:

on <event> <code evaluating to a function>

Here is an example:

on end eval print string Done!

print string Running...

This prints:

Running...
Done!

3-vote

arg

This returns all of the command-line arguments passed to the program. Like so:

node eacal.js <file> 3 4 Hello

File:

print arg

Output:

[ '3', '4', 'Hello' ]

4-vote

init

This is used to initialize stacks, like so:

init main

Otherwise, the stack does not exist.

5-vote

alias

This sets creates a command that function the same as another command. Example:

alias define_stack init
define_stack main

is the same as

init main

This is very helpful in golfing.

6-vote

string

Represents a string, where it's arguments are joined by spaces. So, Hello, World! is this:

string Hello, World!

7-vote

numlist

This returns an array of numbers representative of its arguments. For the first few Fibonacci numbers in a list:

numlist 0 1 1 2 3 5 8 13 21

8-vote

func add

This shows some of eacal's function programming. You can execute it on a stack named k using exec k--func add. For example:

init main
push main number 5
push main number 8
print exec main--func add
; outputs 13
\$\endgroup\$
10
\$\begingroup\$

Casio-BASIC

Casio BASIC is very unlike TI-BASIC; firstly, it doesn't require as much RAM, memory or power. Programs typically only use a few KB of RAM. Secondly, it allows scrolling through the list of functions to write a program, or the use of special buttons which insert common characters. However, unlike TI-BASIC, functions can simply be typed in letter by letter from the keyboard.

Length 8 snippet

Print 9!

This prints 9 factorial, which is 362880.

Length 9 snippet

Print n+n

Even though we didn't define n, the calculator doesn't throw an error. Instead, it treats n as an expression, and prints out 2·n. (A floating dot is used by the calculator to represent multiplication)

Length 13 snippet

DrawGraph x^2

Opens an empty graph plane, and draws the graph of y=x^2 onto it.

Length 15 snippet

seq(x^2,x,1,10)

This will print x^2 for all values of x between 1 and 10.

\$\endgroup\$
  • 1
    \$\begingroup\$ Is it suited for golfing? \$\endgroup\$ – lirtosiast Aug 29 '15 at 4:59
  • 5
    \$\begingroup\$ It probably isn't. \$\endgroup\$ – georgeunix Aug 29 '15 at 5:25
  • 6
    \$\begingroup\$ Add some snipits? \$\endgroup\$ – Conor O'Brien Oct 5 '15 at 20:44
9
\$\begingroup\$

JSFuck

Length 5

+!+[]

As mentioned before (in the length 4 section), !+[] produces true. Also, as mentioned before (in the length 1 section), + can cast to number.

Therefore, this code casts true to number, which is 1.

This snippet can be chained indefinitely to produce any number you want.

For example, 2 would be +!+[]+!+[], and 3 would be +!+[]+!+[]+!+[].

As mentioned before (in the length 4 section), +!![] is also valid.

Length 4

!+[]

The operation ! casts to boolean.

The number 0, the empty string "", the undefined, and the NaN are all treated as false.

Other objects are treated as true.

Unlike Python, the empty array [] and the empty object literal {} are treated as true.

Therefore, this is the shortest snippet to produce true. It is equivalent to !0.

!![] would also work.

Length 3

+[]

As mentioned before, + casts to integer. In this case, it would be evaluated to 0.

However, also as mentioned before, + can join two arrays to form a string.

Therefore, +[]+[] is really 0+[] which would produce "0".

Length 2

++

There are really only 36 length-2 snippets.

Out of the 36 snippets, I chose this one.

This is the shortest way to add 1 to a number.

This function is very strange.

For example, v=1; ++v works, but ++1 does not.

For example, v=[]; ++v also works (empty array [] is implicitly cast to 0), but ++[] does not.

To make it work in JSFuck, you would have to type ++[[]][+[]] instead.

[[]][+[]] is really [[]][0], which is an empty array [].

Why ++[[]][+[]] works but not ++[] is yeond me.

Length 1

+

+ can convert a string to a number, as well as adding two arrays together to form a string. For example, +"0" would result in the number 0, and [1]+[0] will result in the string "10".

Factoid

All JSFuck programs are valid Javascript programs. However, JSFuck aims to use only 6 operators to do everything: +![](). Also, its name is derived from JS (javascript) and Brainfuck. Brainfuck only uses 8 operators.

\$\endgroup\$
  • \$\begingroup\$ It's not strange; increment only works on variables. \$\endgroup\$ – ASCII-only May 24 '16 at 13:34
  • \$\begingroup\$ Why is [[]][+[]] a variable but not []? \$\endgroup\$ – Leaky Nun May 24 '16 at 13:36
  • \$\begingroup\$ @LeakyNun I'm guessing there, but isn't [[]][+[]] technichally the value in an array's cell? hence, it's technichally a variable, alllowing to increment it. \$\endgroup\$ – Katenkyo May 24 '16 at 13:40
  • \$\begingroup\$ @Katenkyo Thanks, but I still don't get it. What is [] then? \$\endgroup\$ – Leaky Nun May 24 '16 at 13:47
  • \$\begingroup\$ @LeakyNun it is an array in itself, in some cases JS will allow you to use it as a pointer to its first value in the second case, you get an empty array, yes, but it is interpreted as a value as it is inside an other array -> [[]][0] vs []. In first case you have the value of an array wich is considered a variable of type "array", in the second one, you manipulate an array. \$\endgroup\$ – Katenkyo May 24 '16 at 13:53
9
\$\begingroup\$

Scratch

Factoid: Scratch has a great appeal to younger audiences, with the large majority of new accounts being from 10 to 16 years old.

1 byte

Say
The say block takes what is in the text space and outputs it as a text bubble.

2 bytes

Start & Stop
The when green flag clicked block is essential for most programs. The stop [all/this script/other scripts in sprite] block does exactly what it says, but it isn't used much in optimized scripts.

\$\endgroup\$
  • \$\begingroup\$ The highest-ranked scoring rule you linked to scores the say block as four bytes say( plus the contents. \$\endgroup\$ – Not that Charles May 25 '16 at 18:41
  • \$\begingroup\$ Although since it does not specify a human-language for scratchBlock output, you can also use decir( or 说( or lots of other options... \$\endgroup\$ – Not that Charles May 25 '16 at 18:44
  • \$\begingroup\$ I'm going off the main post, not the responses. \$\endgroup\$ – weatherman115 May 25 '16 at 18:55
  • \$\begingroup\$ ... but that's not how meta works. However, it makes sense to use "each block is one vote" for the purposes here. \$\endgroup\$ – Not that Charles May 25 '16 at 19:45
  • \$\begingroup\$ And each character of text in text spaces is one vote. Don't forget about that. \$\endgroup\$ – weatherman115 May 26 '16 at 16:23
8
\$\begingroup\$

O

Factoid

O is a programming language inspired by GolfScript, Pyth, K, and tons of other languages. It was made by Phase (me) over the summer of 2015, so it is relatively new. The interpreter was originally written in Java, but development has recently switched to a C interpreter. Here are some examples of the language.

Length 5

'69+o

This programs prints 69.

  • '6 pushes 6 as a string
    • ' pushes the next character in the program as a string to the stack
    • 6 is the next character, so it gets pushes as a string
  • 9 pushes the number 9 to the stack
  • + adds the top two elements of the stack. Since of them is a string, they get concatenated.
  • o outputs the result

Length 4

M]+o

This program gets the sum of all the digits of the input number. (1234 = 1 + 2 + 3 + 4 = 10)

  • M is a builtin macro that calls [i~.
    • [ Starts an array (which really acts like another stack)
    • i Gets an input from stdin and pushes it to the stack (the array in this case)
    • ~ Evaluates the top of the stack (the input) as O code, which pushes each digit of the input number to the stack.
  • ] Closes the array, pushes it to the stack
  • + Folds the array by adding all the elements together
  • o Outputs the sum of the digits to stdout.

It's a pretty complicated program for only being 4 bytes!

Length 3

{1}

O supports CodeBlocks like GolfScript and CJam. This is a CodeBlock that pushes the number 1 to the stack when it is run. Just creating a CodeBlock pushes the block itself to the stack, without running it. We could assign it to a variable, or use ~ to run it.

Length 2

Ao

A pushes 10 to the stack. o pops the top of the stack and outputs it to STDOUT. This program outputs 10 to the screen.

Length 1

1

Any number literal will be pushed to the stack as an integer. The stack is not outputted when the code ends (though this may change soon!), so the program exits without outputting anything.

\$\endgroup\$
8
\$\begingroup\$

ShapeScript

Length 6 snippet

"%c"@%

ShapeScript has no type casts, but Python's % can be used to work around this limitation. This snippet, e.g., pops an integer from the stack and pushes the singleton string of the corresponding Unicode character in return.

Length 5 snippet

'"A"'

This is a string that, when evaluated, pushes the singleton string A on the stack. There is no way to escape a quote in ShapeScript, so two different kinds of quotes are required to use strings in evaluated strings.

Length 4 snippet

01-?

This calculates -1 and then pushes a copy (?) of the bottom-most item on top of the stack. Since there are no variables, leaving things on the bottom to access them later is a common technique.

Length 3 snippet

123

Despite what it may look like, this actually pushes three integers on the stack. Any integer above 9 or below 0 has to be pushed as angebraic sum of products of integers.

Length 2 snippet

*!

With a Boolean and a string on the stack, * pushes the unmodified string for True and and empty string for False, which ! then evaluates. This is the closest ShapeScript has to a conditional operator.

Length 1 snippet

!

Discounting that it can no longer take input, this is a fully compliant ShapeScript interpreter.

Factoid

I created ShapeScript as one half of my submission to Create a programming language that only appears to be unusable as a simple, stack-based language with a simple syntax.

While ShapeScript is far from unusable, it does not have traditional loops, conditionals or variables, can modify only the two topmost stack items, can modify strings only using split and join, etc.

\$\endgroup\$
8
\$\begingroup\$

TurtleGolf

Kind of a shameless plug, but I present to you my very very first language!

It's a simple stack-based language designed to let people make shorter turtle programs.

Factoid

The stack is pre-populated with five zeroes, use this to your advantage in !

Length 1
;
Every single line of code in this language is a loop that will run until the pointer reaches a ;. When the pointer reaches this command, it will break the loop and go to the next line.

Length 2
f^
Yay, two new things! The command f pushes the number 15 onto the stack, and the ^ command pops the top value from the stack and moves forward by that amount in pixels. Too bad we don't have enough room for a ;, so this turtle is going to move forward forever.

Example

The stack during execution:

[0,0,0,0,0]      start
[0,0,0,0,0,15]   f
[0,0,0,0,0]      ^
[0,0,0,0,0,15]   f
[0,0,0,0,0]      ^
etc.

Length 3 snippet
)?;
Finally an if-statement! ) pops two values from the stack and checks if one of them is greater than the first. (It pops X and Y, and checks if Y > X) If that's the case, 1 is pushed on the stack. ? pops one value from the stack and checks if it's zero or non-zero. If it's zero, skip the next command (In this case it's the ';', which terminates the line). Otherwise, run the next command.

Example

The stack before execution:

[0,0,0,0,0,5,2]

The stack during execution:

[0,0,0,0,0]    ) pops the 5 and the 2 to check if 5 > 2.
[0,0,0,0,0,1]  5 > 2, so push 1.
[0,0,0,0,0]    Pop the value so ? can check if it's zero.
[0,0,0,0,0]    It is not zero, so execute the next command, which terminates the line.

Length 4 snippet
12+f

You can use the + - * and / commands to add, subtract, multiply or divide the top two numbers of the stack.

The stack during execution:

[0,0,0,0,0]      Start
[0,0,0,0,0,1]    1 pushes 1 on the stack
[0,0,0,0,0,1,2]  2 pushes 2 on the stack
[0,0,0,0,0,3]    + pushes (1+2=)3 on the stack
[0,0,0,0,0]      f moves the turtle forward by 3 pixels.
\$\endgroup\$
8
\$\begingroup\$

Hassium

Hassium is an object oriented programming language in C#. It contains many of the exact C# classes and over 400 functions built in. You can run Hassium code and examples here.

Length 1

5

This is a constant integer in Hassium.

Length 2

a:

This is a label in Hassium. Hassium supports labels and gotos as well as all types of loops.

Length 3

m()

This is a call to a function called m in Hassium.

Length 4

a=4;

This is declaring the variable a with the initial value of 4. In Hassium you don't have to declare the type of variable like int a=4;

Length 5

a=[];

This declares a new array in Hassium, where arrays are Javascript and python like. From here I could do a.add(), etc.

Length 6

use IO

This imports the IO module into the global namespace, which contains sever different classes including File, Directory, and Path. Hassium as a whole has several of these builtin modules with countless classes.

Length 7

print()

This is the most simple function in Hassium, the print() function which takes in a string and displays it to the console without a trailing newline. print() is one of the functions that is in the global namespace, and not in a class or module.

\$\endgroup\$
8
\$\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\$
8
\$\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
8
\$\begingroup\$

IPOS

Factoid

IPOS is a stack-based golfing-language for string processing. An IPOS program places it's input on the stack at the start and prints the concatenated stack contents at the end. This has the nice side-effect that a zero byte IPOS program is equivalent to a basic cat-program.

Length 1

L

IPOS has a set of predefined variables. This program pushes the value of the variable L to the stack which is the alphabet in lowercase letters. Remember that any input string gets placed on the stack initially. So this program appends the lowercase alphabet to the input and prints it.

Length 2

SA

This program takes a string with space-separated words and sorts them in ascening order. For example the input Programming Puzzles & Code Golf yields the result & Code Golf Programming.

How this works
The input string is already placed at the stack. We push a space (variable S) to the stack and apply the command A which splits the input on spaces, sorts the resulting substrings in ascending order and joins the result back on spaces.

Length 3

'A=

As mentioned in the first program, IPOS has a set of predefined variables. If you want to define a custom variable, you can do that with the = command. It creates a new variable with the name given in the top stack item and assigns the value given by the stack item below that.

Variable names can only be one character long. Also they overwrite the original meaning of this character which means that we can no longer use A for sorting as we did in the program with length 2.

So this program simply takes the input and saves it in a variable named A. Since you usually need this value right away, = also leaves the assigned value on the stack, so the output of this program is identical to the input.

Length 4

P!r%

This program takes an input string and reverses each substring between dots. So the input abc.def.ghij yields jihg.fed.cba.

Straight to the code breakdown this time:

P!r%

P      # Push a dot '.', one of the predefined variables.
 !r    # Push a command that reverses a string
   %   # Split the input on dots, apply the reverse command to every substring 
       # and join the resulting substring back on dots.

This shows one of the commands for functional programming. Those make use of command objects that are basically strings which get treated as IPOS code. They can be created like normal strings, but instead of quotes, we use backticks for them. To create a command object with only one command we can just put a ! before it.

Length 5

S'+Re

This program takes a string of space seperated numbers and outputs their sum. Pretty simple task, but the way it does that is quite interesting.

IPOS does not have any builtins for math operations besides simple incrementing and decrementing. It is still a language for string processing, so I didn't see a reason to include those. However, we can make use of the eval command e to do some basic math. This command takes a string and performs the numeric calculations in it using Python syntax.

You might already suspect where this is going. The above program simply replaces spaces with pluses by pushing a space and a plus character and applying the replace command R to them and the input. The resulting string then gets evaluated by e which yields the expected result.

Length 6

S`2<`%

This program takes a string of space separated words and removes all but the first two characters from them.
We are using % again here which splits the input on a given character (here space), applies a set of commands to each part and joins the parts back. As mentioned above, command objects can be created just like a string, but are enclosed in backticks. The command we are applying to each part here is 2< which takes the first two characters of a string and discards the rest.

Length 7

SC/eCPj

This program takes a string followed by a space and a number, splits the string into that many pieces and joins the result back on dots.

SC       # Split input on spaces
  /      # Swap the two top stack items so the number is on top
   e     # Convert the number into an integer
    C    # Split the string into pieces and pushe the substrings to the stack
     Pj  # Join the whole stack on dots
\$\endgroup\$
8
\$\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
8
\$\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
8
\$\begingroup\$

CSS (Cascading Style Sheets)

Somebody's already done a CSS answer, but here's another one. I promise to make the one-char snippet exactly the same. :)


6 chars

:hover

This is an example of a pseudo-class, which is basically the state of an element. The :hover pseudo-class applies when the element is being hovered over; some others are :active (mouse button down), :valid/:invalid (form/input is valid/invalid), and :target (element is target of current #hash-portion-of-url).

Pseudo-classes can also take arguments, for example :not(some-other-selector) and the :nth-child family: :nth-child, :nth-last-child, :nth-of-type, and :nth-last-of-type.


5 chars

--foo

CSS variables, properly known as custom properties, function like variables in other languages, only a bit more

c
 a
  s
   c
    a
     d
      i
       n
        g

to fit in better with the nature of CSS. Variables are used like this:

:root {
  --foo: goldenrod;
}

.some-element {
  background-color: var(--foo);
}

.another-element {
  background-color: lightgray;
  border: 3px solid var(--foo);
}

and var(--foo) is replaced with the value of --foo.

However, because these variables are parsed at runtime, not as a compilation step in a preprocessor such as Sass or LESS, they can be used more dynamically. For example:

:root { --foo: red }
body:hover { --foo: blue }
p { color: var(--foo) }

This will make the text in <p> (paragraph) elements red, except when the <body> is hovered, in which case the text will turn blue.


4 chars

42cm

As well as the px (pixels), em (relative to font size), rem (relative to font size of root element), vh (1/100 of viewport height), and vw (1/100 of viewport width) units, which are usually what you use, CSS also has physical units for cm, mm, and in. The only problem is that they don't necessarily represent physical centimetres, millimetres, and inches, but (device-dependent) may be relative to the assumption that 1 inch = 96px. Anyway, it's usually better to use relative units like em and rem instead.


3 chars

-o-

Browser prefixes allow browsers to implement WIP standards before they've been finalised. The idea is that if the spec changes, the old implementation's behind a prefix so the correct implementation can be done without the prefix. However, browsers are moving away from prefixes in favour of flags set by the user in the browser (chrome://flags in Chrome and about:config in Firefox), as prefixes have caused headaches when trying to ensure compatibility with old browsers.

The prefix shown above is for Opera (before it switched to using the Blink rendering engine); the other prefixes are:

  • -webkit- for WebKit/Blink (Chrome, Opera, Safari)
  • -moz- for Gecko (Firefox)
  • -ms- for that thing.

Prefixes are used like this:

.foo {
  -webkit-transform: rotateZ(30deg);
          transform: rotateZ(30deg);
}

They can also be used on selectors and property values.


2 chars

//

People ask why CSS doesn't have // comments. Well it does. Sort of.

In this blog post, Tab Atkins talks about using // comments in CSS. They don't function as line comments, but rather "next construct comments". This means that these are equivalent:

foo {
  color: white;
  // font-weight: bold;
  background-color: black;
}

// bar {
  width: 12rem;
}

// @keyframes baz {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

and

foo {
  color: white;
  /* font-weight: bold; */
  background-color: black;
}

/* bar {
  width: 12rem;
} */

/* @keyframes baz {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
} */

There are also some weird tricks like using a @comment { } block to simulate nested comments.


1 char

*

The star hack. Sample usage:

.foo {
  background-color: lightgray; /* displayed by most browsers */
  *background-color: red; /* displayed by IE <= 7 */
}

Factoid: some web servers originally served .css files as application/x-pointplus, to do with presentation software, instead of text/css.

\$\endgroup\$
8
\$\begingroup\$

Unipants' Golfing Language

Factoid

UGL only has 16 operations, a stack, registers, ifs and whiles to do things. But even if these supplies are to spare, anything may be possible if you do things smart enough... or not? ;-)


Length 5 snippet

IlOI:

Try it online!

This is the cat program. As you see, it is a translation of the brainfuck program ,[.,].

I captures one character, so it is the same as , in bf. O prints one character, so it is the same as . in bf. And l and : enclose a while loop, that works the same as [ and ] in bf (while the top of stack is non zero).

Length 2 snippet

io

Try it online!

This program reads and writes an integer. And guess it, it can be any length. i is greedy, meaning it will catch as long an integer as possible.

Length 1 snippet

s

Try it online!

This program sets the current register number to zero. First, let me show you an excerpt of the README for registers:

Registers

  • r - load the value in current register

  • R - save the value in current register

  • s - set current register number to top of stack

If the stack is empty, the current register number is set to zero.

\$\endgroup\$
8
\$\begingroup\$

Tellurium

Factoid

Tellurium is an esoteric, tape-based programming language written by me in Python. It's mainly intended for use in code-golf challenges, but it pretty much failed at that task.

Length 1 snippet

^

^ is the output/print command. It outputs whatever is in the selected cell, which, in the above snippet, is 0. (0 is the default value)

Length 2 snippet

i^

This is a simple cat program (a program that copies its input to its output). i takes input and puts it in the selected cell. As you probably remember, ^ outputs whatever is in the selected cell.

(I promise that there will be more interesting snippets later on. There's not much you can do with two commands)

Length 3 snippet

I§^

This snippet calculates the factorial of the input and displays it.

I gets input and converts it to an integer. § calculates the factorial, and stores the result in the selected cell.

There are numerous other math-related one character builtins, for example:

I½^ calculates the exponent of the input

Iq^ calculates the square root of the input

Length 4 snippet

{p}f

This is an anonymous function that does... nothing.

In Tellurium, you can create an anonymous function by using the syntax {code}f. The function can then be called using the command ä.

p is a placeholder command, the equivalent to the Python statement pass.

Length 5 snippet

[I|^;

This snippet uses a loop to output 0 n times. The syntax for a loop in Tellurium is [times|code;. If I is in the times section, it will run the code input times.

Length 6 snippet

µHi!~^

Finally, something more interesting. This snippet outputs Hi!. The syntax for inserting text into the selected cell is a bit strange: µ(text)~.

Length 7 snippet

¤h|Hey]

This snippet showcases variables. Again, the syntax is a bit strange: ¤(name)|(value)]. In this case, it stores "Hey" in the variable h.

To display that variable, use ;h.^.

\$\endgroup\$
8
\$\begingroup\$

GNU Octave

Snippet 7:

disp(j)
 0 + 1i

Prints j out to the screen without the ans = overhead

Snippet 6:

[i](1)
ans =  0 + 1i

This generates an instance of a scalar only containing sqrt(-1), takes the first element of it (a complex number), and prints it out. A scalar is basically an array.

Snippet 3:

{3}
ans = 
{
  [1,1] =  3
}

This generates an instance of a matrix with one entry, 3.

Snippet 2:

[]
ans = [](0x0)

This is just a simple empty array.

Snippet 1:

j
ans =  0 + 1i

Yes, Octave understands i or j as the square root of -1!

Factoid: Octave is free and approximately 80% compatible with Matlab! (except toolboxes)

\$\endgroup\$
  • 1
    \$\begingroup\$ ... I can't believe this doesn't already exist. Nice job creating it! \$\endgroup\$ – Rɪᴋᴇʀ May 4 '16 at 14:05
  • 1
    \$\begingroup\$ @EᴀsᴛᴇʀʟʏIʀᴋ, Well, it does. =) \$\endgroup\$ – Stewie Griffin May 13 '16 at 10:04
  • 1
    \$\begingroup\$ The question says: It is suggested that you choose a programming language that has not been posted already but this is not a requirement.", so it's OK for you to have another Octave entry. Personally, I suggest you don't use any of the features that's already covered in my (and possibly flawr's answers). \$\endgroup\$ – Stewie Griffin May 18 '16 at 7:48
  • 1
    \$\begingroup\$ {3} creates a 1-by-1 cell array with a 1-by-1 matrix with the value, 3 in it. Creating a 1-by-1 cell array rarely has any pros, only cons. But the brackets can be used to create cell arrays with more elements too of course: {3, rand(3,2); 'This is a string in a cell', magic(4)}, in which case it's very useful. \$\endgroup\$ – Stewie Griffin Aug 10 '16 at 5:34
  • 1
    \$\begingroup\$ This generates an instance of a matrix with one entry, 3. The way to do this exact task is simply one byte: 3! =) Try x = 3; y={3}; whos. You'll see that x is a 1-by-1 double, where as y is a 1-by-1 cell. y = {'This is a cell'} will also result in a 1-by-1 cell. whos y{1} will show that that specific cell element contains a 1-by-14 array of chars. You can't do y = {3}, followed by y==3 or y+3 if yis a cell, since they're not of the same class. \$\endgroup\$ – Stewie Griffin Aug 12 '16 at 8:19
8
\$\begingroup\$

Copy

Copy is my new esolang. The only branching operations are skipping a instruction and code removing and copying, and the only arithmetic operations addition and negation.

Length 6

skip 0

skip skip the next instruction if its argument is not 0. So here, it's essentially a no-op.

Length 7

add a 5

Add 5 to the variable a. Since a is undefined, it set it to 5.

Length 8

add a -8

Add -8 to the variable a. This is to demonstrate than signed numbers are allowed as command arguments.

\$\endgroup\$
  • \$\begingroup\$ Good luck getting enough to make a working program. :P \$\endgroup\$ – user48538 Sep 24 '16 at 20:49
  • \$\begingroup\$ Where's 1 to 5? You don't have to make full programs, you know - something like skip is acceptable. \$\endgroup\$ – Qwerp-Derp Sep 26 '16 at 7:55
8
\$\begingroup\$

Fourier

Factoid

I originally intended this to be a golfing version of Brainfuck... Alas, due to the simplicity of the language structure, this language is in no way good for golfing.

Snippets

Length 0 Snippet:

         

An empty program does nothing. No input, no output, no change to the accumulator.

Try it online!


Length 1 Snippet:

o

o outputs the value of the accumulator. Since the value of the accumulator is 0 at the start of the program, 0 is outputted.

Try it online!


Length 2 Snippet:

^o

^ increases the value of the accumulator by one. The o then outputs the value of the accumulator, printing the number 1.

Try it online!


Length 3 Snippet:

9ro

r generates a random number between 0 and the value pf the accumulator. Here, it generates a random number between 0 and nine and then o outputs the number.

Try it online!


Length 4 Snippet:

4^do

Uses the fifth function of the date function: outputting the current year. The other functions of the date function are:

  • 0: current second
  • 1: current minute
  • 2: current hour
  • 3: current day
  • 4: current month
  • 5: current year

Try it online!


Length 5 snippet:

I*10o

Sets the value of the accumulator the user's input, multiplies it by ten and outputs the number. It's a basic program but demonstrates how user input works.

Try it online!


Length 6 snippet:

2(5ro)

This program prints random numbers until the random number is 2. It is an example of looping:

x(code here)

Repeats the code within the brackets until the resulting value of the accumulator within the brackets is equal to the value of the accumulator at position x.

Try it online!


Length 7 snippet:

|7o|GGG

This is an example of a function. It works like so:

|code here|x

You contain the function code within the pipes and store the function in the variable x (can be any variable name). To run the code within the pipes, just write the function name.

The function here prints the number 7 twice because g (the function name) is called twice.

Try it on FourIDE!


Length 8 snippet:

I^~NN%2o

This is a simple program which takes an input of a single number and tells you if the number is even (1) or not (0).

It is an example of how Fourier uses 1 and 0 as truthy and falsey values.

Try it online!

\$\endgroup\$
8
\$\begingroup\$

QBIC

I'm trying to teach QuickBasic to do codegolf (and myself in the process), so I'm creating the language Quick Basic Interpreter for Codegolf, or QBIC for short.

0 byte factoid

Most of QBIC's strength lies in just making a shorthand for QBasic's expansive syntax, but I've also incorporated several features of my own. When generating the trans-compiled BAS file, a standard header is imported that implements some of these features. For instance, the numbers 1 through 10 get initialised as variables q through z. This occasionally saves me some bytes when initialising a FOR loop, and shaves a byte off of using 10.

1 byte

}

The above statement will do ... exactly nothing. When found in the QBIC code, it wil automatically add END IF's, NEXTs and LOOPs for every opened IF/FOR/DO construct it finds (in the correct order, naturally). Note that ] does the same for one language construct, where } closes all opened constructs.

However, since we've not yet opened any of those constructs, this does nothing and results in an 'empty' Qbasic BAS file. Also, at the end of compiling QBIC, the compiler will run this statement automatically.

2 bytes

?z

This will write 10 on the screen. In QBIC, the letters of the lower-case alphabet are references to numerical variables. This is retained from QBasic, where PRINT a would give me a 0 on the screen (even without ever defining a). In addition, QBIC initialises q-z to be 1 through 10 by default. The ? is obviously shorthand for the PRINT statement and writes to screen.

3 bytes

_Xb

_X can be used to terminate a program, and when used with a suffix, it will print something on exit. Suffixes can be A-Z (which refers to string variables A$ - Z$) or lowercase a-z (for the numerical vars of this name). The example snippet ends the program, and prints variable b to screen before it turns off the lights.

4 bytes

?_r|

_r is a random number generator. By itself, it will generate a random number between 0 and 10 and, in this case, print it. We can also add one or two parameters for a different lower and upper bound; If only one is specified, that's our new upper bound.
_r20| will generate a number between 0 and 20.
_r5,18| will generate a number between 5 and 18. The statement _R is equivalent to _r with one exception: _R assigns to a variable, _r does not:

?_r|    PRINT getNextRandomNumber(0, 10)
_R|?a   a = getNextRandomNumber(0, 10) : PRINT a

5 bytes

:_Ra|

The above snippet introduces the :, which reads the first unread command line parameter and assigns it to the first available numeric var. The resulting QBasic code for this snippet is:

a = assignCMDToNum!
b = getRandomNumber(0, a)

There's also ;, which does the same for string variables.

6 bytes

?!z$+A

Here, we see a cast in action. QBasic is kinda picky when it comes to data types. Adding a string to an integer will result in errors. To work around this, I've added a casting function. The above snippet will print 10 (z is auto-initialised to 10) and append whatever is in the variable A$. For instance, a full program could be

#test`?!z$+A

and the result then is 10test.

Casting is done using the ! symbol. It then casts everything between the ! and the delimiter. Usually | is the delimiter for variable-length arguments, but CAST uses either a $ to perform the cast from number to string, or another ! to cast a string to number.

7 bytes

Z=_f_tA

Lot going on here. Let's work on the assumption that A$ already holds a value, say " Hello " (significant spaces). This snippet then sets Z$ to the reversed (_f), trimmed (_t) version of A$, olleH and prints it to the screen.

  • The behaviour between _f and _F is different: _F declares a variable and assigns its output to it, _f only gives the output and assigning is done by other parts of the script. The same goes for _r in my 5-byte snippet. This is called ULX, or Upper-Lowercase Extension. Whether or not output gets auto-assigned is one of the behavioural changes ULX can bring, but there are other examples. _D, for intance, yields the system date, _d yelds system time. Both don't auto-assign.

  • _t removes the whitespace on both sides of its argument. _u does a left-trim, _v does right-trim. All three support ULX, and for all three this switches between auto-assign (uppercase) or output only (lowercase).

  • Both _f and _t should be delimited with | to signify the end of the parameter list. However, since EOF is reached, the correct number of |'s get added to close all opened parameter lists. If this statement would have been followed by the closing commands for language constructs (]or }, see byte 1) those same |'s would get added.

  • QBIC allows for the result of one function to be the input for the next: _f takes as input the result of _t

  • Finally, if we would run this program, it would actually print olleH, despite we never use a ? or _X* statement. This is because QBIC implicitly prints the contents of Z$ on exit.

Summarizing, the above 7-byte snippet would roughly compile into this QBasic block:

FUNCTION revstring$(in$)
  ... function definition imported through QBIC.H
END FUNCTION 

... we set A$ to be "  Hello  "

Z$ = revstring$(LTRIM$(RTRIM$(A$)))

PRINT Z$

8 bytes

Let's look at literals. There are 2 types in QBIC: String literals (Verbal and Silent) and Code Literals. They are started with @, # and ' respectively, are terminated with ```. Using a &boxul; respresents a line-break.

?@check`  --> Verbal string literal: Defines A$ in the header, assign the value "check" 
              to it, and insert A$ in the body of the resulting QBasic at this moment. 
#10`?A+A  --> Silent literal: Defines the literal A$ as "10", but doesn't insert `A$` 
              in the QBasic output at this time. This sample then prints "1010"; `+`in 
              this context is string concatenation.
'SQR(9)`  --> Code literal: from the `'`(which would be seen as a comment by QBasic) to
              the ``` is not stored as a variable, but passed unaltered to the resulting 
              QBasic. This particular statement calculates the root of 9.
\$\endgroup\$
8
\$\begingroup\$

ActionScript 3

Factoid

AS3 is a scripting language designed to be used in client games and applications. It's a fully object oriented language that features dynamic objects that can be changed at run time, just like JavaScript.

1-length code

7

Each number in AS3 is treated as an object.

2-length code

as

AS3 is a strongly typed language; this is how to perform casting.

3-length code

int

This is one of the two number types that AS3 contains. The designers of the language preferred to make it simple and included just two types:

  • 64-bit float for long values and floating points.
  • 32-bit int for integers, perhaps for performance.

5-length code

a:*=1

In AS3, functions may have optional values; in this code snippet, 1 is assigned to a if no other value been passed to the function. The value after the : represents the type of a; in this case it's *, which means it can have any value. The difference between * and object is that * can also have undefined type. This is how Adobe explains it:

When you want to defer type checking to runtime, you can use an untyped property or expression to circumvent compile-time type checking in strict mode. Note, however, that runtime type checking of assignment statements occurs whether you use strict mode or not.

9-length-ish code

trace("a",0)

trace is the best logging mechanism ever! You don't need to care about the type you are passing to the trace not the number of the params, it will simply print it all back to you, separated with a space char.

\$\endgroup\$
  • \$\begingroup\$ I'm afraid your length-4 code snippet is five characters long? \$\endgroup\$ – Lynn May 27 '15 at 19:30
  • \$\begingroup\$ @Mauris Shhhh, lets keep it between us ;) \$\endgroup\$ – Ilya Gazman May 27 '15 at 20:24
  • \$\begingroup\$ I coded on AS2 so I dont know if this is still a thing but one of my favorite features of AS2 was the ability to use the this. operator when adding code to an object. If I drew a mouse on stage and then selected the mouse and added the code this.x += 5; it would move 5 pixels right (as opposed to stage.layer1.mouse.x += 5; or whatever it was (It's been like 13 years since I coded in AS2 hahaha) \$\endgroup\$ – Albert Renshaw Feb 24 '17 at 7:11
7
\$\begingroup\$

Stylus

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

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

Length 1

=

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

Length 2

p
    a

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

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

Simplex

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


6-vote

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

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

5-vote

"hi"g

Writes a string hi to the strip and outputs it.

4-vote

eRPE

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

3-vote

i¢I

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

2-vote

MO

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

1-vote

5

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

0-vote

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

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

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

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

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.