Arc Forumnew | comments | leaders | submitlogin
2 points by pg 5681 days ago | link | parent

I thought about specifying the default when the table was created, but it seemed more flexible to do it at lookup, because you could choose a value for the default (e.g. a newly created object) that would let you distinguish between having no entry for some key and having an entry whose value was the default.


3 points by Adlai 5681 days ago | link

What if a default specified at lookup overrode the default specified when the table was created?

My Arc knowledge is essentially #f at the moment, but this

  ((hash-table? fn)
   (ar-nill (or (hash-table-get fn (car args) #f)
                (hash-table-get fn hash-table-default #f))))
seems to be the code for looking up a key using the (some-table key) syntax (i.e. putting the table as the "function" in a form). Would it work to have an optional parameter, so that somebody could call (some-table key default) if they wanted to override the default? I'm thinking that this optional parameter would default to #f if unspecified, and would be passed to the first hash-table-get in the above code. This seems to enable overriding of a pre-specified default.

-----

1 point by skenney26 5681 days ago | link

I like your idea of having a default that can be overridden.

The code above is actually Scheme (which Arc is implemented in). Getting and setting table values in Arc is much less clunky.

-----

1 point by Adlai 5681 days ago | link

Yeah, I can tell it's Scheme because of #f used for false, instead of NIL.

If it's possible to pass an optional parameter to an Arc-style hash-table lookup (one where you use the table name as the function), than that would also allow overriding a default to NIL, because the 'or in that Scheme code would return NIL rather than evaluating the hash-table-get for the original default.

-----