dd

From Esolang
Jump to navigation Jump to search
dd
Paradigm(s) Imperative/String-rewriting
Designed by A
Appeared in 2018
Computational class Finite-state automaton
Reference implementation N/A
Major implementations Javascript
File extension(s) .txt

dd is an esoteric programming language published by User:A in 2018, on July fourth. It is an implemented finite-state automata, that has one instruction. "dd" is not to be confused with the UNIX command with the same name.

DDescription

dd has no stack, tape or queues, instead taking a more dynamic approach to output and calculations. Rather than using a set of instructions to control the program flow, the execution order is always the same and straight forward. There is no way to define a variable or a data-structure, and the source code is exactly what the computer will do, which is a concept many find hard to grasp.

There is only one instruction, if you can call it that — dd. It has very interesting properties which make quines and such very easy to write, but more on that later. Anything that isn't this instruction is either ignored, or in some implementations causes an error. Case sensetivity is also up to the implementation to decide, as it's unspecified by original author. The only thing we can say for sure is that the standard syntax is supposed to have both letters lowercase.

dd has no way to input things, no STDIN libraries, no way to read an external file, or even a command-line input. While this is problematic, it has its advantages. For example it is easier to write implementations, because the source code can be taken as input.

Syntax

Instruction Arity Function Size Added in Removed in Alternative syntax Notes
dd 0 Print "dd" in the console. 2 bytes version: 1.0 -- Dd Required in all implementations.
<Anything else> -- Do nothing. Any size -- -- -- In some implementations can cause an error.

dd is an instruction, not a pattern, so:

ddd

will output dd, not dddd, because there is only one pair of dd.
Spaces or newlines aren't required after an instruction, but that means they aren't ignored either. For example:

dddd dd
dd Example
d
d

Will output: dddddddd, because the fifth pair of Ds was divided by a newline.

dd

Instruction dd has many interesting properties. Firstly, it outputs the same characters needed to create itself. In other words: every dd program made out of entirely instructions dd will be a quine.

Because of that, you can think of a dd program not as source code for a computer to execute, but rather some order of characters that will be filtered to contain only dd. That would make dd a string-rewriting paradigm instead of an imperative language.

The second notable property, not really related to the instruction dd, is that every other character acts as a NOP, which makes this language a fine option for writing polyglot programs.

Computational class

The language's computational class is a finite-state automaton, because it can't reach an infinite amount of states without an infinite source code.

Examples

Print "dd"

Print dd.

Quine

dd

Polyglot iterating quine(2 languages), symmetrical program, and Rotary Quine

dd

Works in Text and dd.

Implementations

Javascript

var s=prompt();
var o="";
for(var i=0;i<=s.length;i++){
 if((s.charAt(i)=="d")&&(s.charAt(i+1)=="d")){
  o=o+"dd";i++;
 };
};
console.log(o);
Case sensitive? Does everything except "dd" cause an error? Newlines ignored?
Yes No No

Javascript one-liner

console.log(prompt().replace("ddd","dd.d").match(/dd/g).join(''));
Case sensitive? Does everything except "dd" cause an error? Newlines ignored?
Yes In special cases No

See also