Talk:///

I removed a /// from the bottles of beer program because in my intuition (and in my implementation, although it is simple to adopt that by testing for $s empty) it causes an infinite loop, because every program contains the empty string. Also I disagree that /bar/foobar/bar should print anything, since as I understand the specification, the replacement must be fully completed before a new command can be performed.

Another thing I wondered is whether ][ can be escaped by \ during the initial program transformation. I assumed not in the Perl program. --Ørjan 22:42, 26 May 2006 (UTC)
 * In my (unpublished) implementation, /bar/foobar/bar is also a nonprinting infinite loop, as is anything else with a self-replacement. It seems that trying to get a useful loop is like trying to program in Muriel; the problem is there is no quotify operation, so one has to be written.


 * The implementation and program correction is incorrect; there is no ]\n[ construct in the language. The very first replacement is actually /]\n[//, which removes all instances of ]\n[ in the rest of the program; it is the program itself that asks for ]\n[ removal. (There is nothing special about the ]\n[ sequence; if the program started /)\n(//, then )\n( could be used to remove newlines). I'm reverting that change accordingly. --ais523 10:50, 28 May 2006 (UTC)


 * (Sound of beating head) Doh! On the /bar/foobar/bar point, it should be possible to allow it to print by doing replacement lazily, which could easily be done in a Haskell implementation. This would also allow creating at least one loop in the program. --Ørjan 12:59, 28 May 2006 (UTC)

An ambiguity in the spec
The spec (assuming the article is the spec) does not state what should happen if the program begins with // followed at some point by another / - that is, the "source" is empty. The reference implementation is no help, because an empty pattern in perl evaluates to the last successfully matched pattern (last successful pattern in the perl source, that is) - which probably isn't what the spec author intended. I propose that the most reasonable behavior is for an empty source to match nothing. Here is a modified interpreter:


 * 1) !/usr/bin/perl -w

my $debug = ($#ARGV >= 0 and $ARGV[0] =~ m/^-d([1-2]?)$/ and shift and ($1 || 1)); $| = 1;

$_ = join '', <>; while (1) { print "\n[", $_, "]" if $debug == 1; if (s!^([^/\\]+)!! or s!^\\(.)!!s) { print($1); print "\n[", $_, "]" if $debug == 2; }       elsif (s!^/((?:[^/\\]|\\.)*)/((?:[^/\\]|\\.)*)/!!s) { my ($s,$d) = ($1,$2); next if $s eq ""; ###### add this line ###### $s =~ s/\\(.)/$1/gs; $d =~ s/\\(.)/$1/gs; while (s/\Q$s\E/$d/) { } }       else { last; } }

The spec also does not state what happens if the program begins with a /, but does not contain at least two subsequent (un-backslashed) /'s. Here the reference implementation does implement a reasonable behavior ... it terminates without printing anything. I suggest that this behavior also be stated explicitly in the spec.

--Nthern 19:01, 19 August 2010 (UTC)


 * Whoops - forget that last part; behavior is stated explicitly: "The program ends when there is no longer enough of it to execute" --Nthern 03:20, 20 August 2010 (UTC)


 * Hm, I've been assuming an empty initial pattern matches every boundary, and so is an immediate infinite loop - that's the mathematically obvious interpretation. However I never tested it (it's useless after all), and I didn't recall it was a special case in perl. --Ørjan 03:31, 20 August 2010 (UTC)


 * That works too (and may be more mathematically correct). Either way, the reference implementation should be fixed. To implement a deliberate infinite loop, one could change the added line to

while ($s eq "") { };
 * --Nthern 14:25, 20 August 2010 (UTC)

Clarifying the specs
Cons about precise specs is they are sometimes difficult to read. Especially the "...and the process repeats" at the end. I took the liberty to cut the specs in 3 phases: Source identification, Replacement identification and the Subtitution itself, to make it clear that the substition was restarting from the begining of the string after each substitution. ...That is, if my understanding is correct.

It is unclear from the specification whether backslashes are considered during the replacement phase. The reference interpreter does not consider backslashes during replacement. For example, the program '/f\oo/bar/foo' prints bar, while '/f\oo/bar/f\oo' prints foo (the pattern does not match f\oo). One could make a case for '/f\oo/bar/f\oo' printing bar as well. 24.16.138.191 16:55, 1 November 2015 (UTC)
 * In the program '/f\oo/bar/f\oo', the pattern string is "foo", while the remainder of the program is "f\oo"; since "f\oo" does not contain "foo", no replacement is performed. The pattern string is not "f\oo", and the string "f\oo" in the remainder of the program does not "represent" the string "foo" in any way, until it is actually executed. —Tanner Swett (talk) 17:24, 1 November 2015 (UTC)

Links to article
Apparently linking directly to /// has stopped working again. This applies to the mention in the main page and several others. --Ørjan (talk) 22:42, 8 September 2012 (UTC)
 * This never happened and you are imagining things. ehird (talk) 19:00, 11 December 2012 (UTC)
 * OKAY! --Ørjan (talk) 10:16, 12 December 2012 (UTC)

Even Faster Counter
I've made a program which should function as a counter, and for numbers 1-3 it seems faster than Ørjan's. However, for some reason it's really slow for anything beyond that. I waited at least an hour with the perl implementation, but it never printed 4.

///

I wonder what's going on :P --Challenger5 (talk) 01:49, 26 February 2017 (UTC)
 * *bonks Challenger5 on the head* --Ørjan (talk) 02:09, 26 February 2017 (UTC)