Subject : Re: Coroutines and Go

: From : David Given <dg@...>

: David Given <dg@...> Date: Thu, 12 Nov 2009 16:21:39 +0000

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 steve donovan wrote: [...] > +1, that's good! New languages are fun, but often they're 'one trick > ponies' (like Snobol in the 60s was very good at string matching, but > it lost its niche eventually) [Warning: this message is almost entirely off topic.] There is nothing new under the sun. Have you seen Algol 68? As you might imagine, it's an Algol variant that came out in 1968. (Which makes it older than I am.) It begat Pascal, Modula, Oberon etc and is a cousin of C. (I think it's Lua's uncle.) There's a good Wikipedia page: http://en.wikipedia.org/wiki/ALGOL_68 It's a bit scary. It looks *just like a modern programming language*. It's got C-like types (although to be more accurate, C has Algol-68-like types). It's got user defined polymorphic perators (with user defined precedence). Keywords and identifiers occupy different namespaces. Identifiers can contain spaces! It's got block expressions. It's got OCCAM-like concurrency (there's a par keyword for running processes in parallel and built-in support for namespaces). You can use values before you define them! Most syntax elements have a short form and a long form, where the short form is designed for single statements and the long form for multiline statements. Example: # create a new type, 'vector', of an array of reals indexed 1..3 # mode vector = [1:3] real; # now create a matrix type similarly # mode matrix = [1:3, 1:3] real; # create some vectors # vector v1 := (1, 2, 3); vector v2 := (2, 3, 4); # create an operator that works on vectors # op + = (vector a, b) vector: begin vector out; for i from lwb a to upb a do out[i] := a[i] + b[i]; od; out # value of last expression in block is value of block # end # define a matrix from our vectors matrix m := (v1, v2, v1+v2); # get a reference to one of the rows of the matrix ref vector horizontal = m[2,]; # get a reference to one of the columns of the matrix ref vector vertical = m[,2]; There are a few features I haven't seen anywhere else, such as the universal loop construct which replaces both for...next and while...end, which I've never seen anywhere else: # loop in 'for' mode for i from 1 to 10 do print(i) od # ...and in 'while' mode while i < 10 do print(i); i := i + 1; od # ...and in both! for i from 1 to 10 while checkWhetherCancelled() do print(i) od # ...just loop, no counter! to 10 do print("Ten times!") od # ...minimum syntax do print("Loop forever") od # ...maximum syntax for i from 1 by 1 to 10 while checkWhetherCancelled() do print(i) od Algol-68 has some particularly interesting pointer semantics, nicer than C's IMO. This: int i; ...is actually sugar for: ref int i = loc int; 'loc int' is an expression that returns a new integer stored on the stack. (You can also say 'heap int' to create a new integer stored on the heap.) 'ref int' creates a pointer to an int. In other words, all variables are actually pointers. Unlike C, Algol-68 has distinct operations that work on the pointer and operations that work on the value; most operators will implicitly dereference their operands. If you want to, say, compare two references to see whether they're pointing at the same thing, there is a specific 'a is b' operator for doing so. Personally I think this is much more consistent and less ugly than C (and Go's) approach, where you have to know whether you're dealing with a pointer or a scalar before you can deal with it; but for some reason it's not a concept that seems to have taken off. ... So, to get back to the point: Go vs Algol-68. TBH, I think the 41-year-old language is richer, clearer and more expressive. It's certainly missing some features, like any form of object orientation, polymorphic functions, but the overall design is much more consistent and well thought-out. In 1968 Neil Armstrong was still pootling about in orbit and integrated circuits were rockets science. Why am I able to compare a language from this era with a contemporary one on an equal basis? Because, depressingly, state-of-the-art in programming languages hasn't moved much in those 41 years. I think that it's entirely plausible that if someone were to take the Algol-68 spec, redraft it in modern terminology (types instead of modes, names instead of variables, etc), update some of the odder areas such as transput, give it a catchy Web-2.0 name and produce a decent compiler for it, then it would be heralded as the next great development in programming languages. Which is kind of depressing... - -- ┌─── ｄｇ＠ｃｏｗｌａｒｋ．ｃｏｍ ───── http://www.cowlark.com ───── │ "There is nothing in the world so dangerous --- and I mean *nothing* │ --- as a children's story that happens to be true." --- Master Li Kao, │ _The Bridge of Birds_ -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iEYEARECAAYFAkr8NhEACgkQf9E0noFvlzjT7wCeJ6tM6FcNlpMBx9RZOZ+ncWkO gxIAoN2sYYXwo/IkcFefMs+rg1/Rfvrz =cdpP -----END PGP SIGNATURE-----