Кіріспе
Аспекттік және функционалдық бағдарламалауда кеңес – басқа функциялар орындалған кезде оларды өзгертетін функциялар тобын сипаттайды; бұл бағдарламаның белгілі бір қосылу нүктесінде қолданылатын функция, әдіс немесе процедура.
Оқылуы
Кеңестер шатасуға себеп болуы мүмкін, себебі функцияға қолданылған кеңес, функцияның бастапқы анықтамасын іздеп, оны үйренуге тырысатын пайдаланушыға көрінбейді. Мұндай жағдайларда кеңес, INTERCAL тіліне қосылған, GOTO операторларын көп пайдаланудан туындайтын кодтың күрделенуін пародизациялауға арналған COMEFROM сияқты жұмыс істейді. Бірақ практикада мұндай мәселелер көбінесе туындамайды. Lisp пакеттері мен модульдерін дамытушылар мен күтушілер кеңестерді пайдаланбайды, өйткені олардың бастапқы кодтарын қалаған мүмкіндіктерді қосу үшін еркін өзгертуге болады, сондықтан функцияларға кеңес берудің қажеті жоқ. Кеңес тек төменгі деңгейдегі пайдаланушыларға негізгі кодтың бастапқы анықтамасын өзгертуді қажет етпей, әдепкі мінез-құлқына кейіннен өзгеріс енгізуге мүмкіндік береді.
Қолданылу
Кеңестердің бір түрі 1970-ші жылдардың соңы мен 1980-ші жылдардың басында C with Classes тілінің құрамына енді, атап айтқанда, сыныпта анықталған шақыру және қайтару функциялары, олар сынып мүше функцияларынан бұрын (сәйкесінше, кейін) шақырылатын. Бірақ, бұл мүмкіндік C++ тілінен алынып тасталды. Кеңестер Common Lisp Object System (CLOS) жүйесінің бөлігі болып табылады, яғни :бұрын, :кейін және :айнала әдістер түрінде, олар "стандартты әдіс комбинациясы" арқылы негізгі әдіспен біріктіріледі. Common Lisp жүйесінің іске асырылымдары кеңейтімдер ретінде кеңес беру мүмкіндігін ұсынады (CLOS үшін стандартты әдіс комбинациясынан өзге). LispWorks функцияларды, макростарды және CLOS әдістерін кеңес беруді қолдайды. EmacsLisp 1994 жылғы 19.28 нұсқасында кеңестерге қатысты кодты қосты.
Тарих
Келесі мәтін aosd discuss электрондық пошта тізіміндегі талқылаудан алынған. Паскаль Костанца мынаны қосты: "Кеңес" термині Уоррен Тейтельманның 1966 жылғы докторлық диссертациясында енгізген кеңес беру түсінігіне қатысты. Оның диссертациясының 3-тарауынан үзінді келтіріледі:
The term "advice" goes back to the term advising as introduced by Warren Teitelman in his PhD thesis in 1966. Here is a quote from Chapter 3 of his thesis:
Advising is the basic innovation in the model, and in the PILOT system. Advising consists of inserting new procedures at any or all of the entry or exit points to a particular procedure (or class of procedures). The procedures inserted are called "advice procedures" or simply "advice". Since each piece of advice is itself a procedure, it has its own entries and exits. In particular, this means that the execution of advice can cause the procedure that it modifies to be bypassed completely, e. g., by specifying as an exit from the advice one of the exits from the original procedure; or the advice may change essential variables and continue with the computation so that the original procedure is executed, but with modified variables. Finally, the advice may not alter the execution or affect the original procedure at all, e. g., it may merely perform some additional computation such as printing a message or recording history. Since advice can be conditional, the decision as to what is to be done can depend on the results of the computation up to that point. The principal advantage of advising is that the user need not be concerned about the details of the actual changes in his program, nor the internal representation of advice. He can treat the procedure to be advised as a unit , a single block, and make changes to it without concern for the particulars of this block. This may be contrasted with editing in which the programmer must be cognizant of the internal structure of the procedure. "Advising" found its way into BBN Lisp and later into Xerox PARC's Interlisp. It also found its way to Flavors, the first object oriented extension to Lisp developed at MIT. They were subsumed under the notion of method combination. Since method combination and macros are closely related, it's also interesting to note that the first macro system was described in 1963, three years before Warren Teitelman's PhD thesis.
Кеңес беру – модельдегі және PILOT жүйесіндегі негізгі жаңалық. Кеңес беру белгілі бір процедураға (немесе процедуралар класына) кіру немесе шығу нүктелерінің кез келгеніне немесе барлығына жаңа процедураларды қосудан тұрады. Қосылған процедуралар "кеңес процедуралары" немесе жай ғана "кеңес" деп аталады. Әрбір кеңес өзі де процедура болып табылады, сондықтан оның өз кірісі мен шығысы бар. Бұл кеңестің орындалуы өзгерткен процедураны толықтай айналып өтуі мүмкін, мысалы, кеңестен шығу ретінде бастапқы процедурадан шығудың біреуін көрсету арқылы; немесе кеңес маңызды айнымалыларды өзгертіп, есептеуді жалғастыра алады, нәтижесінде бастапқы процедура өзгертілген айнымалылармен орындалады. Соңында, кеңес орындалу барысын өзгерте алмайды немесе бастапқы процедураға ешқандай әсер етпеуі мүмкін, мысалы, ол жай ғана қосымша есептеулерді орындауы мүмкін, сияқты хабарламаны басып шығару немесе тарихты жазу. Кеңес шартты бола алатындықтан, не істеу керектігі туралы шешім сол уақытқа дейінгі есептеулердің нәтижелеріне байланысты болуы мүмкін. Кеңес берудің басты артықшылығы – пайдаланушы бағдарламадағы нақты өзгерістердің егжей-тегжейін немесе кеңестің ішкі бейнесін қарастырудың қажеті жоқ. Ол кеңес берілетін процедураны бірлік ретінде, жалғыз блок ретінде қарастыра алады және осы блок ерекшеліктеріне алаңдамай, оған өзгерістер енгізе алады. Бұл процедураның ішкі құрылымын білуді талап ететін өңдеуден өзгеше. "Кеңес беру" BBN Lisp-ке, кейін Xerox PARC-тің Interlisp-іне енді. Ол сондай-ақ MIT-те жасалған Lisp-тің алғашқы объектіге бағытталған кеңейтілуі Flavors-қа да жол тапты. Олар әдіс комбинациясы тұжырымына біріктірілді. Әдіс комбинациясы мен макростар тығыз байланысты болғандықтан, алғашқы макро жүйе 1963 жылы, Уоррен Тейтельманның докторлық диссертациясынан үш жыл бұрын сипатталғанын атап өту де қызықты.
The term "advice" goes back to the term advising as introduced by Warren Teitelman in his PhD thesis in 1966. Here is a quote from Chapter 3 of his thesis:
Advising is the basic innovation in the model, and in the PILOT system. Advising consists of inserting new procedures at any or all of the entry or exit points to a particular procedure (or class of procedures). The procedures inserted are called "advice procedures" or simply "advice". Since each piece of advice is itself a procedure, it has its own entries and exits. In particular, this means that the execution of advice can cause the procedure that it modifies to be bypassed completely, e. g., by specifying as an exit from the advice one of the exits from the original procedure; or the advice may change essential variables and continue with the computation so that the original procedure is executed, but with modified variables. Finally, the advice may not alter the execution or affect the original procedure at all, e. g., it may merely perform some additional computation such as printing a message or recording history. Since advice can be conditional, the decision as to what is to be done can depend on the results of the computation up to that point. The principal advantage of advising is that the user need not be concerned about the details of the actual changes in his program, nor the internal representation of advice. He can treat the procedure to be advised as a unit , a single block, and make changes to it without concern for the particulars of this block. This may be contrasted with editing in which the programmer must be cognizant of the internal structure of the procedure. "Advising" found its way into BBN Lisp and later into Xerox PARC's Interlisp. It also found its way to Flavors, the first object oriented extension to Lisp developed at MIT. They were subsumed under the notion of method combination. Since method combination and macros are closely related, it's also interesting to note that the first macro system was described in 1963, three years before Warren Teitelman's PhD thesis.