On Tue, Feb 07, 2012 at 01:34:58PM -0800, Richard Fateman wrote:
> Here is how you make all non-entries produce an error.
> hash[x]:= error("ERROR ", x);
>
> /* try it out */
>
> hash[a]:aaa;
>
>
>
> hash[a];
>
> hash[b];
Whilst this works in the simple case, it did not work in the context I
wish to use it -- contrived example follows:
---8<---
(%i0) kill(all)$
(%i1) new_hash() := (
hash : make_array(hashed),
hash[x] := error("Error: ", x),
/* populate */
hash[a] : 1,
hash[b] : 2,
hash[c] : 3,
hash
)$
(%i2) h : new_hash();
(%o2) HashTable
(%i3) h[a];
(%o3) false
---8<---
It seems like the 'hash[x] := error(...)' declaration is syntactic, in
that it will only match for hashes called 'hash'; the behavior is not
associated with the hash itself.
However, I would not have expected 'h[a]' to return false. That is a
mystery. If you remove the 'hash[x] := error(...)' from new_hash(),
'h[a]' returns 1 as expected. A bug?
--
Best Regards
Edd Barrett
http://www.theunixzoo.co.uk