Replace unnecessary parts of the code
I have to implement a program that finds useless pieces of code and replaces it with some better code. I'll give you an example:
;;(define (positive-odd? n) ;; (if (and (odd? n) (positive? n)) #t #f))
should be replaced with:
;;(define (positive-odd? n) ;; (and (odd? n) (positive? n)))
I also have a list with rules. I will give you an example of a rule that will help us with the following example:
;;(define redundant-if ;; '((WHEN (if ?cond #t #f)) ;; (THEN ?cond)))
So, I have to iterate over this list of rules and find a match between the rules and my function with useless code. For this I only have an idea, but I don't think it's a good one: I take a very rule from the list of rules, then I iterate over the body of my function and look for similarities, and when I find it, I replace the code. But I think this is quite difficult to do.
Please give me an idea of this issue.
source to share