Concord Physics

download Concord Physics

of 1

description

IT

Transcript of Concord Physics

In each case we get the right answer, but we don't get any indication of what ?X is, sowe couldn't substitute it into the response. We need to modify pat -match to returnsome kind of table of variables and correspondingvalues. In making this choice, theexperienced Common Lisp programmer can save some time by being opportunistic:recognizing when there is an existing function that will do a large part of the task athand. What we want is to substitute values for variables throughout the response.The alert programmer could refer to the index of this book or the Common Lispreferencemanualandfindthefunctions substitute, subst,and subl i s . Allof thesesubstitute some new expression for an old one within an expression. It turns out thatsubl i s is most appropriate because it is the only one that allows us to make severalsubstitutions all at once. s ubl i s takes two arguments, the first a list of old-new pairs,and the second an expression in which to make the substitutions. For each one ofthe pairs, the car is replaced by the cdr. In other words, we would form each pairwith something like ( cons 01 d new 1. (Such a list of pairs is known as an associationlist, or a-list, because it associates keys with values. See section 3.6.) In terms of theexample above, we would use: