Discussion:
The joy of FORTRAN
(too old to reply)
Kerr-Mudd, John
2024-09-28 08:33:23 UTC
Permalink
On 27 Sep 2024 14:17:38 GMT
On 27 Sep 2024 at 11:10:37, The Natural Philosopher
On Thu, 26 Sep 2024 20:51:25 -0000 (UTC) Lawrence D'Oliveiro
One of the favourite functions in my library pulls the next token
from a delimited string, but as opposed to strtok() it does it
non-destructively and can handle empty strings.
print(item)
#end for
the quick brown fox
In Python, strings are objects, and that applies to string
expressions (including string literals) as well.
You need Rexx
NOBODY needs REGEX!
He said Rexx; very superior language, written by a Brit at IBM Hursley
45 years ago,
Was, maybe still is, the default language on IBM mainframes.
https://sourceforge.net/projects/oorexx/files/
https://sourceforge.net/projects/regina-rexx/
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
OK,OK. Cribbed & hacked from a stackoverflow answer:
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-separator


myline="the,quick,brown,fox"

do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end
w.0 = i-1

do i = 1 to w.0
say w.i
end


Hmm, must be a shorter way without the bother of setting up the stem
array.


xpost to comp.lang.rexx, if it still exists
--
Bah, and indeed Humbug.
Bob Eager
2024-09-28 09:41:59 UTC
Permalink
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
If you use space as a delimiter, which I would argue is more natural:

------------------------------------------
myline="the quick brown fox"

do i = 1 to words(myline)
say word(myline, i)
end
------------------------------------------
--
Using UNIX since v6 (1975)...

Use the BIG mirror service in the UK:
http://www.mirrorservice.org
Kerr-Mudd, John
2024-09-29 08:19:10 UTC
Permalink
On 28 Sep 2024 09:41:59 GMT
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end
------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
--
Bah, and indeed Humbug.
R Daneel Olivaw
2024-09-29 09:23:18 UTC
Permalink
Post by Kerr-Mudd, John
On 28 Sep 2024 09:41:59 GMT
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end
------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
What does "parse" do?
I just had a look at some REXX documentation but it was not particularly
helpful, it looked to me to be something which a couple of FORTRAN 77
function calls would have handled perfectly adequately.
Bob Eager
2024-09-29 10:18:47 UTC
Permalink
Post by R Daneel Olivaw
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end ------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
What does "parse" do?
I just had a look at some REXX documentation but it was not particularly
helpful, it looked to me to be something which a couple of FORTRAN 77
function calls would have handled perfectly adequately.
It essentially splits a string into substrings, using specified
delimiters. The source string may be from a variety of places (variable,
argument array, input line, stack) and there are some weird special cases
such as getting the version number.

Essentially, you specify a template and it splits the string in accordance
with that. For example:

parse var s1 "," s2 "-" s3
--
Using UNIX since v6 (1975)...

Use the BIG mirror service in the UK:
http://www.mirrorservice.org
R Daneel Olivaw
2024-09-29 14:47:47 UTC
Permalink
Post by Bob Eager
Post by R Daneel Olivaw
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end ------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
What does "parse" do?
I just had a look at some REXX documentation but it was not particularly
helpful, it looked to me to be something which a couple of FORTRAN 77
function calls would have handled perfectly adequately.
It essentially splits a string into substrings, using specified
delimiters. The source string may be from a variety of places (variable,
argument array, input line, stack) and there are some weird special cases
such as getting the version number.
Essentially, you specify a template and it splits the string in accordance
parse var s1 "," s2 "-" s3
Ok, similar to "unstring" in COBOL, although unstring is more flexible
and can tell you which separator was hit if more than one was permitted,
and probably how many characters were in each extracted substring.

Unstring had so many possibilities I don't think I ever tried them all.
Peter Flass
2024-09-29 20:15:04 UTC
Permalink
Post by R Daneel Olivaw
Post by Kerr-Mudd, John
On 28 Sep 2024 09:41:59 GMT
Post by Kerr-Mudd, John
Post by Kerr-Mudd, John
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-
separator
Post by Kerr-Mudd, John
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end
------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
What does "parse" do?
I just had a look at some REXX documentation but it was not particularly
helpful, it looked to me to be something which a couple of FORTRAN 77
function calls would have handled perfectly adequately.
What doesn’t it do? It breaks down a string according to a pattern, a lot
like SNOBOL (IIRC, my use of REXX now is limited to straightforward stuff)
--
Pete
Bob Eager
2024-09-29 10:10:14 UTC
Permalink
Post by Kerr-Mudd, John
Post by Bob Eager
Post by Kerr-Mudd, John
Hmm, must be a shorter way without the bother of setting up the stem
array.
------------------------------------------
myline="the quick brown fox"
do i = 1 to words(myline)
say word(myline, i)
end ------------------------------------------
Thanks; It's been yea^w decades since I used Rexx. And even then not
extensively. But Rexx has "Parse" which few(no?) other languages have.
The nearest I've seen is the string resolution in Edinburgh IMP. You can
give pretty well the same kind of pattern, with specified delimiters, and
it splits the string into variables.

For example:

s1 -> s2.(",").s3.("-").s4

The number of terms is limited only by temporary stack space. I once
parsed entries in a termcap database using this.

If the resolution fails, an event is signalled. But you can use the
resolution as a conditional expression to avoid that, and find out if it
failed that way.

http://www.ancientgeek.org.uk/EMAS/EMAS_Manuals/IMP/
The_IMP80_Language.pdf

(bottom of page 26 onwards)
--
Using UNIX since v6 (1975)...

Use the BIG mirror service in the UK:
http://www.mirrorservice.org
Lawrence D'Oliveiro
2024-09-29 23:37:40 UTC
Permalink
Post by Kerr-Mudd, John
But Rexx has "Parse" which few(no?) other languages have.
Given that Rexx example is so much more wordy than my Python original,
perhaps that should come as no surprise.
lar3ryca
2024-10-09 01:53:39 UTC
Permalink
Post by Kerr-Mudd, John
On 27 Sep 2024 14:17:38 GMT
On 27 Sep 2024 at 11:10:37, The Natural Philosopher
On Thu, 26 Sep 2024 20:51:25 -0000 (UTC) Lawrence D'Oliveiro
One of the favourite functions in my library pulls the next token
from a delimited string, but as opposed to strtok() it does it
non-destructively and can handle empty strings.
print(item)
#end for
the quick brown fox
In Python, strings are objects, and that applies to string
expressions (including string literals) as well.
You need Rexx
NOBODY needs REGEX!
He said Rexx; very superior language, written by a Brit at IBM Hursley
45 years ago,
Was, maybe still is, the default language on IBM mainframes.
https://sourceforge.net/projects/oorexx/files/
https://sourceforge.net/projects/regina-rexx/
I was too lazy to dig into my rusty brain to code the equivalent in Rexx,
I was hoping someone here would do it!
print(item)
#end for
https://stackoverflow.com/questions/15437494/rexx-parse-a-csv-line-separator
myline="the,quick,brown,fox"
do i = 1 by 1 while myline <> ''
parse var myline w.i ',' myline
end
w.0 = i-1
do i = 1 to w.0
say w.i
end
Hmm, must be a shorter way without the bother of setting up the stem
array.
But stem variables are SO much fun. Here's one I wrote many years ago
with ARexx, modified to run on Linux. It's better than uniq as the file
need not be pre-sorted

#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
Post by Kerr-Mudd, John
xpost to comp.lang.rexx, if it still exists
--
Computers follow your orders, not your intentions.
Lawrence D'Oliveiro
2024-10-09 05:46:15 UTC
Permalink
Post by lar3ryca
#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
#!/usr/bin/python3
# Show only one copy of each line in a whole file
import sys
seen = set()
for line in sys.stdin :
if not line in seen :
sys.stdout.write(line)
seen.add(line)
Peter Dean
2024-10-09 07:12:49 UTC
Permalink
Post by Lawrence D'Oliveiro
Post by lar3ryca
#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
#!/usr/bin/python3
# Show only one copy of each line in a whole file
import sys
seen = set()
sys.stdout.write(line)
seen.add(line)
#!/usr/bin/perl
my %seen;
while (<>) {
if (!$seen{$_}) {
$seen{$_}++;
print;
}
}
Kerr-Mudd, John
2024-10-09 08:27:10 UTC
Permalink
On Wed, 9 Oct 2024 07:12:49 -0000 (UTC)
Post by Peter Dean
Post by Lawrence D'Oliveiro
Post by lar3ryca
#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
#!/usr/bin/python3
# Show only one copy of each line in a whole file
import sys
seen = set()
sys.stdout.write(line)
seen.add(line)
#!/usr/bin/perl
my %seen;
while (<>) {
if (!$seen{$_}) {
$seen{$_}++;
print;
}
}
Perl wins! -much more obscu^w shorter
--
Bah, and indeed Humbug.
lar3ryca
2024-10-10 03:42:01 UTC
Permalink
Post by Kerr-Mudd, John
On Wed, 9 Oct 2024 07:12:49 -0000 (UTC)
Post by Peter Dean
Post by Lawrence D'Oliveiro
Post by lar3ryca
#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
#!/usr/bin/python3
# Show only one copy of each line in a whole file
import sys
seen = set()
sys.stdout.write(line)
seen.add(line)
#!/usr/bin/perl
my %seen;
while (<>) {
if (!$seen{$_}) {
$seen{$_}++;
print;
}
}
Perl wins! -much more obscu^w shorter
Good to know that other languages can do it, even if _I_ can't wrap my
head around them.
--
Private signature.
Do not read.
Peter Dean
2024-10-10 04:39:02 UTC
Permalink
Post by lar3ryca
Post by Kerr-Mudd, John
On Wed, 9 Oct 2024 07:12:49 -0000 (UTC)
Post by Peter Dean
Post by Lawrence D'Oliveiro
Post by lar3ryca
#!/usr/bin/rexx
/* Show only one copy of each line in a whole file */
seen. = 0
Do While Lines() > 0
Parse Pull this_line
If seen.this_line Then Iterate
seen.this_line = 1
Say this_line
end
#!/usr/bin/python3
# Show only one copy of each line in a whole file
import sys
seen = set()
sys.stdout.write(line)
seen.add(line)
#!/usr/bin/perl
my %seen;
while (<>) {
if (!$seen{$_}) {
$seen{$_}++;
print;
}
}
Perl wins! -much more obscu^w shorter
Good to know that other languages can do it, even if _I_ can't wrap my
head around them.
and that was just a direct translation. This is more idiomatic perl.

#!/usr/bin/perl
while (<>) {
print unless $seen{$_}++;
}

Loading...