Node:Вычисление процедур,
Next:Особые вычисления,
Previous:Вычисление переменных,
Up:Вычисления
[Показать/скрыть оригинал] [Показать/скрыть перевод] [Переключить перевод и оригинал]
This is where evaluation starts getting interesting! As already noted, a procedure invocation expression has the form
С этого момента выражения становятся нетривиальными. Ранее можно было
заметить, что форма выражения, вызывающего процедуру имело форму:
(procedure [arg1 [arg2 ...]])
where procedure must be an expression whose value, when evaluated, is a procedure.
где procedure должно быть выражением, значения которого в момент вычисления это процедура.
The evaluation of a procedure invocation expression like this proceeds by
Вычисление значения, вызывающего подобную процедуру обрабатывается следующим образом:
For a procedure defined in Scheme, "calling the procedure with the list of values as its parameters" means binding the values to the procedure's formal parameters and then evaluating the sequence of expressions that make up the body of the procedure definition. The value of the procedure invocation expression is the value of the last evaluated expression in the procedure body. The side effects of calling the procedure are the combination of the side effects of the sequence of evaluations of expressions in the procedure body.
Для процедуры, определённой в Scheme, фраза "вызывается процедура, с параметрами, которые являются значениями" означает связать значения с формальными параметрами процедуры и затем произвести последовательность вычислений выражений, составляющих тело определения процедуры. Значение выражения, вызывающего процедуру, это значение последнего вычисленного выражения в теле процедуры. Сторонний эффект вызова процедуры состоит из сторонних эффектов последовательности вычислений выражений в теле процедуры.
For a built-in procedure, the value and side-effects of calling the procedure are best described by that procedure's documentation.
Для встроенных процедур значение и сторонние эффекты от вызова указаны в описании процедуры в документации.
Note that the complete side effects of evaluating a procedure invocation expression consist not only of the side effects of the procedure call, but also of any side effects of the preceding evaluation of the expressions procedure, arg1, arg2, and so on.
Заметим, что общий сторонний эффект вычисления выражения вызова процедуры состоит не только из сторонних эффектов вызова процедуры, но также из любых возможных сторонних эффектов предшествующих вычислений выражений procedure, arg1, arg2, и т.д.
To illustrate this, let's look again at the procedure invocation expression:
Для лучшего понимания, взглянем на пример вызова процедуры:
(string-length (string-append "/home" "/" "andrew"))
In the outermost expression, procedure is string-length and
arg1 is (string-append "/home" "/" "andrew").
Для последнего выражения procedure это string-length и arg1 это (string-append "/home" "/" "andrew").
string-length, which is a variable, gives a
procedure value that implements the expected behaviour for
"string-length".
(string-append "/home" "/" "andrew"), which is
another procedure invocation expression, means evaluating each of
string-append, which gives a procedure value that implements the
expected behaviour for "string-append"
"/home", which gives the string value "/home"
"/", which gives the string value "/"
"andrew", which gives the string value "andrew"
and then invoking the procedure value with this list of string values as
its arguments. The resulting value is a single string value that is the
concatenation of all the arguments, namely "/home/andrew".
string-length даёт нам процедурное значение (ведь string-length это
переменная, содержащая в себе процедуру определения длины строки)
(string-append "/home" "/" "andrew") (тоже вызов процедуры) :
string-append даёт нам процедурное значение, реализующее функцию "string-append" (объединение строк)
"/home" даёт нам строковое заначение "/home"
"/" даёт нам строковое заначение "/"
"andrew" даёт нам строковое заначение "andrew"
Затем вызывается процедурное значение (т.е. вызывается процедура string-append), которая принимает
три строковых параметра, а возвращает один ("/home/andrew").
In the evaluation of the outermost expression, the interpreter can now invoke the procedure value obtained from procedure with the value obtained from arg1 as its arguments. The resulting value is a numeric value that is the length of the argument string, which is 12.
В итоге, в процессе вычисления последнего выражения, интерпретатор вызовет
процедуру подсчёта длины строки (она известна в результате вычисления переменной string-length)
с аргументом, значение которого получено из arg1, в результате выполнения процедуры string-append.
Итоговое значение всего выражения - число 12, которое и является длиной объединённой строки.
> > далее > >