9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] first capital letter in function names at man pages, why?
@ 2004-05-20 18:42 rog
  2004-05-20 19:21 ` Scott Schwartz
  2004-05-20 20:07 ` [9fans] first capital letter in function names at man pages, why? boyd, rounin
  0 siblings, 2 replies; 8+ messages in thread
From: rog @ 2004-05-20 18:42 UTC (permalink / raw)
  To: 9fans

> you'd better write N parsers.

actually it's not an unreasonable idea to have a regular expression
engine that could work on arbitrary alphabets.
you could express it quite nicely with the new limbo
polymorphism stuff:

	match[T](c: chan of T, p: ref Regex[T]): int for {
		T =>
			eq: fn(t: self T, t1: T): int;
			eof: fn(t: self T): int;
		}

so the alphabet would consist of members of type T, arriving down
channel c, being matched against a previously compiled pattern p.

match would return when it enounters a match, or reads a t such that
t.eof() is true.

then you could write N parsers and just plug 'em in.

i've got something that would allow one to use this kind of stuff
with a shell-like syntax. it's awaiting a bit more of my time...



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] first capital letter in function names at man pages, why?
  2004-05-20 18:42 [9fans] first capital letter in function names at man pages, why? rog
@ 2004-05-20 19:21 ` Scott Schwartz
  2004-05-20 19:51   ` [9fans] limbo polymorphism rog
  2004-05-20 20:07 ` [9fans] first capital letter in function names at man pages, why? boyd, rounin
  1 sibling, 1 reply; 8+ messages in thread
From: Scott Schwartz @ 2004-05-20 19:21 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

| you could express it quite nicely with the new limbo
| polymorphism stuff:

Is there a good reference to look at for that?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* [9fans] limbo polymorphism
  2004-05-20 19:21 ` Scott Schwartz
@ 2004-05-20 19:51   ` rog
  2004-05-20 20:10     ` Charles Forsyth
  0 siblings, 1 reply; 8+ messages in thread
From: rog @ 2004-05-20 19:51 UTC (permalink / raw)
  To: 9fans, inferno-list

>| you could express it quite nicely with the new limbo
>| polymorphism stuff:
>
>Is there a good reference to look at for that?

ahem.

i don't believe there is, until someone gets around to updating the
reference manual.

the syntax does seem reasonably stable now, so that should probably
happen...

it's really quite straightforward though:

a function or adt can be parameterised with one or more type names (in
square brackets).  these types can be used in the body of the function
or adt as any other type.

e.g.
	reverse[T](x: list of T): list of T;

	Table: adt[T] {
		items:	array of list of (int, T);

		new: fn(nslots: int): ref Table[T];
		add:	fn(t: self ref Table, id: int, x: T): int;
		del:	fn(t: self ref Table, id: int): int;
		find:	fn(t: self ref Table, id: int): T;
	};

a "for" clause can define operations on the types (by default
there are none save assignment (and possibly equality, although
i think that will be deprecated).

e.g.
	sort[T](a: array of T) for {
		T =>
			cmp: fn (t0, t1: T): int;
		};

	Env: adt[V]
		for {
		V =>
			discard: fn(v: self V);
		}
	{
		items:	array of list of (string, V);

		new: fn(nslots: int): ref Env[V];
		set:	fn(t: self ref Env, id: string, x: V);
		get:	fn(t: self ref Env, id: string): V;
		clear: fn(t: self ref Env);
	};

[the last syntax is going to change, i think, so that
the for clause comes *after* the adt declaration, rather
than in the middle as currently.]

when calling a type-parameterised function, the compiler infers the
type parameter from the given arguments (currently it's not possible
to explicitly name the type, although that'll come, once john susses
the grammar).

with a function or adt declared polymorphically, you can use any
"pointer type" (i.e.  ref adts, chans, arrays, lists and strings).

for polymorphic types that require member functions, the type has to
be an adt containing at least the required member functions.

so, given the above declaration, you could do:

	x := reverse("one" :: "two" :: "three" :: nil);

to get a list containing "three"::"two"::"one"::nil (assuming
reverse() reverses a list!).



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] first capital letter in function names at man pages, why?
  2004-05-20 18:42 [9fans] first capital letter in function names at man pages, why? rog
  2004-05-20 19:21 ` Scott Schwartz
@ 2004-05-20 20:07 ` boyd, rounin
  2004-05-21 14:05   ` rog
  1 sibling, 1 reply; 8+ messages in thread
From: boyd, rounin @ 2004-05-20 20:07 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> then you could write N parsers and just plug 'em in.

how large is N?  comments and strings and stuff?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] limbo polymorphism
  2004-05-20 19:51   ` [9fans] limbo polymorphism rog
@ 2004-05-20 20:10     ` Charles Forsyth
  0 siblings, 0 replies; 8+ messages in thread
From: Charles Forsyth @ 2004-05-20 20:10 UTC (permalink / raw)
  To: 9fans, inferno-list

	Env: adt[V]
		for {
		V =>
			discard: fn(v: self V);
		}
	{

following a suggestion of roger's, that for clause might move
to follow the adt declaration, that's one reason the syntax
hasn't been published yet.  it doesn't affect functionality.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] first capital letter in function names at man pages, why?
  2004-05-20 20:07 ` [9fans] first capital letter in function names at man pages, why? boyd, rounin
@ 2004-05-21 14:05   ` rog
  2004-05-21 15:12     ` boyd, rounin
  0 siblings, 1 reply; 8+ messages in thread
From: rog @ 2004-05-21 14:05 UTC (permalink / raw)
  To: 9fans

> how large is N?  comments and strings and stuff?

depends what you're interested in.
just the C lexer wouldn't be too hard, and would be useful.



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] first capital letter in function names at man pages, why?
  2004-05-21 14:05   ` rog
@ 2004-05-21 15:12     ` boyd, rounin
  2004-05-21 16:25       ` rog
  0 siblings, 1 reply; 8+ messages in thread
From: boyd, rounin @ 2004-05-21 15:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

> just the C lexer wouldn't be too hard, and would be useful.

which C?



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [9fans] first capital letter in function names at man pages, why?
  2004-05-21 15:12     ` boyd, rounin
@ 2004-05-21 16:25       ` rog
  0 siblings, 0 replies; 8+ messages in thread
From: rog @ 2004-05-21 16:25 UTC (permalink / raw)
  To: 9fans

> > just the C lexer wouldn't be too hard, and would be useful.
>
> which C?

i was under the impression that tokenisation in most dialects
of C was more-or-less the same. don't most incompatibilities
arise at the parsing level and above?



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-05-21 16:25 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-20 18:42 [9fans] first capital letter in function names at man pages, why? rog
2004-05-20 19:21 ` Scott Schwartz
2004-05-20 19:51   ` [9fans] limbo polymorphism rog
2004-05-20 20:10     ` Charles Forsyth
2004-05-20 20:07 ` [9fans] first capital letter in function names at man pages, why? boyd, rounin
2004-05-21 14:05   ` rog
2004-05-21 15:12     ` boyd, rounin
2004-05-21 16:25       ` rog

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