User defined pipe and redirection operators: Difference between revisions
Content added Content deleted
m (misc desc tidy) |
(→[[User defined pipe and redirection operators#ALGOL 68]]: retain only the user defined pipe with redirection operators and terst case.) |
||
Line 85: | Line 85: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
See [[User defined pipe and redirection operators/ALGOL 68]] |
See [[User defined pipe and redirection operators/ALGOL 68]] |
||
{{works with|ALGOL 68|Revision 1; one minor extension - PRAGMA READ; one major extension - Algol68G's [[wp:Currying|Currying]].}}{{works with|ALGOL 68G|tested with release [http://sourceforge.net/projects/algol68/files/algol68g/algol68g-1.18.0/algol68g-1.18.0-9h.tiny.el5.centos.fc11.i386.rpm/download 1.18.0-9h.tiny].}} |
|||
{{wont work with|ELLA ALGOL 68|Any (with appropriate job cards) - tested with release [http://sourceforge.net/projects/algol68/files/algol68toc/algol68toc-1.8.8d/algol68toc-1.8-8d.fc9.i386.rpm/download 1.8-8d] - due to extensive use of '''format'''[ted] ''transput''.}} |
|||
'''File: Iterator_pipe_operators.a68''' |
|||
<lang algol68>MODE |
|||
PAGEIN = PAGE, |
|||
PAGEAPPEND = REF PAGE, |
|||
PAGEOUT = REF PAGE; |
|||
MODE |
|||
MOID = VOID, |
|||
YIELDLINE = PROC(LINE)VOID, |
|||
GENLINE = PROC(YIELDLINE)VOID, |
|||
FILTER = PROC(GENLINE)GENLINE, # the classic shell filter # |
|||
MANYTOONE = PROC([]GENLINE)GENLINE; # eg cat, as in con[cat]enate # |
|||
PRIO =: = 5, << = 5, >> = 5; |
|||
OP < = (FILTER filter, PAGEIN page)GENLINE: filter(READ page), |
|||
< = (MANYTOONE cmd, PAGEIN page)GENLINE: cmd(READ page), |
|||
<< = (FILTER filter, PAGEIN page)GENLINE: filter(READ page), |
|||
> = (GENLINE gen, PAGEOUT page)VOID: gen(WRITE page), |
|||
>> = (GENLINE gen, PAGEAPPEND page)VOID: gen(APPEND page), |
|||
=: = (GENLINE gen, FILTER filter)GENLINE: filter(gen), |
|||
=: = (GENLINE gen, MANYTOONE cmd)GENLINE: cmd(gen);</lang>'''File: Iterator_pipe_utilities.a68''' |
|||
* See [[User defined pipe and redirection operators/ALGOL 68]] |
|||
'''File: Iterator_pipe_page.a68''' |
|||
* See [[User defined pipe and redirection operators/ALGOL 68]] |
|||
'''File: test_Iterator_pipe_page.a68''' |
|||
<lang algol68>#!/usr/local/bin/a68g --script # |
|||
# First define what kind of record (aka LINE) we are piping and filtering # |
|||
FORMAT line fmt = $xg$; |
|||
MODE |
|||
LINE = STRING, |
|||
PAGE = FLEX[0]LINE, |
|||
BOOK = FLEX[0]PAGE; |
|||
PR READ "Iterator_pipe_page.a68" PR |
|||
PR READ "Iterator_pipe_operators.a68" PR |
|||
PR READ "Iterator_pipe_utilities.a68" PR |
|||
PAGE list of computer scientists = ( |
|||
"Wil van der Aalst - business process management, process mining, Petri nets", |
|||
"Hal Abelson - intersection of computing and teaching", |
|||
"Serge Abiteboul - database theory", |
|||
"Samson Abramsky - game semantics", |
|||
"Leonard Adleman - RSA, DNA computing", |
|||
"Manindra Agrawal - polynomial-time primality testing", |
|||
"Luis von Ahn - human-based computation", |
|||
"Alfred Aho - compilers book, the 'a' in AWK", |
|||
"Stephen R. Bourne - Bourne shell, portable ALGOL 68C compiler", |
|||
"Kees Koster - ALGOL 68", |
|||
"Lambert Meertens - ALGOL 68, ABC (programming language)", |
|||
"Peter Naur - BNF, ALGOL 60", |
|||
"Guido van Rossum - Python (programming language)", |
|||
"Adriaan van Wijngaarden - Dutch pioneer; ARRA, ALGOL", |
|||
"Dennis E. Wisnosky - Integrated Computer-Aided Manufacturing (ICAM), IDEF", |
|||
"Stephen Wolfram - Mathematica", |
|||
"William Wulf - compilers", |
|||
"Edward Yourdon - Structured Systems Analysis and Design Method", |
|||
"Lotfi Zadeh - fuzzy logic", |
|||
"Arif Zaman - Pseudo-random number generator", |
|||
"Albert Zomaya - Australian pioneer of scheduling in parallel and distributed systems", |
|||
"Konrad Zuse - German pioneer of hardware and software" |
|||
); |
|||
PAGE algol pioneers list, the scientists list; |
|||
PAGE aa; |
|||
# Now do a bit of plumbing: # |
|||
cat(( |
|||
head(4, ) < list of computer scientists, |
|||
cat(READ list of computer scientists) =: grep("ALGOL", ) =: tee(WRITE algol pioneers list), |
|||
tail(4, READ list of computer scientists) |
|||
)) =: sort =: uniq =: tee(WRITE the scientists list) =: grep("aa", ) >> aa; |
|||
# Finally check the result: # |
|||
printf(( |
|||
$"Pioneer: "$, line fmt, aa, $l$, |
|||
$"Number of Algol pioneers: "g(-0)$, UPB algol pioneers list, $l$, |
|||
$"Number of scientists: "g(-0)$, UPB the scientists list, $l$ |
|||
))</lang> |
|||
'''Output:''' |
|||
<pre> |
|||
Pioneer: Adriaan van Wijngaarden - Dutch pioneer; ARRA, ALGOL |
|||
Number of Algol pioneers: 6 |
|||
Number of scientists: 15 |
|||
</pre> |
|||
=={{header|J}}== |
=={{header|J}}== |