Tiny addition to stdlib


Subject: Tiny addition to stdlib
From: Keunwoo Lee (klee@cs.washington.edu)
Date: Thu Jan 25 2001 - 18:30:03 PST


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 : Thu Jan 25 2001 - 18:30:14 PST