This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Nesting" computing – news ·newspapers ·books ·scholar ·JSTOR(June 2024) (Learn how and when to remove this message) |
Incomputing science andinformatics,nesting[1] is where information is organized in layers, or whereobjects contain other similar objects. It almost always refers toself-similar orrecursive structures in some sense.
Nesting can mean:
In aspreadsheet functions can benested one into another, making complex formulas. The function wizard of theOpenOffice.orgCalc application allows to navigate through multiple levels of nesting,[further explanation needed] letting the user to edit (and possibly correct) each one of them separately.
For example:
=IF(SUM(C8:G8)=0,"Y","N")
In thisMicrosoft Excel formula, the SUM function is nested inside the IF function. First, the formula calculates the sum of the numbers in the cells from C8 to G8. It then decides whether the sum is 0, and it displays the letter Y if the sum is 0, and the letter N if it is not.
Naturally, to allow the mathematical resolution of these chained (or better:nested) formulas, the inner expressions must be previously evaluated, and this outward direction is essential because the results that theinternal functions return are temporarily used as entry data for theexternal ones.
Due to the potential accumulation of parentheses in only one code line, editing and error detecting (ordebugging) can become somehowawkward. That is why modern programming environments -as well as spreadsheet programs- highlight in bold type the pair corresponding to the current editing position. The (automatic) balancing control of the opening and closing parenthesis is known asbrace match checking.
Instructured programming languages,nesting is related to theenclosing ofcontrol structures one into another, usually indicated through differentindentation levels within thesource code, as it is shown in this simpleBASIC function:
functionLookupCode(sCodeasstring)asintegerdimiReturnValueasintegerdimsLine,sPathasstringsPath="C:\Test.dsv"ifFileExists(sPath)thenopensPathforinputas#1dowhilenotEOF(1)lineinput#1,sLineifsCode=left(sLine,3)then'Action(s) to be carried outEndifloopclose#1EndifLookupCode=iReturnValueendfunction
In this small and simple example, the conditional block “if... then... end if” is nested inside the “do while... loop” one.
Some languages such asPascal andAda have no restrictions on declarations depending on the nesting level, allowing precisely nested subprograms or even nested packages (Ada). Here is an example of both (simplified from a real case):
-- Getting rid of the global variables issue (cannot be used in parallel)-- from a set of old sources, without the need to change that code's-- logic or structure.--procedureNesting_example_1istypeBuffer_typeisarray(Integerrange<>)ofInteger;procedureDecompress(compressed:inBuffer_type;decompressed:outBuffer_type)is-- Here are the legacy sources, translated:packageX_Globalsisindex_in,index_out:Integer;-- *** ^ These variables are local to Decompress.-- *** Now Decompress is task-safe.endX_Globals;-- Methods 1,2,3,... (specifications)packageX_Method_1isprocedureDecompress_1;endX_Method_1;-- Methods 1,2,3,... (code)packagebodyX_Method_1isuseX_Globals;procedureDecompress_1isbeginindex_in:=compressed'First;-- Here, the decompression code, method 1endDecompress_1;endX_Method_1;-- End of the legacy sourcesbeginX_Method_1.Decompress_1;endDecompress;test_in,test_out:Buffer_type(1..10_000);beginDecompress(test_in,test_out);endNesting_example_1;
Nesteddata structures are also commonly encountered in programming.
In thefunctional programming languages, such asLisp, alist data structure exists as does a simpleratom data structure.[2]
(ATOMS)
The atoms in the list are A, T, O, M, and S.
(((NESTED)LISTS)(CAN)(BE)UNNECESSARILY(COMPLEX))