<#802#>(d<#802#><#803#>efine<#803#> <#804#>(f<#804#> <#805#>x<#805#> <#806#>...<#806#> <#807#>y)<#807#> <#808#>an-expression)<#808#>That is, a definition is a sequence of several words and expressions: ``('', the word ``define'', ``('', a non-empty sequence of names separated by spaces, ``)'', an expression, and a closing ``)''. The embedded sequence of names, <#60404#><#812#>f<#812#>\ <#813#>x<#813#>\ <#814#>...<#814#>\ <#815#>y<#815#><#60404#>, introduces the name of the program and the names of its parameters.
<#70649#>Syntax
<#826#>(d<#826#><#827#>efine<#827#> <#828#>(P<#828#> <#829#>x)<#829#> <#830#>(+<#830#> <#831#>(x)<#831#> <#832#>10))<#832#> <#833#>(d<#833#><#834#>efine<#834#> <#835#>(P<#835#> <#836#>x)<#836#> <#837#>x<#837#> <#838#>10)<#838#>The first one contains an extra pair of parentheses around the variable <#60408#><#842#>x<#842#><#60408#>, which is not a compound expression; the second contains two atomic expressions, <#60409#><#843#>x<#843#><#60409#> and <#60410#><#844#>10<#844#><#60410#>, instead of one. When we click DrScheme's <#845#>Execute<#845#> button, the programming environment first determines whether the definitions are formed according to Scheme's rules. If some part of the program in the <#846#>Definitions<#846#> window is ill-formed, DrScheme signals a <#60411#><#847#>SYNTAX ERROR<#847#><#60411#> with an appropriate error message and highlights the offending part. Otherwise it permits the user to evaluate expressions in the <#848#>Interactions<#848#> window.
<#859#>(+<#859#> <#860#>(10)<#860#> <#861#>20)<#861#> <#862#>(10<#862#> <#863#>+<#863#> <#864#>20)<#864#> <#865#>(+<#865#> <#866#>+)<#866#>Read and understand the error messages.~ Solution<#60413#><#60413#> <#875#>Exercise 2.4.2<#875#>
<#883#>(d<#883#><#884#>efine<#884#> <#885#>(f<#885#> <#886#>1)<#886#> <#887#>(+<#887#> <#888#>x<#888#> <#889#>10))<#889#> <#890#>(d<#890#><#891#>efine<#891#> <#892#>(g<#892#> <#893#>x)<#893#> <#894#>+<#894#> <#895#>x<#895#> <#896#>10)<#896#> <#897#>(d<#897#><#898#>efine<#898#> <#899#>h(x)<#899#> <#900#>(+<#900#> <#901#>x<#901#> <#902#>10))<#902#>Read the error messages, fix the offending definition in an appropriate manner, and repeat until all definitions are legal.~ Solution<#60414#><#60414#>
<#922#>(d<#922#><#923#>efine<#923#> <#924#>(f<#924#> <#925#>n)<#925#> <#926#>(+<#926#> <#927#>(/<#927#> <#928#>n<#928#> <#929#>3)<#929#> <#930#>2))<#930#>we cannot ask DrScheme to evaluate <#60416#><#934#>(f<#934#>\ <#935#>5<#935#>\ <#936#>8)<#936#><#60416#>. When the evaluation of a legal Scheme expression demands a division by zero or similarly nonsensical arithmetic operations, or when a program is applied to the wrong number of inputs, DrScheme stops the evaluation and signals a <#60417#><#937#>RUN-TIME ERROR<#937#><#60417#>. Typically it prints an explanation in the <#938#>Interactions<#938#> window and highlights the faulty expression. The highlighted expression triggered the error signal.
<#949#>(+<#949#> <#950#>5<#950#> <#951#>(/<#951#> <#952#>1<#952#> <#953#>0))<#953#> <#954#>(sin<#954#> <#955#>10<#955#> <#956#>20)<#956#> <#957#>(somef<#957#> <#958#>10)<#958#>Read the error messages.~ Solution<#60418#><#60418#> <#967#>Exercise 2.4.4<#967#>
<#975#>(d<#975#><#976#>efine<#976#> <#977#>(somef<#977#> <#978#>x)<#978#> <#979#>(sin<#979#> <#980#>x<#980#> <#981#>x))<#981#>Then, in the <#985#>Interactions<#985#> window, evaluate the expressions:
<#990#>(somef<#990#> <#991#>10<#991#> <#992#>20)<#992#> <#993#>(somef<#993#> <#994#>10)<#994#>and read the error messages. Also observe what DrScheme highlights.~ Solution<#60419#><#60419#>
<#1012#>(d<#1012#><#1013#>efine<#1013#> <#1014#>(wage<#1014#> <#1015#>h)<#1015#> <#1016#>(+<#1016#> <#1017#>12<#1017#> <#1018#>h))<#1018#>the program would still produce a number every time it is used. Indeed, if we evaluate <#60422#><#1022#>(wage<#1022#>\ <#1023#>12/11)<#1023#><#60422#>, we even get the correct result. A programmer can only catch such mistakes by designing programs carefully and systematically.