Re: Fallbacks in Euphoria
- Posted by dcuny Jan 12, 2015
- 1587 views
Another possible implementation could be to set a meta flag on the sequence structure instead of a separate sequence. If the flag is set, the fallback routine would be called instead, and directly passed the sequence.
Actually, it would need to be passed a copy of the sequence, without the meta flag set, or you'd be stuck in recursion forever.
Since the low-level operations would always check for the meta flag, there would be a (hopefully small) hit for all the sequence operations.
On the other hand, it simplifies the implementation quite a bit. The fallback always executes for a meta sequence, and there's no need to maintain a second sequence.
The sequence that's passed to the fallback is a copy without the meta field set, which means it's processed inside the fallback as a normal sequence. Of course, if that sequence contains other meta sequences, they are processed properly.
Here's the catch: how would the changes get saved back to the meta sequence?
That's why I suggested that meta holds a pointer to a sequence - you could have a fetch_meta() and set_meta() sort of call to access the metadata. But now that I think about it, I'm not sure that would work either - because only the meta sequence for the copy would get changed, not the calling sequence.
This sort of thing makes my head hurt! But I suspect that this is doable, I just need to wrap my head around it.
- David