[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutines and Go
- From: David Given <dg@...>
- Date: Fri, 13 Nov 2009 16:17:11 +0000
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Mark Hamburg wrote:
[...]
> On the other hand, it's probably better formatted as:
>
> func( p* ByteSlice ) Write( data[] byte )( n int, err os.Error )
Go's * type modifier binds to the type, not the variable name, so:
var i, j *int;
...actually defines two pointers.
[...]
> I'm still finding Write to feel lost in that notation, however.
Algol-68 doesn't have methods or return parameters, so the above would
probably have to be written using pass-by-reference paramteres as:
PROC Write = (REF []BYTE p, []BYTE data, REF INT n, REF OSError err):
BEGIN
~
END
Putting the [] before the type looks weird to my C-trained eyes, but I
quite like the way the 'Write' is brought out to be the first
non-keyword on the line. I also like Algol-68's implicit slice
functionality --- Go's explicit differentiation between arrays and
slices seems like a big step backwards, IMO.
(In fact, a more Algol-68ish way of representing the append operation
would be:
PROC append = (REF FLEX []BYTE buffer, []BYTE data) VOID:
FOR i FROM LWB data TO UPB data DO
buffer[UPB buffer + 1] := data[i]
OD;
FLEX arrays automatically resize themselves... and does that inside of
the loop look familiar? Particularly if you realise that you can rewrite
it as:
buffer[⌈buffer + 1] := data[i]
Lua, of course, doesn't have explicit typing, but one obvious syntax
extension for types would be:
function append(buffer: ByteArray, data: const ByteArray): void
But that's simply because it's convenient to put an optional : after
each parameter.
- --
┌─── dg@cowlark.com ───── 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
iEYEARECAAYFAkr9hoQACgkQf9E0noFvlzjjRwCfU3rnCzZz6SUbww/6NeRCgv+I
/nMAmwU1M5DU1R0IvkOhBJGpPwWpq7l9
=c31g
-----END PGP SIGNATURE-----