///
/// 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 ///.
1What is the definition of a loop? – CousinCocaine – 2014-07-09T12:44:47.897
The bash 'yes' command would do, right? – CousinCocaine – 2014-07-09T12:45:21.127
The definition of a loop for this question will be
A programming language statement which allows code to be repeatedly executed
– CailinP – 2014-07-09T12:46:42.540hmm.. shame you had to post this comment.. just noted something you didnt mention in the structures you cant use XD – Teun Pronk – 2014-07-09T12:48:27.747
I think it should be possible to copy over a lot of answers from this question.
– Martin Ender – 2014-07-09T12:51:46.783This might sound stupid but what is the exact definition of recursion? Is that just a function calling itself? – Teun Pronk – 2014-07-09T12:53:19.233
@user24925 How sneeky and crappy can the answer be? – Teun Pronk – 2014-07-09T13:00:34.373
1Would creating new functions with the same content and then repeatedly calling them be considered recursion? What about a program compiling a program then calling that program? – SBoss – 2014-07-09T13:11:47.303
1As the existing comments and answers demonstrate, it's not clear what is covered by the "etc." in the forbidden structures. – Peter Taylor – 2014-07-09T13:43:07.447
The question has been updated for a focus on creativity. The goal here is to be creative and learn tricks that other programming languages might have (like the 'yes' command in BASH). – CailinP – 2014-07-09T13:47:52.970
@TeunPronk I added a definition of recursion to the question. It's just your basic, function calling itself definition. – CailinP – 2014-07-09T14:16:58.690
27For those who want an easy trick, i can't be bothered posting it :P Just make 2 functions,
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 ^.^ – Teun Pronk – 2014-07-09T14:34:42.3832"Changed to popularity contest for a focus on creativity" Changing the question is cheating! – CousinCocaine – 2014-07-09T15:12:36.990
@CousinCocaine The question and its requirements were not changed, only the winning guidelines from code golf to popularity contest. – CailinP – 2014-07-09T15:35:19.730
2@CailinP a winning answer is not a winning answer anymore. That is changing the outcome by changing the question. – CousinCocaine – 2014-07-09T15:41:19.923
1For the people who are complaining that the question is unclear, what is unclear about it? – CailinP – 2014-07-09T18:21:25.653
1Do vectorized functions count as loops? Otherwise R has this with
apply
– shadowtalker – 2014-07-10T02:16:03.4374The definition of "recursion" isn't very useful. It would be better to disallow recursive functions, which are functions that refer to themselves, directly or indirectly. – lrn – 2014-07-10T05:59:36.347
3What is unclear is the "definitions" of loop constructor and recursion. Neither are very precise. Example:
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? – lrn – 2014-07-10T06:08:45.863What is unclear hasn't changed since my first comment: what is permitted and what is forbidden. And there's no reasonable way to fix it without posting all the permitted answers in the question, which rather defeats the object. – Peter Taylor – 2014-07-10T12:55:35.217
Please don't get hung up on what is and is not permitted. As stated above: No loops or goto, Functions cannot call themselves, Do whatever you want in the 'loop.'
If you want to implement something and the rules don't explicitly say no to it, go ahead and do it. Many answers have already bent the rules. – CailinP – 2014-07-10T13:02:33.500
1What about a clock? Such as
tty-clock -D
? Or is that too lame ;) – CousinCocaine – 2014-07-11T08:53:51.4173@CailinP, what I'm "hung up on" is that questions on the site should be on topic for the site: that means having a clear, objective specification, which this question does not. – Peter Taylor – 2014-07-11T10:20:18.343
1I don't think that this question has an answer. Even if you don't write and exact loop or recursion, it is hidden somewhere inside. – Michal – 2014-07-14T08:04:39.507
I'm too lazy to go through all the answers... is there a
crontab
solution yet? – CompuChip – 2014-07-14T19:56:59.710