Re: Fallbacks in Euphoria
- Posted by dcuny Jan 12, 2015
- 1658 views
It seems to me fallbacks are an exceptional case handling mechanism
Yes... But in Lua it's possible to make the "normal" case exceptional. For example, indexing by:
atom a = s[1]
differs from Euphoria in that in Lua it's actually a hashtable lookup. So all you need to do in Lua is place your data one level deeper - in an element called data, for example. Since the data is actually in:
atom a = s["data"][1]
calling the index directly will trigger the fallback.
One reason that it's attractive to have these as error fallbacks is speed: you only check on error, so "normal" cases don't have an additional cost to them.
You could choose instead to assume that if there are any fallbacks, you should execute them instead of the default behavior. There is some reason to argue that this might be a useful behavior.
I think being able to access the meta sequence independent of the fallback mechanism is potentially valuable, as language like JavaScript use this sort of functionality to extend their functionality.
- David