9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] Re: advantages of limbo
Date: Tue,  2 Mar 2004 15:04:25 +0000	[thread overview]
Message-ID: <bb080f48852e81778453f33543dac9c4@vitanuova.com> (raw)
In-Reply-To: <200403020756.i227uE08071388@adat.davidashen.net>

> Yet [Java] is more powerful in expressing algorithms. Things like closures
> or message polymorphism are natural and easy to express in Java, while
> either not possible or inconvenient in limbo.

re: closures: cheap and easy threads provide a more than adequate
substitute in many cases.  a channel can represent a connection to a
remote procedure with its attached data.

for instance, a trivial example:

getop(s: string): chan of (string, chan of string)
{
	c := chan of (string, chan of string);
	spawn append(s, c);
	return c;
}

append(s: string, c: chan of (string, chan of string))
{
	for(;;){
		(t, reply) := <-c;
		reply <-= s + t;
	}
}

in this example, the channel returned by getop(s)
is functionally equivalent to λt.(s + t).
the generic operator would look like:

op(s: string, c: chan of (string, chan of string)): string
{
	reply := chan of string;
	c <-= (s, reply);
	return <-reply;
}

of course in this case the amount of code compared with its actual
function is considerable, but for less trivial applications this is
often viable (moreover, it's considerably more powerful, as the
channel represents an ongoing continuation rather than just a closure).


re: message polymorphism.
strings are often used for this kind of thing in limbo, as they're
easy to use, by-value (yet locally mutable) and it's trivial to
transfer them externally.

generally, Limbo programs tend to avoid polymorphism (although the
latest version does have parametric polymorphism) in favour of a
simple, direct style of coding.

channels i mentioned earlier in this respect.  dynamically loaded
modules mean that you can have several dynamically loaded pieces of
code each complying to the same interface.

i've used this to pleasing effect in some limbo programs.  for
example, a piece of "grid" software i did recently allows one to farm
out pieces of work to multiple clients and reliably collect them.  the
module that actually splits up the work and marshals the results is
separately implemented.  its interface is entirely specified by the
following self-contained module definition:

Taskgenerator: module {
	init:		fn(jobid: string, state: string, args: list of string): string;
	taskcount:	fn(): int;
	state:	fn(): string;
	start:		fn(id: string,
		tries:	int,
		spec: ref Clientspec,
		read: chan of (int, chan of array of byte, chan of int),
		write: chan of (array of byte, chan of string, chan of int),
		finish: chan of (int, big, chan of string)): (int, string);
	reconnect:	fn(id: string,
		read: chan of (int, chan of array of byte, chan of int),
		write: chan of (array of byte, chan of string, chan of int),
		finish: chan of (int, big, chan of string)): int;

	complete:	fn();
	quit:	fn();

	Clientspec: adt {
		addr: string;
		attrs: list of (string, string);
		nodeattrs: list of (string, string);
	};
	Started, Error, Nomore: con iota;
};

this uses the above mentioned forms of polymorphism in several ways:

multiple different implementations of Taskgenerator modules coexist
concurrently, each with its own unrelated state.

calling start() asks the task generator to start a new task; it
returns some channels that can then be used by the core software to
communicate with an instance of that task (usually a thread will be
started).  the interface is straightforward, and both sides of the
software can be written in a straightforward manner.

strings are used to hold arbitrary data (attribute-value pairs,
arbitrary client-created identifiers).

implementation is almost completely divorced from interface, making
the whole thing highly modular.  i can replace task generator modules
at run time with no hassle (and often do).

of course, it's no magic bullet, but the features of Limbo do seem to
me to work in synergy to produce a language that spurs creativity
rather than inviting perplexity.

  cheers,
    rog.



  parent reply	other threads:[~2004-03-02 15:04 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f62d09b11d1f097b3f4b5f6b70b65ea5@proxima.alt.za>
2004-03-02  6:58 ` David Tolpin
2004-03-02  7:06   ` Fco.J.Ballesteros
2004-03-02  7:08     ` David Tolpin
2004-03-02  7:14       ` Fco.J.Ballesteros
2004-03-02  7:30         ` David Tolpin
2004-03-02  7:37           ` Fco.J.Ballesteros
2004-03-02  7:48             ` David Tolpin
2004-03-02  9:50               ` Fco.J.Ballesteros
2004-03-02 20:50               ` Andrew Simmons
2004-03-02 20:56                 ` matt
2004-03-02 20:57                   ` ron minnich
2004-03-02 12:44           ` Bruce Ellis
2004-03-02  7:50   ` lucio
2004-03-02  7:56     ` David Tolpin
2004-03-02  8:12       ` Charles Forsyth
2004-03-02  8:12         ` David Tolpin
2004-03-02  8:45           ` Charles Forsyth
2004-03-02  8:51             ` David Tolpin
2004-03-02  9:06               ` David Presotto
2004-03-02  9:14                 ` David Tolpin
2004-03-02  9:26                   ` Charles Forsyth
2004-03-02 15:04       ` rog [this message]
2004-03-02 15:12         ` David Tolpin
2004-03-02 16:03         ` C H Forsyth
2004-03-02 16:06           ` David Tolpin
2004-03-02 16:24             ` David Tolpin
2004-03-02 16:35             ` C H Forsyth
2004-03-02 17:18     ` andrey mirtchovski
2004-03-02 12:39   ` Bruce Ellis
2004-03-02  8:02 David Presotto
2004-03-02  8:20 ` David Tolpin
2004-03-02  8:55   ` David Presotto
2004-03-02  9:20   ` Rob Pike
     [not found] <918d202b192f1bcb8dd969285010a329@proxima.alt.za>
2004-03-02  8:37 ` David Tolpin
     [not found] <d02d8014f5f4b58c6863ec7a3cd652ee@proxima.alt.za>
2004-03-02  9:07 ` David Tolpin
2004-03-02 10:04   ` lucio
2004-03-02 10:08     ` Fco.J.Ballesteros
2004-03-02 11:35       ` matt
2004-03-02 18:38         ` boyd, rounin
2004-03-02 19:03           ` Fco.J.Ballesteros
2004-03-02 19:10             ` rog
2004-03-02 19:08               ` Fco.J.Ballesteros
2004-03-02 15:03 rog
2004-03-03  7:21 YAMANASHI Takeshi
2004-03-03  7:29 ` Kenji Okamoto
2004-03-03  7:31   ` Kenji Okamoto
2004-03-03  7:37 YAMANASHI Takeshi
2004-03-03 12:29 ` boyd, rounin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bb080f48852e81778453f33543dac9c4@vitanuova.com \
    --to=rog@vitanuova.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).