Range extraction: Difference between revisions

Content added Content deleted
(→‎{{header|Go}}: language change. built in error type.)
Line 1,140: Line 1,140:


=={{header|PL/I}}==
=={{header|PL/I}}==
{{incorrect|PL/I|Ranges must cover >2 integers.}}
<lang PL/I>
<lang PL/I>
/* Modified 19 November 2011 to meet new requirement that there be */
range_extraction:
/* at least 3 items in a run. */
range_extraction: /* 17 August 2010 */
procedure options (main);
procedure options (main);
declare c character (1);
declare (c, d) character (1);
declare (old, new, initial) fixed binary (31);
declare (old, new, initial) fixed binary (31);
declare in file;
declare out file output;
declare out file output;
open file (out) output title ('/out,type(text),recsize(70)');


open file (in) title ('/range2.dat,type(text),recsize(80)' );
c = ' ';
open file (out) output title ('/range2.out,type(text),recsize(70)');
get list (old);

c = ' '; d = ',';
get file (in) list (old);
do forever;
do forever;
initial = old;
initial = old;
on endfile (sysin) begin;
on endfile (in) begin;
put file (out) edit (c, trim(old)) (a);
put file (out) edit (c, trim(old)) (a);
stop;
stop;
end;
end;
get (new);
get file (in) list (new);
put edit (c) (a);
if new = old+1 then
if new = old+1 then
do; /* we have a run. */
do; /* we have a run. */
on endfile (sysin) begin;
on endfile (in) begin;
put file (out) edit (c, trim(initial), '-', trim(old) ) (a);
if old > initial+1 then d = '-';
put file (out) edit (c, trim(initial), d, trim(old) ) (a);
stop;
stop;
end;
end;
do while (new = old+1);
do while (new = old+1);
old = new;
old = new;
get (new);
get file (in) list (new);
end;
end;
/* At this point, old holds the last in a run; */
/* At this point, old holds the last in a run; */
/* initial holds the first in a run. */
/* initial holds the first in a run. */
put file (out) edit (c, trim(initial), '-', trim(old) ) (a);
/* if there are only two members in a run, don't use the */
/* range notation. */
if old > initial+1 then d = '-';
put file (out) edit (c, trim(initial), d, trim(old) ) (a);
old = new;
old = new;
end;
end;
Line 1,179: Line 1,186:
old = new;
old = new;
end;
end;
c = ',';
c, d = ',';
end;
end;
end range_extraction;
end range_extraction;
</lang>
</lang>
OUTPUT:
OUTPUT 17/8/2010:
<lang>
<lang>
0-2,4,6-8,11-12,14-25,27-33,35-39
0-2,4,6-8,11-12,14-25,27-33,35-39
</lang>
OUTPUT 19/11/2011:
<lang>
0-2,4,6-8,11,12,14-25,27-33,35-39
</lang>
</lang>