1616 <SPLITINLINE ><SCHEME ><SCHEMEINLINE >Sqrt</SCHEMEINLINE ></SCHEME ><JAVASCRIPT >The function <JAVASCRIPTINLINE >sqrt</JAVASCRIPTINLINE ></JAVASCRIPT ></SPLITINLINE > is our first example of a process defined by a set of
1717 mutually
1818 <SPLITINLINE ><SCHEME >defined procedures</SCHEME >
19- <JAVASCRIPT >declared functions</JAVASCRIPT ></SPLITINLINE >.
19+ <JAVASCRIPT >defined functions</JAVASCRIPT ></SPLITINLINE >.
2020 Notice that the
2121 <SPLITINLINE ><SCHEME >definition of <SCHEMEINLINE >sqrt-iter</SCHEMEINLINE ></SCHEME ><JAVASCRIPT >declaration of <JAVASCRIPTINLINE >sqrt_iter</JAVASCRIPTINLINE ></JAVASCRIPT ></SPLITINLINE > is
2222 <INDEX >recursive procedure<SUBINDEX >recursive procedure definition</SUBINDEX ></INDEX >
@@ -385,13 +385,14 @@ function square(y) {
385385 </JAVASCRIPT >
386386 </SPLITINLINE >
387387 For example, we used
388- <SCHEMEINLINE >square</SCHEMEINLINE > in
389- the definition of
388+ <SCHEMEINLINE >square</SCHEMEINLINE >
390389 <SPLITINLINE >
391390 <SCHEME >
391+ in the definition of
392392 <SCHEMEINLINE >good-enough?</SCHEMEINLINE >
393393 </SCHEME >
394394 <JAVASCRIPT >
395+ in the declaration of
395396 <JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE >
396397 </JAVASCRIPT >
397398 </SPLITINLINE >
@@ -528,13 +529,13 @@ function good_enough(guess, x) {
528529 has a very special role in the
529530 <SPLITINLINE >
530531 <SCHEME >
531- procedure
532+ procedure definition,
532533 </SCHEME >
533534 <JAVASCRIPT >
534- function
535+ function declaration,
535536 </JAVASCRIPT >
536537 </SPLITINLINE >
537- definition, in that it doesn<APOS />t matter what name the
538+ in that it doesn<APOS />t matter what name the
538539 <SPLITINLINE >
539540 <SCHEME >
540541 formal
@@ -549,14 +550,13 @@ function good_enough(guess, x) {
549550 <SPLITINLINE >
550551 <SCHEME >
551552 a <EM >bound variable</EM >, and we
552- say that the procedure
553+ say that the procedure definition
553554 </SCHEME >
554555 <JAVASCRIPT >
555556 <EM >bound</EM >, and we
556- say that the function
557+ say that the function declaration
557558 </JAVASCRIPT >
558559 </SPLITINLINE >
559- definition
560560 <INDEX >bind</INDEX >
561561 <EM >binds</EM > its
562562 <SPLITINLINE >
@@ -573,18 +573,22 @@ function good_enough(guess, x) {
573573 procedure definition is unchanged if a bound variable
574574 </SCHEME >
575575 <JAVASCRIPT >
576- function definition is unchanged if a bound name
576+ function declaration is unchanged if a bound name
577577 </JAVASCRIPT >
578578 </SPLITINLINE >
579- is consistently renamed throughout the definition.<FOOTNOTE >The
579+ is consistently renamed throughout the
580+ <SPLITINLINE ><SCHEME >definition</SCHEME ><JAVASCRIPT >declaration</JAVASCRIPT ></SPLITINLINE >.<FOOTNOTE >The
580581 concept of consistent renaming is actually subtle and difficult to
581582 define formally. Famous logicians have made embarrassing errors
582583 here.</FOOTNOTE >
583584If a <SPLITINLINE ><SCHEME >variable</SCHEME ><JAVASCRIPT >name</JAVASCRIPT ></SPLITINLINE >
584585is not bound, we say that it is
585586 <INDEX >free variable</INDEX ><INDEX >variable<SUBINDEX >free</SUBINDEX ></INDEX >
586587 <EM >free</EM >. The
587- set of expressions for which a binding defines a name is called the
588+ set of expressions for which a binding
589+ <SPLITINLINE ><SCHEME >defines</SCHEME ><JAVASCRIPT >declares</JAVASCRIPT ></SPLITINLINE >
590+ a name
591+ is called the
588592 <INDEX >scope of a variable</INDEX ><INDEX >variable<SUBINDEX >scope of</SUBINDEX ></INDEX >
589593 <EM >scope</EM > of that name.
590594 In a
@@ -593,7 +597,7 @@ function good_enough(guess, x) {
593597 procedure definition, the bound variables
594598 </SCHEME >
595599 <JAVASCRIPT >
596- function definition , the bound names
600+ function declaration , the bound names
597601 </JAVASCRIPT >
598602 </SPLITINLINE >
599603 declared as the
@@ -662,7 +666,7 @@ function good_enough(guess, x) {
662666 </SCHEME >
663667 <JAVASCRIPT >
664668 <TEXT >
665- In the definition of <JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE > above,
669+ In the declaration of <JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE > above,
666670 <JAVASCRIPTINLINE >guess</JAVASCRIPTINLINE > and <JAVASCRIPTINLINE >x</JAVASCRIPTINLINE > are
667671 bound names but <JAVASCRIPTINLINE >abs</JAVASCRIPTINLINE >, and
668672 <JAVASCRIPTINLINE >square</JAVASCRIPTINLINE > are free.
@@ -683,19 +687,21 @@ function good_enough(guess, x) {
683687 meaning of <JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE > is
684688 not independent of the choice of its
685689 free names, however. It surely depends upon the fact (external to
686- this definition ) that the symbol <JAVASCRIPTINLINE >abs</JAVASCRIPTINLINE > names a
690+ this declaration ) that the symbol <JAVASCRIPTINLINE >abs</JAVASCRIPTINLINE > names a
687691 function for computing the absolute value of a number.
688692 The JavaScript function <JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE > will
689693 compute a different mathematical function if we substitute
690694 <JAVASCRIPTINLINE >math_cos</JAVASCRIPTINLINE > (JavaScript<APOS />s cosine function)
691- for <JAVASCRIPTINLINE >abs</JAVASCRIPTINLINE > in its definition .
695+ for <JAVASCRIPTINLINE >abs</JAVASCRIPTINLINE > in its declaration .
692696 <INDEX >local name|)</INDEX >
693697 </TEXT >
694698 </JAVASCRIPT >
695699 </SPLIT >
696700
697701 <SUBHEADING >
698- <NAME >Internal definitions and block structure</NAME >
702+ <NAME >Internal
703+ <SPLITINLINE ><SCHEME >definitions</SCHEME ><JAVASCRIPT >declarations</JAVASCRIPT ></SPLITINLINE >
704+ and block structure</NAME >
699705 </SUBHEADING >
700706 <LABEL NAME =" sec:block-structure" />
701707
@@ -903,9 +909,14 @@ function sqrt(x) {
903909 This <EM >block structure</EM >
904910 is basically the right solution to the simplest
905911 name-packaging problem. But there is a better idea lurking here. In
906- addition to internalizing the definitions of the auxiliary
907- <SPLITINLINE ><SCHEME >procedures</SCHEME ><JAVASCRIPT >functions</JAVASCRIPT ></SPLITINLINE >,
908- we can simplify them. Since <SCHEMEINLINE >x</SCHEMEINLINE > is bound in the definition of
912+ addition to internalizing the
913+ <SPLITINLINE ><SCHEME >definitions of the auxiliary procedures</SCHEME >
914+ <JAVASCRIPT >declarations of the auxiliary functions</JAVASCRIPT ></SPLITINLINE >,
915+ we can simplify them. Since <SCHEMEINLINE >x</SCHEMEINLINE >
916+ is bound in the
917+ <SPLITINLINE ><SCHEME >definition</SCHEME >
918+ <JAVASCRIPT >declaration</JAVASCRIPT ></SPLITINLINE >
919+ of
909920 <SCHEMEINLINE >sqrt</SCHEMEINLINE >, the
910921 <SPLITINLINE >
911922 <SCHEME >
@@ -917,8 +928,12 @@ function sqrt(x) {
917928 </SPLITINLINE >
918929 <SPLITINLINE ><SCHEME ><SCHEMEINLINE >good-enough?</SCHEMEINLINE ></SCHEME ><JAVASCRIPT ><JAVASCRIPTINLINE >good_enough</JAVASCRIPTINLINE ></JAVASCRIPT ></SPLITINLINE >,
919930 <SCHEMEINLINE >improve</SCHEMEINLINE >, and
920- <SPLITINLINE ><SCHEME ><SCHEMEINLINE >sqrt-iter</SCHEMEINLINE ></SCHEME ><JAVASCRIPT ><JAVASCRIPTINLINE >sqrt_iter</JAVASCRIPTINLINE ></JAVASCRIPT ></SPLITINLINE >,
921- which are defined internally to
931+ <SPLITINLINE >
932+ <SCHEME ><SCHEMEINLINE >sqrt-iter</SCHEMEINLINE >,
933+ which are defined internally to</SCHEME >
934+ <JAVASCRIPT ><JAVASCRIPTINLINE >sqrt_iter</JAVASCRIPTINLINE >,
935+ which are defined internally to</JAVASCRIPT >
936+ </SPLITINLINE >
922937 <SCHEMEINLINE >sqrt</SCHEMEINLINE >, are in the
923938 scope of <SCHEMEINLINE >x</SCHEMEINLINE >.
924939 Thus, it is not necessary to pass
@@ -930,7 +945,10 @@ function sqrt(x) {
930945 <INDEX >free variable<SUBINDEX >internal@in internal definition</SUBINDEX ></INDEX >
931946 free
932947 <SPLITINLINE ><SCHEME >variable</SCHEME ><JAVASCRIPT >name</JAVASCRIPT ></SPLITINLINE >
933- in the internal definitions, as shown below.
948+ in the internal
949+ <SPLITINLINE ><SCHEME >definitions,</SCHEME >
950+ <JAVASCRIPT >declarations,</JAVASCRIPT ></SPLITINLINE >
951+ as shown below.
934952 Then <SCHEMEINLINE >x</SCHEMEINLINE >
935953 gets its value from the argument with which the enclosing
936954 <SPLITINLINE >
@@ -960,25 +978,24 @@ function sqrt(x) {
960978 bindings made by enclosing
961979 <SPLITINLINE >
962980 <SCHEME >
963- procedure
981+ procedure definitions;
964982 </SCHEME >
965983 <JAVASCRIPT >
966- function
984+ function declarations;
967985 </JAVASCRIPT >
968986 </SPLITINLINE >
969- definitions;
970987 that is, they are looked up in
971988 <INDEX >environment<SUBINDEX >lexical scoping and</SUBINDEX ></INDEX >
972989 the environment in which the
973990 <SPLITINLINE >
974991 <SCHEME >
975- procedure
992+ procedure was defined.
976993 </SCHEME >
977994 <JAVASCRIPT >
978- function
995+ function was declared.
979996 </JAVASCRIPT >
980997 </SPLITINLINE >
981- was defined. We will see how
998+ We will see how
982999 this works in detail in chapter<SPACE />3 when we
9831000 study environments and the
9841001 detailed behavior of the interpreter.</FOOTNOTE >
@@ -1022,19 +1039,23 @@ function sqrt(x) {
10221039
10231040 <TEXT >
10241041 We will use block structure extensively to help us break
1025- up large programs into tractable pieces.<FOOTNOTE >Embedded definitions
1026- <INDEX >internal definition<SUBINDEX >position of</SUBINDEX ></INDEX >
1027- must come first in a
1042+ up large programs into tractable pieces.<FOOTNOTE >Embedded
10281043 <SPLITINLINE >
10291044 <SCHEME >
1030- procedure
1045+ definitions must come first in a procedure
10311046 </SCHEME >
10321047 <JAVASCRIPT >
1033- function
1048+ declarations must come first in a function
10341049 </JAVASCRIPT >
10351050 </SPLITINLINE >
1036- body. The management is not responsible
1037- for the consequences of running programs that intertwine definition
1051+ body.
1052+ <INDEX >internal definition<SUBINDEX >position of</SUBINDEX ></INDEX >
1053+ The management is not responsible
1054+ for the consequences of running programs that intertwine
1055+ <SPLITINLINE >
1056+ <SCHEME >definition</SCHEME >
1057+ <JAVASCRIPT >declaration</JAVASCRIPT >
1058+ </SPLITINLINE >
10381059 and use.<LABEL NAME =" foot:management" /></FOOTNOTE >
10391060 The idea of block structure originated with the
10401061 programming language
0 commit comments