Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Assignable reg exps in GAWK?

35 views
Skip to first unread message

Kenny McCormack

unread,
Oct 14, 2016, 1:44:14 PM10/14/16
to
I am 99% certain that I saw this as a recent addition to GAWK.

That is, that you could do something like:

re = @/foo/

and re could then be used later like:

if ($0 ~ re)

I.e., that re would be treated as a reg exp object, not just a string.

But the above syntax gives a syntax error, and I cannot find it anywhere in
the documentation. Please help.

P.S. Note the similarity between this syntax and the indirect function
call syntax - they both use the @ character.

--

"If God wanted us to believe in him, he'd exist."

(Linda Smith on "10 Funniest Londoners", TimeOut, 23rd June, 2005.)

Kaz Kylheku

unread,
Oct 14, 2016, 2:30:54 PM10/14/16
to
On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> I am 99% certain that I saw this as a recent addition to GAWK.
>
> That is, that you could do something like:
>
> re = @/foo/

If you have intuition for programming language design, it
immediately strikes you that quoting a regex literal just
to make it an object is ridiculous; it ought to be
unnecessary.

There is no difference between what the quoted and unquoted
syntax denotes.

The following works in gawk 3.1.8:
$ gawk '{ re = /abc/ } re'
1
2
abc
abc

It appears as if the regex abc is assigned into re, and then the
expression re is sufficient as a pattern for matching records
containing abc.

Hermann Peifer

unread,
Oct 14, 2016, 2:31:49 PM10/14/16
to
On 2016-10-14 19:44, Kenny McCormack wrote:
> I am 99% certain that I saw this as a recent addition to GAWK.
>
> That is, that you could do something like:
>
> re = @/foo/
>
> and re could then be used later like:
>
> if ($0 ~ re)
>
> I.e., that re would be treated as a reg exp object, not just a string.
>

Typed regular expressions are gone, for the time being:
http://git.savannah.gnu.org/cgit/gawk.git/tree/ChangeLog#n166

Hermann

Kenny McCormack

unread,
Oct 14, 2016, 3:04:51 PM10/14/16
to
In article <20161014...@kylheku.com>,
Kaz Kylheku <221-50...@kylheku.com> wrote:
>On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>> I am 99% certain that I saw this as a recent addition to GAWK.
>>
>> That is, that you could do something like:
>>
>> re = @/foo/
>
>If you have intuition for programming language design, it
>immediately strikes you that quoting a regex literal just
>to make it an object is ridiculous; it ought to be
>unnecessary.

Kaz, usually your responses are logical and useful.

This time, however, I have no idea what you're on about.
Was this post intended to be at all useful or are you just flaming?

--
Debating creationists on the topic of evolution is rather like trying to
play chess with a pigeon --- it knocks the pieces over, craps on the
board, and flies back to its flock to claim victory.

Kenny McCormack

unread,
Oct 14, 2016, 3:06:05 PM10/14/16
to
In article <ntr8ak$e09$1...@news.albasani.net>,
I see. I assume that the phrase "typed regular expressions" is the GAWK
buzzword for what I'm talking about. Is that correct?

I just want to make sure we're all talking about the same thing.

P.S. Do you know what was wrong with them?

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain in
compliance with said RFCs, the actual sig can be found at the following web address:
http://www.xmission.com/~gazelle/Sigs/Snicker

Kaz Kylheku

unread,
Oct 14, 2016, 3:41:14 PM10/14/16
to
On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <20161014...@kylheku.com>,
> Kaz Kylheku <221-50...@kylheku.com> wrote:
>>On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>>> I am 99% certain that I saw this as a recent addition to GAWK.
>>>
>>> That is, that you could do something like:
>>>
>>> re = @/foo/
>>
>>If you have intuition for programming language design, it
>>immediately strikes you that quoting a regex literal just
>>to make it an object is ridiculous; it ought to be
>>unnecessary.
>
> Kaz, usually your responses are logical and useful.
>
> This time, however, I have no idea what you're on about.
> Was this post intended to be at all useful or are you just flaming?

Sorry; I got confused by a missing BEGIN in the code! Ha!

re = /abc/

of course stores, in re, the Boolean result of testing /abc/ against the
record.

Kenny McCormack

unread,
Oct 14, 2016, 3:53:09 PM10/14/16
to
In article <201610141...@kylheku.com>,
Right. That's basic AWK 101 - and also GAWK 101.

That's why the @ is in there. To tell it that this is a reg exp object to
be parsed and stored for later use - not an immediate comparison against $0.

But Herman tells us that this feature is gone now. Too bad...

I just tested with 4.1, 4.3, and 4.4 - all still get syntax error.
It'd be nice to know which versions did have it...

--
"I have a simple philosophy. Fill what's empty. Empty what's full. And
scratch where it itches."

Alice Roosevelt Longworth

Kaz Kylheku

unread,
Oct 14, 2016, 4:04:24 PM10/14/16
to
On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <201610141...@kylheku.com>,
> Kaz Kylheku <221-50...@kylheku.com> wrote:
>>On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>>> In article <20161014...@kylheku.com>,
>>> Kaz Kylheku <221-50...@kylheku.com> wrote:
>>>>On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
>>>>> I am 99% certain that I saw this as a recent addition to GAWK.
>>>>>
>>>>> That is, that you could do something like:
>>>>>
>>>>> re = @/foo/
>>>>
>>>>If you have intuition for programming language design, it
>>>>immediately strikes you that quoting a regex literal just
>>>>to make it an object is ridiculous; it ought to be
>>>>unnecessary.
>>>
>>> Kaz, usually your responses are logical and useful.
>>>
>>> This time, however, I have no idea what you're on about.
>>> Was this post intended to be at all useful or are you just flaming?
>>
>>Sorry; I got confused by a missing BEGIN in the code! Ha!
>>
>> re = /abc/
>>
>>of course stores, in re, the Boolean result of testing /abc/ against the
>>record.
>
> Right. That's basic AWK 101 - and also GAWK 101.

Yes; /RE/ is not a literal or value, but syntax denoting an operation
which produces a Boolean result.

By the way, given @/RE/, there is no need to call it a "strongly typed"
anything; just a regex literal. Given "STR", that isn't called a
"strongly typed string literal", right?

In principle, this could be supported: @/1.2/ + 3 yields 3.2.
There goes your "strongly typed". Yet, regex wise, it works as before.

> That's why the @ is in there. To tell it that this is a reg exp object to
> be parsed and stored for later use - not an immediate comparison against $0.

I just verified that the very last commit before that aforementioned
one elsewhere in the thread supports this:

$ ./gawk 'BEGIN { re = @/abc/ } $0 ~ re'
1
2
abc
abc
3
4

AFter that commit, it's a syntax error.

Very poor way to treat users.

Given that the @ isn't valid POSIX syntax, why remove it?

Whatever is conceptually wrong with @/RE/, it's hard to justify
replacing working use cases of it with an syntax error in your face!

Kaz Kylheku

unread,
Oct 14, 2016, 4:14:19 PM10/14/16
to
On 2016-10-14, Kenny McCormack <gaz...@shell.xmission.com> wrote:
> In article <201610141...@kylheku.com>,
> Kaz Kylheku <221-50...@kylheku.com> wrote:
>>Sorry; I got confused by a missing BEGIN in the code! Ha!
>>
>> re = /abc/
>>
>>of course stores, in re, the Boolean result of testing /abc/ against the
>>record.
>
> Right. That's basic AWK 101 - and also GAWK 101.

By the way, the Democrats obviously rigged that to make me look stupid.

Andrew Schorr

unread,
Oct 14, 2016, 7:20:01 PM10/14/16
to
On Friday, October 14, 2016 at 3:06:05 PM UTC-4, Kenny McCormack wrote:
> I see. I assume that the phrase "typed regular expressions" is the GAWK
> buzzword for what I'm talking about. Is that correct?

Yes.

> P.S. Do you know what was wrong with them?

The idea was conceptually good, but there were bugs in the implementation. It was withdrawn until somebody has the time to take another whack at it.

Regards,
Andy



0 new messages