Arc Forumnew | comments | leaders | submitlogin
1 point by bogomipz 5929 days ago | link | parent

table-w/keys is useful for counting. After creating the table in icemaze's exemple you can for instance do

  (++ (h 'cars))
Even more useful, however, is to specify a default value for keys not yet in the table, so you can do the above without first initializing for the keys you intend to use. PG mentioned in Arc at 3 Weeks that lookup failure should return the global value * fail* , in which case you would be able to do

  (with (h (table) *fail* 0)
        (++ (h 'red))
        (++ (h 'blue))
        (++ (h 'blue))
        (++ (h 'green))
        h)
which returns a table where red is 1, blue is 2, green is 1, and no other keys exist. The example is kind of stupid, but the concept is quite powerful.

Edit: spaces added so * fail* doesn't become fail