Subject: Re: Tiny addition to stdlib
From: Craig Chambers (chambers@cs.washington.edu)
Date: Fri Jan 26 2001 - 11:56:40 PST
I like it!
You could imagine any kind of table being built from one of these ordered
collections of associations, as long as the keys had the right properties (e.g.
hashable)....
-- Craig
Keunwoo Lee wrote:
> 
> I'm posting this to get feedback before I commit it.  It's a convenient
> syntactic sugar for constructing association tables; it would go in
> stdlib/assoc-table.cecil.  What do you think?
> 
> ~k
> 
> -- Used this instead of '=>' to avoid confusion with the implication
> -- operator in boolean.cecil.
> method ==>(k:`Key <= comparable[Key], v:`Value):assoc[Key,Value] {
>     new_assoc[Key,Value](k, v) }
> 
> precedence ==> non_associative below =, +, -, *, /, &, |;
> 
> method new_assoc_table_init_from(assocs@:collection[assoc[`Key <= comparable[Key],
>                                                           `Value]]
>                                  ):assoc_table[Key,Value] {
>     let table := new_assoc_table[Key,Value]();
>     assocs.do(&(pair:assoc[Key,Value]) {
>         table.assocs.add_last(pair);
>     });
>     table }
> 
> -- Demo usage
> method main():void {
>     let atable := new_assoc_table_init_from([
>           "foo" ==> 1,
>           "bar" ==> 2,
>           "baz" ==> 3
>       ]);
>     atable.elems_print;
> }
This archive was generated by hypermail 2b25 : Fri Jan 26 2001 - 11:56:47 PST