Slashes
From Esolang
- The title of this article is incorrect because of technical limitations. The correct title is ///.
/// is an esoteric language by User:Ihope127, based on the "s/foo/bar/" that everybody seemed to be doing. It has two symbols: delimiters (forward slashes) and escapes (backslashes). Other characters are allowed: see below.
To run a /// program, the first character is taken. If it's not / or \, it's printed. If it's a \, the character after it is printed and both characters are removed. If it's a /, characters are taken up to the next / (\ followed by a character means that character, not anything special the character normally means). These make up the "source." Characters are again read up to the next /, and again escaped characters are treated as themselves. These make up the "destination." Finally, if the rest of the program contains the source, the first occurrence of it is replaced with the destination. This is repeated until the program no longer contains the source.
Note that a destination which contains the source will cause an infinite loop: for example, /foo/foobar/foo will produce an infinite number of bars at the end of the program, but will leave the beginning undefined. A similar program is /bar/foobar/bar. Neither program ever prints anything since they will not finish the replacement of foo or bar, respectively.
Finally, the remainder of the program is run. The program ends when there is no longer enough of it to execute, e.g.:
\ /foo /foo/bar
A "Hello, world!" program and quine:
Hello, world!
A more elaborate "Hello, world!"
/ world! world!/Hello,/ world! world! world!
Here, the first occurence of " world! world!" is replaced with "Hello,", yielding "Hello, world!". This is then printed.
Even more elaborate, which demonstrates the "data used as code" idea:
/foo/Hello, world!//bar/foo/bar
First, foo is replaced with "Hello, world!", yielding /bar/Hello, world!/bar. This turns the bar into "Hello, world!" as well, which is then printed.
Finally, the "beer program":
/] [///#/ bottles of beer on the wall, //$/ bottles of beer Take one down, pass it around //%/ bottles of beer on the wall. /99#99$98%98#98$97%97#97$96%96#96$95%95#95$94%94#94$93%93] [#93$92%92#92$91%91#91$90%90#90$89%89#89$88%88#88$87%87#87] [$86%86#86$85%85#85$84%84#84$83%83#83$82%82#82$81%81#81$80] [%80#80$79%79#79$78%78#78$77%77#77$76%76#76$75%75#75$74%74] [#74$73%73#73$72%72#72$71%71#71$70%70#70$69%69#69$68%68#68] [$67%67#67$66%66#66$65%65#65$64%64#64$63%63#63$62%62#62$61] [%61#61$60%60#60$59%59#59$58%58#58$57%57#57$56%56#56$55%55] [#55$54%54#54$53%53#53$52%52#52$51%51#51$50%50#50$49%49#49] [$48%48#48$47%47#47$46%46#46$45%45#45$44%44#44$43%43#43$42] [%42#42$41%41#41$40%40#40$39%39#39$38%38#38$37%37#37$36%36] [#36$35%35#35$34%34#34$33%33#33$32%32#32$31%31#31$30%30#30] [$29%29#29$28%28#28$27%27#27$26%26#26$25%25#25$24%24#24$23] [%23#23$22%22#22$21%21#21$20%20#20$19%19#19$18%18#18$17%17] [#17$16%16#16$15%15#15$14%14#14$13%13#13$12%12#12$11%11#11] [$10%10#10$9%9#9$8%8#8$7%7#7$6%6#6$5%5#5$4%4#4$3%3#3$2%2#2] [$1 bottle of beer on the wall. 1 bottle of beer on the wall, 1 bottle of beer Take one down, pass it around No more bottles of beer on the wall.
Note the brackets: these are used to mark unnecessary ("comment") line breaks, and are removed at the beginning of the program. The brackets are not part of the language itself; they are removed by the very first replacement given in the program. The symbols #, $ and % make up a simple data compression scheme which shrinks most of the bulk from the program.
Since characters other than / and \ are used only for printing, they aren't necessary for writing programs. However, they make good comments as well as data representations, as long as you don't try to execute them. You may want to write code to strip the comments out.
[edit] Implementation
The below implementation is appropriately written in the Perl language, well-known for also supporting a /// construction.
#!/usr/bin/perl -w
my $debug = $#ARGV >= 0 and $ARGV[0] eq '-d' and shift;
$_ = join '', <>;
while (1) {
print "\n[", $_, "]" if $debug;
if (s!^([^/\\]+)!! or s!^\\(.)!!s) { print($1); }
elsif (s!^/((?:[^/\\]|\\.)*)/((?:[^/\\]|\\.)*)/!!s) {
my ($s,$d) = ($1,$2);
$s =~ s/\\(.)/$1/g;
$d =~ s/\\(.)/$1/g;
while (s/\Q$s\E/$d/) {}
}
else { last; }
}
[edit] See also
- Itflabtijtslwi - /// with input

