Rangarajan Posted April 20, 2016 Share Posted April 20, 2016 Very useful function. I have a few questions: 1) Why is it called “motif-map” instead of, say, “sequence-map” or “substitute-sequence”, because what it does is to replace a part of a sequence with another. 2) I expected it to use the “best match” when replacing. In the following case (motif-map '(((0 1 2) (a b c)) ((0 1 2 3) (p q r))) '(0 1 2 3 4 5 6 7 8 9 10 11) :otherwise 'x) => (a b c x x x x x x x x x) I thought it would give (p q r x x x x x x x x x) because (0 1 2 3) is (arguably) a better match than (0 1 2). However, when I did this (motif-map '(((0 1 2 3) (a b c)) ((0 1 2) (p q r))) '(0 1 2 3 4 5 6 7 8 9 10 11) :otherwise 'x) it gave me => (a b c x x x x x x x x) That means it checks from left to right. So, technically, the longest sequence matching can be done by just re-arranging the given sequences in decreasing order of length. Does it make sense to use the “longest” sequence logic? I am not sure. 3) If there are many sequence pairs to work with, does the replacement occur at the top level, or iteratively? For example, in this case: (motif-map '(((0 1 2 3) (a b c)) ((a b c) (p q r)) ((p q) (m n o))) '(0 1 2 3 4 5 6 7 8 9 10 11) :otherwise 'x) I was pleasantly surprised to see this answer: => (m n o r x x x x x x x x) That shows it works on successive replaced result. I like this, but it may be a good idea to take an optional keyword to decide which of the 2 possible behaviors will be applied. In this example, if the replacement only worked at the top level, the result would be: => (a b c x x x x x x x x) Whatever is the behaviour, it is a good idea to document it. - Rangarajan Quote Link to comment Share on other sites More sharing options...
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.