|
From: <don...@is...> - 2005-06-15 18:18:14
|
Bruno Haible writes: > About LOAD-TIME-VALUE: There are two reasons for keeping clisp's behaviour, > i.e. in the interpreter, reevaluate each time: > > 1) In the interpreter, the developer wants changes to other functions to > be activated immediately, without re-entering forms. Example: I agree that there's some value in this form of "immediate gratification", but it's not as if the current behavior is perfect in that respect, or as if perfection is only a few tweaks away. For instance, if you find yourself in an error break, say + complaining that nil is not a number and you see that your error was that (+ (cdr x) 2) should have been (+ (car x) 2) and then redefine your function, you can't just back up to the + and redo. (Actually, in the days of structure editing that might have worked!) Even if you could, you would have to understand all the same issues when you started to compile. To me it makes more sense to try to make the interpreted behavior similar to the compiled behavior. This seems especially important when it's so much easier to debug the interpreted code, but you really want the compiled code to work! Note that it's pretty easy to find cases where the interpreted code will now do what the programmer wants while the compiled code does not. (This is much more likely to happen to a beginner, but then the ideal of trying to make every change take immediate effect seems mainly for his benefit.) > 2) MEMOIZED does extra consing; it's useless to do extra consing to > implement a behaviour of which ANSI CL says that you cannot count upon. Alternatively, one might argue that it's useless to do extra evaluation (including lots of consing in many cases) that the spec says you can't count upon. The performance tradeoff seems clearly in favor of memoizing. The interpreted code already uses a whole bunch of conses and the addition of one more to store the result and a boolean is small fixed overhead compared to (almost always) much higher cost on (almost always) many different occasions. > About DEFMACRO, it's not clear what you mean. It's completely analogous. > (loop for i below 3 collect (load-time-value (print 2))) 2 2 2 (2 2 2) > (defmacro foo () (print 2)) > (loop for i below 3 collect (foo)) 2 2 2 (2 2 2) In both of these cases I'd like the print to happen only once, as would be the case if the code were compiled. |