Hi again,
I wish to use a hash table to store a mapping from a variable name to a
list of coefficients. This is accomplished easily enough in maxima,
however, is there a way of throwing an error if the key accessed is not
a key in the hash table?
Why? Because if the key does not exist, the expression is interpreted as
a symbolic expression, eg:
hash[a] : "aaa"$
So, `hash[a]` would return "aaa", but `hash[b]` is a non-existing key
and thus the expression evaluates symbolically to "hash_{b}" (subscript
b).
The question arises, "Did the hash[b] map to hash_{b} or was the key
non-existent"?
My current solution is silly:
pget(x, hash) := (
info : arrayinfo(hash),
/* strip non-keys */
for i:1 thru 2 do (
info : delete(first(info), info, 1)
),
if member(x, info) then hash[x] else (
error("ERROR: Unknown variable", x),
false
)
)$
This makes my hash table lookup linear :\
What is the correct way?
--
Best Regards
Edd Barrett
http://www.theunixzoo.co.uk