Nested function

Nested function

Fonction imbriquée

Une fonction imbriquée ou fonction interne est une fonction encapsulée dans une autre. Elle ne peut être appelée que par la fonction englobante ou par des fonctions imbriquées directement ou non dans la même fonction englobante.

En d'autres termes, la portée de la fonction imbriquée est limitée par la fonction englobante.

Exemples

Un exemple avec la syntaxe de Pascal :

 function E(x: integer): integer
 
     function F(y: integer): integer
     begin
         F := x + y
     end
 
 begin
     E := F(3)
 end

Et le même exemple avec une syntaxe façon C :

 int E(int x)
 {
     int F(int y)
     {
         return x + y;
     }
     return F(3);
 }

Remarque : Le langage C standard ne supporte pas cette construction. Mais certains compilateurs l'acceptent.

La fonction F est imbriquée dans E (notez que x est visible dans F, mais y est invisible en dehors de F).

Les fonctions imbriquées sont une forme d'encapsulation et sont utilisées pour diviser des tâches procédurales en sous-tâches qui n'ont de signification que locale. Elle permet d'éviter la pollution de l'espace global de noms par des noms de fonctions, variables... dont l'usage est restreint à une petite partie du programme.

Parmi les langages les plus connus qui supportent les fonctions imbriquées, il y a

En Scheme et la plupart des langages fonctionnels, les fonctions imbriquées sont une manière commune d'implanter des fonctions comportant des boucles. Une simple fonction imbriquée récursive ou récursion terminale est créée, qui se comporte comme la boucle principale, alors que la fonction englobante effectue les actions qui ne doivent être faites qu'une fois. Dans les cas plus complexes, plusieurs fonctions mutuellement récursives peuvent être créées comme des fonctions imbriquées.

Voir aussi

  • Portail de la programmation informatique Portail de la programmation informatique
Ce document provient de « Fonction imbriqu%C3%A9e ».

Wikimedia Foundation. 2010.

Contenu soumis à la licence CC-BY-SA. Source : Article Nested function de Wikipédia en français (auteurs)

Игры ⚽ Нужна курсовая?

Regardez d'autres dictionnaires:

  • Nested function — definitions can be compared to how a Matryoshka doll nests within larger versions of itself, in several levels. In computer programming, a nested function (or nested procedure/subroutine) is a function which is lexically (textually) encapsulated… …   Wikipedia

  • nested function — įdėtinė funkcija statusas T sritis informatika apibrėžtis ↑Funkcija, kurios ↑aprašas įdėtas į kitos funkcijos aprašą. atitikmenys: angl. nested function ryšiai: dar žiūrėk – aprašas dar žiūrėk – funkcija dar žiūrėk – funkcija dar žiūrėk –… …   Enciklopedinis kompiuterijos žodynas

  • Nested word — In computer science, more specifically in automata and formal language theory, nested words are a concept proposed by Alur and Madhusudan as a joint generalization of words, as traditionally used for modelling linearly ordered structures, and of… …   Wikipedia

  • Nested transaction — With reference to a database transaction, a nested transaction occurs when a new transaction is started by an instruction that is already inside an existing transaction. The new transaction is said to be nested within the existing transaction,… …   Wikipedia

  • Nested quotation — A nested quotation is a quotation that is encapsulated inside another quotation, forming a hierarchy with multiple levels. When focusing on a certain quotation, one must interpret it within its scope. Nested quotation can be used in literature… …   Wikipedia

  • Nested quote — A nested quote is a quote that is encapsulated inside another quote, forming a hierarchy with multiple levels. When focusing on a certain quote, one must interpret it within its scope. Nested quotes can be used in literature (as in nested… …   Wikipedia

  • Function prologue — In assembly language programming, the function prologue is a few lines of code which appear at the beginning of a function, which prepare the stack and registers for use within the function. Similarly, the function epilogue appears at the end of… …   Wikipedia

  • Ackermann function — In recursion theory, the Ackermann function or Ackermann Péter function is a simple example of a general recursive function that is not primitive recursive. General recursive functions are also known as computable functions. The set of primitive… …   Wikipedia

  • Closure (computer science) — In computer science, a closure (also lexical closure, function closure, function value or functional value) is a function together with a referencing environment for the non local variables of that function.[1] A closure allows a function to… …   Wikipedia

  • Call stack — In computer science, a call stack is a stack data structure that stores information about the active subroutines of a computer program. This kind of stack is also known as an execution stack, control stack, run time stack, or machine stack, and… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”