replace variable with recursive function