> narutocan
@yahoo.ca writes:
> > On May 7, 7:46 am, Pascal Bourguignon <p
@informatimago.com> wrote:
> >> narutocan
@yahoo.ca writes:
> >> > After coding the Groebner Basis program in scheme, I have a good
> >> > question to ask. I have coded the low level polynomial library with
> >> > excessive error catch statements, now after the code has being semi-
> >> > proved working, how do I systematically remove those dead code? "Dead
> >> > code" in the sense that when called from some particular top level
> >> > functions those exceptional situations can never happen. There is no
> >> > way I am going to it by eye-balling the codes. Is this problem easily
> >> > solvable in scheme using some paradigm? I sorta know this problem has
> >> > solution but probably require some brute force approach. The reason I
> >> > know there is a solution was because, I used to write verilog code for
> >> > hardware logic, and those hardware compilers can so aggressively
> >> > optimize your code that there can be no "dead code" or "un-used" path
> >> > in the final hardware logic. Thanks for sharing your insight.
> >> One way would be to redefine these operators as macros expanding only
> >> as the main body.
> > I don't quite understand. Macro are expanded at runtime right?
> No. They are expanded at macro-expansion time, that is, when you use
> a compiler, at compilation-time.
> > Wouldn't that be the same as running the code?
> No.
> > My understand of macros are that macros work like feeding the code
> > back to the reader at run-time. (The way I imagine it works, probably
> > not true in reality)
> > If what you say is true, wouldn't math people write proofs in macros,
> > then expand to see if some code is actually eliminated to prove some
> > statements.
> Well macros are just functions, so they can write directly proofs in
> functions and watch the results of their functions.
> The difference between macro and function is that macros are functions
> that takes a form and return a form, and that are defined in a special
> way, to be pluggable into the compiler. Macros are compiler plug-in
> functions.
> > Can you give an small example of such technique. Thanks.
> Well, I'm not too knowledgeable of scheme (I basically only know some
> of R5RS), and any error catching operator would be an implementation
> specific extension, so I'll take as an example
> common-lisp:handler-case :
> (handler-case
> (+ (/ x y) (/ (x (- y x))))
> (division-by-zero () (princ "Cannot divide by 0"))
> (error (err) (princ "Got some other error: ")(princ err)))
> So we could override the definition of the handler-case operator with
> a macro that generates merely the protected body, that is in the above
> example: (+ (/ x y) (/ (x (- y x)))):
> (define-syntax handler-case (syntax-rules ()
> ((handler-case body handling-clause ...)
> body)))
Ok, I get this. This is like using #ifdef to block out debugging code.