February 15, 2005
>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>      gr1 = $1
>>>>>>>      gr2 = $2
>>>>>>>      etc ...
>>>>>>Just off hand, suggesting this syntax for D scares the
>>>>>>living daylights out of me.

if file1line =~ /unquoted-regex-pattern-here/
mystring = $3 ~ "bla" ~ $5;
if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
	mystring ~= $9 ~ "xx" ~ $3;
else {
	if file2line =~ /unquoted-regex-pattern-here/
	mystring ~= $2 ~ $3 ~ " got out of hand!";
}
mystring ~= "\nAnd he never knew why.";
February 15, 2005
Rather,

if (file1line =~ /unquoted-regex-pattern-here/)
{
   mystring = $3 ~ "bla" ~ $5;

   if ($3 < $8 && $9 == $1 || $3 > $2 && $5 =< ($2 ~ foo)
      mystring ~= $9 ~ "xx" ~ $3;
   else
   {
      if (file2line =~ /unquoted-regex-pattern-here/)
         mystring ~= $2 ~ $3 ~ " got out of hand!";
   }
   mystring ~= "\nAnd he never knew why.";
}

I guess?  Yes, that is out of hand - but that's just bad use of the feature.  I could take arrays or classes or something and do the same thing to them :P.

-[Unknown]


>>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>>      gr1 = $1
>>>>>>>>      gr2 = $2
>>>>>>>>      etc ...
>>>>>>>
>>>>>>> Just off hand, suggesting this syntax for D scares the
>>>>>>> living daylights out of me.
> 
> 
> if file1line =~ /unquoted-regex-pattern-here/
> mystring = $3 ~ "bla" ~ $5;
> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>     mystring ~= $9 ~ "xx" ~ $3;
> else {
>     if file2line =~ /unquoted-regex-pattern-here/
>     mystring ~= $2 ~ $3 ~ " got out of hand!";
> }
> mystring ~= "\nAnd he never knew why.";
February 15, 2005
Is that supposed to be scary? It seems perfectly comprehensible to me. Or are you proving that it's not?

Confused ...

"Georg Wrede" <georg.wrede@nospam.org> wrote in message news:4211C3BE.3060402@nospam.org...
>>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>>      gr1 = $1
>>>>>>>>      gr2 = $2
>>>>>>>>      etc ...
>>>>>>>Just off hand, suggesting this syntax for D scares the living daylights out of me.
>
> if file1line =~ /unquoted-regex-pattern-here/
> mystring = $3 ~ "bla" ~ $5;
> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
> mystring ~= $9 ~ "xx" ~ $3;
> else {
> if file2line =~ /unquoted-regex-pattern-here/
> mystring ~= $2 ~ $3 ~ " got out of hand!";
> }
> mystring ~= "\nAnd he never knew why.";


February 15, 2005

Matthew wrote:
> Is that supposed to be scary? It seems perfectly comprehensible to me. Or are you proving that it's not?
> 
> Confused ...

What's the value of $1 after the code snippet?

> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:4211C3BE.3060402@nospam.org...
> 
>>>>>>>>> if line =~ /unquoted-regex-pattern-here/
>>>>>>>>>     gr1 = $1
>>>>>>>>>     gr2 = $2
>>>>>>>>>     etc ...
>>>>>>>>
>>>>>>>>Just off hand, suggesting this syntax for D scares the
>>>>>>>>living daylights out of me.
>>
>>if file1line =~ /unquoted-regex-pattern-here/
>>mystring = $3 ~ "bla" ~ $5;
>>if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>mystring ~= $9 ~ "xx" ~ $3;
>>else {
>>if file2line =~ /unquoted-regex-pattern-here/
>>mystring ~= $2 ~ $3 ~ " got out of hand!";
>>}
>>mystring ~= "\nAnd he never knew why."; 
> 
> 
> 
February 15, 2005
Georg Wrede wrote:
>>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>>      gr1 = $1
>>>>>>>>      gr2 = $2
>>>>>>>>      etc ...
>>>>>>>
>>>>>>> Just off hand, suggesting this syntax for D scares the
>>>>>>> living daylights out of me.
> 
> 
> if file1line =~ /unquoted-regex-pattern-here/
> mystring = $3 ~ "bla" ~ $5;
> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>     mystring ~= $9 ~ "xx" ~ $3;
> else {
>     if file2line =~ /unquoted-regex-pattern-here/
>     mystring ~= $2 ~ $3 ~ " got out of hand!";
> }
> mystring ~= "\nAnd he never knew why.";

Actually, it doesn't look all that bad.
February 15, 2005
"John Reimer" <brk_6502@yahoo.com> wrote in message news:cuth6l$165u$1@digitaldaemon.com...

>> if file1line =~ /unquoted-regex-pattern-here/
>> mystring = $3 ~ "bla" ~ $5;
>> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>     mystring ~= $9 ~ "xx" ~ $3;
>> else {
>>     if file2line =~ /unquoted-regex-pattern-here/
>>     mystring ~= $2 ~ $3 ~ " got out of hand!";
>> }
>> mystring ~= "\nAnd he never knew why.";
>
> Actually, it doesn't look all that bad.

Also, the alternative is to replace every $4 with Re[4], according to the original poster.  That would be just as "line-noisy."  I think the biggest issue with built-in string expressions is that you do approach that line-noise look which some people are repelled from: ~= /^Re$/


February 15, 2005

John Reimer wrote:
> Georg Wrede wrote:
> 
>>>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>>>      gr1 = $1
>>>>>>>>>      gr2 = $2
>>>>>>>>>      etc ...
>>>>>>>>
>>>>>>>>
>>>>>>>> Just off hand, suggesting this syntax for D scares the
>>>>>>>> living daylights out of me.
>>
>>
>>
>> if file1line =~ /unquoted-regex-pattern-here/
>> mystring = $3 ~ "bla" ~ $5;
>> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>     mystring ~= $9 ~ "xx" ~ $3;
>> else {
>>     if file2line =~ /unquoted-regex-pattern-here/
>>     mystring ~= $2 ~ $3 ~ " got out of hand!";
>> }
>> mystring ~= "\nAnd he never knew why.";
> 
> 
> Actually, it doesn't look all that bad.

Yeah, but there is one bug already in this code, made by
the "author" (i.e. me, writing the code). And there is
another that'll hit him the second he starts writing the
rest (of this imagined example).

My problem is that neither you, nor Matthew, noticed it.
So probably the average user, or the next guy won't either.

Thus, I'm not happy with the syntax.

---------

D can brag about being very easy to understand. Just browsing
someone's code gives you immediately an idea of what's
going on. But the above code takes a pencil and paper,
and peace and quiet, before one can figure it out.

I really see worms and anacondas taking over, if we
we unlock the door and let Larry Wall in.
February 15, 2005
Charlie Patterson wrote:
> "John Reimer" <brk_6502@yahoo.com> wrote in message news:cuth6l$165u$1@digitaldaemon.com...
> 
> 
>>>if file1line =~ /unquoted-regex-pattern-here/
>>>mystring = $3 ~ "bla" ~ $5;
>>>if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>>    mystring ~= $9 ~ "xx" ~ $3;
>>>else {
>>>    if file2line =~ /unquoted-regex-pattern-here/
>>>    mystring ~= $2 ~ $3 ~ " got out of hand!";
>>>}
>>>mystring ~= "\nAnd he never knew why.";
>>
>>Actually, it doesn't look all that bad.
> 
> 
> Also, the alternative is to replace every $4 with Re[4], according to the original poster.  That would be just as "line-noisy."  I think the biggest issue with built-in string expressions is that you do approach that line-noise look which some people are repelled from: ~= /^Re$/

How true. Additionally, in this example, we didn't even include
the regex itself! So the code is getting illegible overall.
February 15, 2005
In article <42125F89.2070109@nospam.org>, Georg Wrede says...
>
>
>
>John Reimer wrote:
>> Georg Wrede wrote:
>> 
>>>>>>>>>>  if line =~ /unquoted-regex-pattern-here/
>>>>>>>>>>      gr1 = $1
>>>>>>>>>>      gr2 = $2
>>>>>>>>>>      etc ...
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Just off hand, suggesting this syntax for D scares the living daylights out of me.
>>>
>>>
>>>
>>> if file1line =~ /unquoted-regex-pattern-here/
>>> mystring = $3 ~ "bla" ~ $5;
>>> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>>     mystring ~= $9 ~ "xx" ~ $3;
>>> else {
>>>     if file2line =~ /unquoted-regex-pattern-here/
>>>     mystring ~= $2 ~ $3 ~ " got out of hand!";
>>> }
>>> mystring ~= "\nAnd he never knew why.";
>> 
>> 
>> Actually, it doesn't look all that bad.
>
>Yeah, but there is one bug already in this code, made by
>the "author" (i.e. me, writing the code). And there is
>another that'll hit him the second he starts writing the
>rest (of this imagined example).
>
>My problem is that neither you, nor Matthew, noticed it.
>So probably the average user, or the next guy won't either.
>
>Thus, I'm not happy with the syntax.
>
>---------
>
>D can brag about being very easy to understand. Just browsing
>someone's code gives you immediately an idea of what's
>going on. But the above code takes a pencil and paper,
>and peace and quiet, before one can figure it out.
>
>I really see worms and anacondas taking over, if we
>we unlock the door and let Larry Wall in.


Yeah.

One major problem, as I see it, with this syntax is the anonymous nature of the $ references. I presume these are supposed to refer to numbered sub-patterns, yes?

From my perspective, this would be much better served using structs with <gasp> named members instead:

^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?
12            3  4          5       6  7        8 9

struct Uri_RFC2396
{
char[] uri,
protocol,
scheme,
resource,
authority,
path,
args,
query,
tail,
fragment;
}

If one could pass this off to the RegExp and have it filled in, then so much the better. One might make the struct a union if need be (with a char[][10]). One could also give the members really obtuse names if so desired (a, b, c, d, e, f ..), and end up with vague 3 letter abbreviations instead of 2

In addition to readability & maintainability, the primary benefit is via the lack of implicit global variables (or thread-locals), coupled with the privacy, utility, and speedy access of stack-based structures. Heck, you could place the struct on the heap if you needed to; or even make it a global if you feel lucky. The point is that you have a choice.

I sure hope D does not end up looking like, ahh, APL :-)


February 15, 2005
On Tue, 15 Feb 2005 13:39:16 +0200, Georg Wrede <georg.wrede@nospam.org> wrote:
> Matthew wrote:
>> Is that supposed to be scary? It seems perfectly comprehensible to me. Or are you proving that it's not?
>>  Confused ...
>
> What's the value of $1 after the code snippet?

So you're suggesting the problem is that $1 or r[0] may be replaced unintentionally in some cases... would this problem be obviated/solved if the r[] was returned explicitly i.e.

r = regex.parse(/unquoted-regex-pattern-here/);

I don't think so..

I suspect this problem is simply a problem with compex code, and while syntax may play a part in making it more or less likely, neither of these suggested syntax'es, to me, seems to make any difference in this respect.

>> "Georg Wrede" <georg.wrede@nospam.org> wrote in message news:4211C3BE.3060402@nospam.org...
>>
>>>>>>>>>> if line =~ /unquoted-regex-pattern-here/
>>>>>>>>>>     gr1 = $1
>>>>>>>>>>     gr2 = $2
>>>>>>>>>>     etc ...
>>>>>>>>>
>>>>>>>>> Just off hand, suggesting this syntax for D scares the
>>>>>>>>> living daylights out of me.
>>>
>>> if file1line =~ /unquoted-regex-pattern-here/
>>> mystring = $3 ~ "bla" ~ $5;
>>> if ($3<$8 && $9==$1 || $3>$2 && $5=<($2 ~ foo)
>>> mystring ~= $9 ~ "xx" ~ $3;
>>> else {
>>> if file2line =~ /unquoted-regex-pattern-here/
>>> mystring ~= $2 ~ $3 ~ " got out of hand!";
>>> }
>>> mystring ~= "\nAnd he never knew why.";

Regan