Pergunta

In most contexts, the concept of "interpolation" seems to be related to estimating unknown states from known ones, like video frames or data points.

From the Wikipedia entry on interpolation:

In the mathematical field of numerical analysis, interpolation is a type of estimation, a method of constructing new data points within the range of a discrete set of known data points.

In engineering and science, one often has a number of data points, obtained by sampling or experimentation, which represent the values of a function for a limited number of values of the independent variable. It is often required to interpolate, i.e., estimate the value of that function for an intermediate value of the independent variable.

And from the Wikipedia entry on interpolation (computer graphics):

In the context of live-action and computer animation, interpolation is inbetweening, or filling in frames between the key frames. It typically calculates the in-between frames through use of (usually) piecewise polynomial interpolation to draw images semi-automatically.

Now, from what I understand, string interpolation is the evaluation of an expression inside a string literal. From the Wikipedia entry on string interpolation:

In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values. It is a form of simple template processing or, in formal terms, a form of quasi-quotation (or logic substitution interpretation). String interpolation allows easier and more intuitive string formatting and content-specification compared with string concatenation.

What I don't get is what exactly is being interpolated during string interpolation. There's no estimation involved in the process, right? Am I interpreting these concepts in the wrong way? How are they related?

Foi útil?

Solução

The mathematical use of "interpolation" is not the only meaning. Quoting the Wiktionary entree on interpolate [emphasis from original]:

  1. (transitive, intransitive) To introduce (something) between other things; especially to insert (possibly spurious) words into a text.
  2. (mathematics) To estimate the value of a function between two points between which it is tabulated.
  3. (computing) During the course of processing some data, and in response to a directive in that data, to fetch data from a different source and process it in-line along with the original data.

String iterpolation is an example of meaning 1, not meaning 2.

Also notice that meaning 2 is derived from meaning 1: "to interpolate" is used to mean "insert a data point between two other datapoints (by means of estimation)".

Licenciado em: CC-BY-SA com atribuição
scroll top