I want to write a function that can be used to grow an expression from a seed or another existing expression based on part specification.


So if I start from a seed say "START" like follows:

expr = growExpression["START",{{1,2,3}->"B",{2,1}->"A"},Null]


Note I want it to accept a parameter which can be used to decide unspecified but necessary growth to support the rest of the structure. Next, if I now take this expression as a seed and do further growth as follows:

expr = growExpression[expr,{{1}->"C",{1,2,2,4}->"D",{1,2,1}->"A",{2,1}->"E"},f]


Note even if non-leaves are replaced the expression doesn't shrink, i.e. {1}->"C" is basically equivalent to {1,0}->"C".

Is there a builtin function that can help to achieve this behavior without side effects?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.