Open phoe opened 2 years ago
In the flurry of activity I overlooked this issue. If you're still interested this seems like a good idea, although it could use a more descriptive name (common-tail-p?).
Sure, that works. I suggested tailp*
because of the sorta-obvious similarity with the standard tailp
, but naming is the hard part.
I'll submit this as a PR eventually.
I can't find a utility that can tell me if any two lists share structure anywhere.
TAILP
only works correctly if you provide it the concrete tail of the list. RunningTAILP
for every element of the other list mostly achieves the goal but has quadratic time complexity, which is painful, plus one needs to remember to handle dotted lists.I propose adding a
TAILP*
operator which uses a hash table for detection of shared structure and therefore can do this in linear time and linear memory. Oh, and it also handles circularities.A quick and hasty implementation:
Some quick and hasty REPL tests:
How does this sound? I can clean this up, add more tests, and make a PR if this sounds like a good addition.