-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make hashmap[val]
return an error when val is unbound
#73
Comments
When |
Hmm.. at first I thought I wanted lookup to bind, but now I think it shouldn't. As a comparison, it doesn't bind in either python or ruby. |
You'd need a way to tell the difference between Also having some function that binds, or a quick way to bind to the last place you looked at (not very thread-friendly) actually saves work in many common use cases. |
Another thought -- this is really a question for all "map" data structures. It would be nice to have a uniform API that covered this and the accumulation functions in Max's current implementation. There are a bunch of graph-theoretic and orbit-like algorithms that could be expressed effectively in that framework -- orbit & stabilizer, shortest path and cycle-finding algorithms and so on. Then any data structure that provided this API could be used efficiently and interchangeably without changing the application code. |
At the moment,
hashmap[val]
returnfail
whenval
is not in hashmap. This is inconsistent with lists, wherel[2]
returns an error if2
is not bound in a listl
.My suggested fix:
Make
hashmap[val]
return an Error if val is unbound.Add a new function
Lookup(map, key [,default])
, which returnsmap[key]
if that is defined, anddefault
otherwise. If default is ommitted, treat it asfail
, which gives the behaviour of the currenthashmap[val]
.The text was updated successfully, but these errors were encountered: