SCIP

1.2 Elements of Programming

Every powerful language has three such mechanisms:

  1. primitive expressions and statements, which represent the simplest building blocks that the language provides,

  2. means of combination, by which compound elements are built from simpler ones, and

  3. means of abstraction, by which compound elements can be named and manipulated as units.

In programming, we deal with two kinds of elements: functions and data. Informally, data is stuff that we want to manipulate, and functions describe the rules for manipulating the data. Thus, any powerful programming language should be able to describe primitive data and primitive functions, as well as have some methods for combining and abstracting both functions and data.

Выражения

  • Язык программирования дает возможность записывать простые выражения используя значения и встроенные операторы.

  • call-выражение (call-expression) - это выражение вызова функции. Это наиболее обобщенный вариант выражения т.к. может принимать и произвольное число аргументов, так и сами аргументы могут быть результатами других функций, так и сам может содержать другие функции.

>>> max(7.5, 9.5)
>>> max(1, -2, 3, -4)
>>> max(min(1, -2), min(pow(3, 5), -4))
  • В Python функции импортируются в текущее пространство имен при помощи import-выражения:

>>> from math import sqrt
>>> from operator import add, sub, mul
  • Язык программирования позволяет использовать имена для ображения к computational object.

Assignment is our simplest means of abstraction, for it allows us to use simple names to refer to the results of compound operations. In this way, complex programs are constructed by building, step by step, computational objects of increasing complexity.

  • Окружение - это все имена, доступные в данный момент в программе. Бессмысленно говорить о программе без учета ее окружения.

Вычисление call-выражений: 1. Evaluate the operator and operand subexpressions, then 2. Apply the function that is the value of the operator subexpression to the arguments that are the values of the operand subexpressions.

We take care of the primitive cases by stipulating that

  • A numeral evaluates to the number it names,

  • A name evaluates to the value associated with that name in the current environment.

Last updated