From: Ben Bacarisse on
James Dow Allen <jdallen2000(a)yahoo.com> writes:

> On Nov 6, 1:36 am, Ben Pfaff <b...(a)cs.stanford.edu> wrote:
>> I looked around the web for a while and found a few superficial
>> descriptions of SNOBOL patterns....
>>
>> Can you give a few examples?
>
> Another nice feature of the SNOBOL programming language
> is that the string matching a subpattern can be saved in
> a variable. IIRC,
> A B.X C

You recall the operator correctly but, unless it is my turn to
misremember, SNOBOL is very fussy about spaces and you must write:

A B . X C

> is the same as
> A B C
> but the string matching the subpattern B is saved in X.

In case anyone is puzzled, SNOBOL has 2 of these assignment
operators. The . assigns on a successful match and $ (that I
illustrated elsewhere) does so, repeatedly, during the match.

> I've often wanted to use this feature when sed'ing, e.g.
> sed "sqhas [0-9]* wivesqwill have N happy widowsq"
> where "N" is the matching [0-9]* remembered.

Which, of course, you can do. Using a name is nicer, but \1 does the
job. In SNOBOL, you use pretty much anything as the replacement:

LINE SPAN('0123456789') . N = N + 1

increments the first number found in the variable LINE.

--
Ben.
From: Christian Gollwitzer on
James Dow Allen schrieb:
> I've often wanted to use this feature when sed'ing, e.g.
> sed "sqhas [0-9]* wivesqwill have N happy widowsq"
> where "N" is the matching [0-9]* remembered.

Use backreferences:

$ sed 'sqhas \([0-9]*\) wivesqwill have \1 happy widowsq'
has 9 wives
will have 9 happy widows
has 4 wives
will have 4 happy widows

Christian


From: Ben Pfaff on
Ben Bacarisse <ben.usenet(a)bsb.me.uk> writes:

> Ben Pfaff <blp(a)cs.stanford.edu> writes:
>> I looked around the web for a while and found a few superficial
>> descriptions of SNOBOL patterns. I also found a few SNOBOL
>> reference manuals, but again their descriptions of patterns were
>> very brief and I found it difficult to figure out how they were
>> used and why exactly they were so powerful.
>>
>> Can you give a few examples?
>
> The main feature is that patterns are built from pattern primitives
> using operators. Patterns are named so you can write:

Thank you for the examples.
--
"Long noun chains don't automatically imply security."
--Bruce Schneier
From: James Dow Allen on
On Nov 6, 10:24 pm, Christian Gollwitzer <Christian.Gollwit...(a)uni-
bayreuth.de> wrote:
> James Dow Allen schrieb:
>
> > I've often wanted to use this feature when sed'ing, e.g.
> >    sed "sqhas [0-9]* wivesqwill have N happy widowsq"
> > where "N" is the matching [0-9]* remembered.
>
> Use backreferences:
>
> $ sed 'sqhas \([0-9]*\) wivesqwill have \1 happy widowsq'
> has 9 wives
> will have 9 happy widows
> has 4 wives
> will have 4 happy widows
>
>         Christian

Thanks! I had a hunch sed had such a facility and thought it easier
to ask here than read the man. :-)

Odd that I remembered a feature (forgetting the spaces) of a language
(SNOBOL) which I've not used for *40 years* ... yet can't remember
what I had for breakfast yesterday.

James