Saturday, April 27, 2013

User defined pipe and redirection operators... a code tribute to (my annoying cousin) Warren's encouragement... :-)

Note:
  1. These "pipes" can be any type (including tagged unions), in essence you have "strong typed" pipes (compile time checked) ...  Perfect for a message passing system.
  2. The shell "&" can also be implemented.  Happily the "&" is trivial when implemented with Algol68's parallel clause...  
Hope you enjoy this "space-aged" code (a.k.a. 1960s code)... :-)

 File: Iterator_pipe_operators.a68

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);

File: Iterator_pipe_utilities.a68

 # Sample ''utilities'' PROCedure declarations #
PROC cat = ([]GENLINE argv)GENLINE:~;
PROC tee = ([]YIELDLINE args filter)FILTER:~;
PROC grep = (STRING pattern, []GENLINE argv)GENLINE:~;
PROC uniq = (GENLINE arg)GENLINE:~;
PROC sort = (GENLINE arg)GENLINE:~;
PROC head = (INT n, []GENLINE args)GENLINE:~;
PROC tail = (INT n, []GENLINE args)GENLINE:~;

File: Iterator_pipe_page.a68

# Sample ''pipe I/O'' OPerator declarations #
OP READ = (PAGEIN page)GENLINE:~;
OP WRITE = (PAGEOUT page)YIELDLINE: ~;
OP APPEND = (PAGEAPPEND page)YIELDLINE:~;

File: test_Iterator_pipe_page.a68

#!/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$
))

Output:

Pioneer:  Adriaan van Wijngaarden - Dutch pioneer; ARRA, ALGOL
Number of Algol pioneers: 6
Number of scientists: 15

Saturday, April 20, 2013

Have you ever wanted to test drive Algol68?... are ANY of the rumours true?

Have you ever coded in Algol68?... 

Or have you ever wanted to test drive Algol68?...

If so, download Linux's Algol68 Compiler, Interpreter & Runtime:
But wait... maybe you want to hack your first "Hello, world!" program and run it online NOW:
NJoy NevilleDNZ

Wednesday, April 3, 2013

Algol68 FAQ: re: What operators in C were modeled on similar operators in ALGOL 68?

The short answer is probably these C operators +=, -=, *=, /= * %= are from Algol68′s +:=, -:=, *:=, /:= & %:=.

c.f. usenet: Ada and C and Algol 68

BTW: The best quote about C’s ancestory comes from Dennis Ritchie himself:
“The scheme of type composition adopted by C owes considerable debt to Algol 68, although it did not, perhaps, emerge in a form that Algol’s adherents would approve of. The central notion I captured from Algol was a type structure based on atomic types (including structures), composed into arrays, pointers (references), and functions (procedures). Algol 68′s concept of unions and casts also had an influence that appeared later.” Apr 1993 c.f. Dennis Ritchie (April 1993). "The Development of the C Language" (PDF)

End of short answer…
——– 8>< - - - - - - - - cut here - - - - - - - -

But note that the /= and /:= are subtly different. Also C's %= is the same as Algol's %*:= operator.

Note also that the majority of C's operators came from Algol (+ – * / = ≠ etc ). However the “%” operator is notability different.
* Wikipedia: Monadic_operators
* Wikipedia: Dyadic_operators_with_associated_priorities

C has the “return” and “sizeof” operator, whereas Algol68 has syntax “EXIT” (or "□") and operator “UPB”  (or  "⌈") that achieve a similar function.

Algol 68 also has some related constants: “max int”, “max real”, “int width”, “real width” etc to determine sizes of things. These are not the same a C’s sizeof, but similar.

The most peculiar operators of C’s are /\ & \/, these come from Algol's ∧ & ∨ operators. These “C originals” were replaced by the current && and || operators. c.f. What _did_ the C operators /\ and \/ do?

Algol68 further allows operators to be define using non-ASCII characters:
               ×, ÷, ≤, ≥, ¬, ∨, ∧, , ↓, ↑, ⌊, ⌈, ⎩, ⎧ and ⊥;
And used the characters →, ○, □, ␣ and ¢ for other purposes. It is kind of like Algol68 was taking the liberty of using unicode some 20 years before Unicode characters were defined. {Earlier Algol60 used non-ASCII ⊂ and ≡}

* C's: int i = b ? a : b; /* pick maximum */
* A68′s: INT i := ( a > b | a | b );

c.f. Wikipedia: ?: - a ternary operator

The assignment “:=” looks like an operator, but in terms of “Algol68″ OPerators it isn’t. I believe they are called “Units associated with names” c.f. Array, Procedure, Dereference and coercion operations
(Or – if you are a language lawyer c.f. Algol 68 r1 report.html#52)

Similarly: Left assign, right assign and compare ( :=, =:, =) are also not "Algol68" Operators.

Pointers are not operators per se. There are a few “identity relations” associated with pointers: e.g. :=:, :/=:, IS & ISNT
c.f. Assignation and identity relations etc
(Or – if you are a language lawyer c.f. Algol 68 r1 report.html#5221)

Monday, April 1, 2013

Thinking about Go documentation - Language Specification through the years ... Algol68 then, then C89 & Go now. (From: Google Groups/golang-nuts, with links to original A68 & C89 specs&books as PDFs)

ALGOL 68 was the first (and possibly one of the last) major language for which a full formal definition was made before it was implemented.
C.H.A. Koster Algol68 Report co-editor, [7]
Sadly Koster was killed in a motorcycle accident last week. c.f. http://www.ru.nl/icis/news/memoriam-kees-koster

1960s was a time for Informaticians to blaze a path and the construction of the Algol68 Report was a very early example of collaborations that has left echos in how collaborations have been done ever since.  Aside from being the first as above, it was early IT days so the actual report may well have been the first in several other areas.  It was certainly pioneering.

For example:
  • "Translations of the standard were made for Russian, German, French and Bulgarian, and then later Japanese and Chinese.  The standard was also made available in Braille."
    • The report "invented" its own vocabulary as was mentioned above.  
      • My favourite is GOMMA, for a ";" meaning "Go on comma", i.e. sequentially (vs in parallel or collaterally)
    • Arguably this vocabulary aided in the documents translation, moreover served as a technical blue print for actual implementation in other countries on other disparate computer systems (6-bit, 7-bit, 8-bit chars, 16-bit, 24-bit, 36-bit CPUs etc.)
    • (Maybe) As a result there are at least 20 independently constructed Algo68 compilers, plus a few interesting dialects such as S3 & Mary.
  • IMHO the report was targeted at compiler implementers not end users. 
    • e.g. Algol68's description is not just a 4 page BNF description as it includes lots of language semantic rules, hence it is not just purely about syntax.  
    • {Iconically here the Algol68 Report breaks "Wadler's Law": http://www.haskell.org/haskellwiki/Wadlers_Law about semantics vs syntax.}
    • Moreover the alternative could have been be to "code" these semantics in "English", hope they survive linguistic translations, or implement them in a 3GL like C then wait 10+ years for a the formal "English" version to be drafted as a actual formal standard.
  • The "Data Security" requirement allowed detecting semantic errors at compile time.
    • Compile time detection is better then run time cure (such as type error exception handling while code is in production)
    • Most of these "Data Security" semantics are specifically detailed in the actual "Algol68 Report" and were a language requirement.
Regarding documentation, here are some links:
Some people prefer to learn a language by reading source code: Don't get me wrong, the Algol68 Report is hard to read, especially to non-compiler writers.
  • Compare with the first C standard
  • The Go Programming Language Specification, Version of September 4, 2012
    • http://golang.org/ref/spec 110 pages of A4 as at March 2013.
    • Clear and easy to read.
    • Some of "English" semantics
      • Fortunately(?) only one implementation of Go will ever need exist
    • Good syntax description, but not much in the way of "Formal Semantics",
Confession: I have not learned Go yet... I'm itching to give it a go as I like many of the ideas incorporated.

All the best and enjoy
NevilleDNZ