0

I am cleaning up some (Chicken) scheme code and I want to identify all lists/procedures not used in a given program. Is there a specific option to pass either to the Chicken compiler or to csi -s I can use to do so without listing out each define and grep-ing for the identifiers in the *.scm scripts?

xuinkrbin.
  • 975
  • 2
  • 7
  • 17

3 Answers3

0

you could use the repl function from eval unit and pass to that an evaluator function that keeps track of the symbol if it is a list or a lambda before calling eval on the argument.

ramrunner
  • 1,362
  • 10
  • 20
  • Perhaps this is just My lack of experience with repl but I don't see how that would help. – xuinkrbin. Jan 10 '14 at 15:55
  • it's not that hard. all is explained in chapter 4 of SICP. check out this implementation of an evaluator (https://github.com/jacktrades/Scheme-Meta-Circular-Evaluator) . all you have to do is add some code in the meta-eval lambda, to keep track of the symbols it uses. (if you require-extension symbol-utils you can use the symbol->keyword lambda to for nice printing). just dump all the symbol names in a file port. you will end up with all the names of the lists or lambdas (the procedure? test) that were used. don't forget to load your main program from inside the meta-repl. – ramrunner Jan 10 '14 at 18:54
0

It is not possible to decide which top-level entries will be used, because it is possible to dynamically craft expressions:

(eval (list (string->symbol "+") 1 2)) →  3

It would be necessary to evaluate all possible permutations of your program.

ceving
  • 21,900
  • 13
  • 104
  • 178
0

If you put your code in a module, it will show a warning about unused, unexported identifiers when compiling it (you might need to use csc -v to show them).

sjamaan
  • 2,282
  • 10
  • 19