///
/// is a minimalistic programming language. It has only two commands: "output character literal", and "replace the first occurrence of first string literal with second string literal in the remainder of the program, repeating until the first string literal does not appear in the program".
In both commands, a backslash denotes that the next character is taken literally. The replacement command is /first literal/second literal/
, and the output command is any character besides /
. So, for example, the program /lo\\c\k/\ake/che\ese\\clo\ck
first replaces every occurrence of lo\ck
with ake
(the \
s before the k
and the a
have no effect), resulting in che\ese\\cake
. Then the program executes the printing commands c
, h
, e
, \e
, s
, e
, \\
, c
, a
, k
, and e
, thereby printing cheese\cake
.
Needless to say, writing useful programs in /// is very difficult. The only way for a program to loop (besides using an infinite substitution like in /a/aa/a
) is for a part of the program to use substitutions to create a copy of itself later in the program. I've never figured out how to do this, but Ørjan Johansen has written a program which does this:
/|/<-\\\\>\\\\\\//QT/|/R|N|/Q|T|/|/<-|\|\>|/<-|\|\|\|\>|\|\|\|\|/|/<|\->|/|/C|T|/C|\T|/C|T|/|/*|\
|/I|\N|/|/I|\N|/**|\
|/|/Q|\T|/Q|T|/R|N//RN/QT//<-\\>/<-\\\\>\\\\//<\->///CT/*
//Q\T/QT/RN
How does this work? I'm not completely sure, but it's something like this.
The first replacement replaces |
(which is just syntactic sugar) with <-\\>\\\
. The second replacement replaces the string QT
with a quoted version of the second half of the program. In the second replacement command itself, most characters are preceded by <-\\>\\\
. The result is that in the string produced by the second replacement, most characters are preceded by <-\>\
.
The third replacement looks like it replaces RN
with QT
. But QT
has been replaced with a quoted version of the program, where most characters are preceded by <-\>\
. So this replacement actually replaces RN
with yet another quoted version of the second half of the program, in which most characters are preceded by <->
.
In the fourth replacement, each occurrence of <-\>
is restored back to <-\\>\\
. (I can't see where <-\>
actually occurs.) The fifth replacement deletes every occurrence of <->
, resulting in the quoted version of the second half of the program being completely restored to an unquoted state. The sixth replacement replaces CT
with *
—somehow this results in the program containing an ever increasing number of asterisks. The seventh replacement seems to do the same thing as the second replacement.
Finally, following all seven replacements is the string RN
, which is eventually replaced with a copy of the program, and everything starts over.
The end result is that the program outputs an infinite triangle of asterisks.
Details about all this can be found at the Esolang wiki page for ///.
function A
callsfunction B
andfunction B
callsfunction A
while 1 of the functions performs something. Since the function doesn't call itself it should be valid based on the criteria ^.^ \$\endgroup\$rep(f){f();f();}
- this is a statement (a function declaration is a statement in some languages) that allows executing code repeatedly. Is it disallowed. You ask for code to implement a loop. If that code is syntactically a statement, you have just disallowed it. Another example:f(b) { b(); g(b); }; g(b) { f(b); }
. I'd sayf
is a recursive function (by being mutually recursive withg
). Is it disallowed? \$\endgroup\$