正在加载图片...
6.001 Structure and Interpretation of Computer Programs. Copyright o 2004 by Massachusetts Institute of Technology Slide 7.2.6 a second class of errors deals with mistakes in syntax Syntax errors creating expressions that do not satisfy the programming language's rules for creating legal expressions. A simple rong number of argume of these is an expression in which the wrong number ofone Source: programming en arguments is provided to the procedure. If this occurs while Solution: use debugger to isolate instance attempting to evaluate the offending expression, we will usually be thrown into the debugger -a system intended to help us determine the source of the error. In Scheme the debugger provides us with information about the environment in which he offending expression occurred. It supplies tools for 6 001 SICP examining the values associated with variable names, and for examining the sequence of expressions that have been evaluated leading up to this error. By stepping through the frames of the debugger, we can often isolate where in our code the incorrect expression resides Slide 7.2.7 A more insidious syntax error occurs when we use an expression of the wrong type somewhere in our code Syntax errors If we use an expression whose value is not a procedure as the Wrong number of arguments first subexpression of a combination, we will get an error that Source: programming error indicates we have tried to apply a non-procedure object. As Solution: use debugger to isolate instance before, the debugger can often help us isolate the location of errors this error, though it may not provide much insight into why an As procedure incorrect object was used as a procedure. For that, we may As arguments have to trace back through our code. to determine how this Source: calling error The harder error to isolate is one in which one of the argument 4 maor Solution: trace back through chain of call value was supplied to the offending expression expressions to a combination is of the wrong type. The reason this is harder to track down is that the cause of the creation of an incorrect object type may have occurred far upstream, that is, some other part of our code may have created an incorrect object, which has been passed through several levels of procedure calls before causing an error. Tracking down the original source of this error can be difficult, as we need to chase our way back through the sequence of expression evaluations to find where we accidentally created the wrong type of argument Slide 7. 2.8 Structure errors The most common sorts of errors, though, are structural ones his means that our code is syntactically valid-composed of Wrong initialization of parameters correctly phrased expressions, but the code does not compute what we intended because we have made an error somewhere Wrong end test in the code design. This could be for a variety of reasons and so on started a recursive process with the wrong initial values, or we are ending at the wrong place, or we are updating parameters incorrectly, or we are using the wrong procedure somewhere and so on. Finding these errors is tougher, since the code may run without causing a language error, but the results we get are6.001 Structure and Interpretation of Computer Programs. Copyright © 2004 by Massachusetts Institute of Technology. Slide 7.2.6 A second class of errors deals with mistakes in syntax – creating expressions that do not satisfy the programming language’s rules for creating legal expressions. A simple one of these is an expression in which the wrong number of arguments is provided to the procedure. If this occurs while attempting to evaluate the offending expression, we will usually be thrown into the debugger – a system intended to help us determine the source of the error. In Scheme, the debugger provides us with information about the environment in which the offending expression occurred. It supplies tools for examining the values associated with variable names, and for examining the sequence of expressions that have been evaluated leading up to this error. By stepping through the frames of the debugger, we can often isolate where in our code the incorrect expression resides. Slide 7.2.7 A more insidious syntax error occurs when we use an expression of the wrong type somewhere in our code. If we use an expression whose value is not a procedure as the first subexpression of a combination, we will get an error that indicates we have tried to apply a non-procedure object. As before, the debugger can often help us isolate the location of this error, though it may not provide much insight into why an incorrect object was used as a procedure. For that, we may have to trace back through our code, to determine how this value was supplied to the offending expression. The harder error to isolate is one in which one of the argument expressions to a combination is of the wrong type. The reason this is harder to track down is that the cause of the creation of an incorrect object type may have occurred far upstream, that is, some other part of our code may have created an incorrect object, which has been passed through several levels of procedure calls before causing an error. Tracking down the original source of this error can be difficult, as we need to chase our way back through the sequence of expression evaluations to find where we accidentally created the wrong type of argument. Slide 7.2.8 The most common sorts of errors, though, are structural ones. This means that our code is syntactically valid – composed of correctly phrased expressions, but the code does not compute what we intended, because we have made an error somewhere in the code design. This could be for a variety of reasons: we started a recursive process with the wrong initial values, or we are ending at the wrong place, or we are updating parameters incorrectly, or we are using the wrong procedure somewhere, and so on. Finding these errors is tougher, since the code may run without causing a language error, but the results we get are erroneous
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有