UNIX — универсальная среда программирования
UNIX — универсальная среда программирования читать книгу онлайн
В книге американских авторов — разработчиков операционной системы UNIX — блестяще решена проблема автоматизации деятельности программиста, системной поддержки его творчества, выходящей за рамки языков программирования. Профессионалам открыт богатый "встроенный" арсенал системы UNIX. Многочисленными примерами иллюстрировано использование языка управления заданиями
shell.
Для программистов-пользователей операционной системы UNIX.
Внимание! Книга может содержать контент только для совершеннолетних. Для несовершеннолетних чтение данного контента СТРОГО ЗАПРЕЩЕНО! Если в книге присутствует наличие пропаганды ЛГБТ и другого, запрещенного контента - просьба написать на почту [email protected] для удаления материала
.I.ta 1ifunction: func name() stmtprocedure: proc name() stmt.R.DE.I namemay be the name of any variable (em built-in functions are excluded.The definition, up to the opening brace or statement,must be on one line, as with the.I ifstatements above..PPUnlike C,the body of a function or procedure may be any statement, notnecessarily a compound (brace-enclosed) statement.Since semicolons have no meaning in @[email protected],a null procedure body is formed by an empty pair of braces..PPFunctions and procedures may take arguments, separated by commas,when invoked. Arguments are referred to as in the shell:.ix [hoc] arguments.IT $3refers to the third (1-indexed) argument.They are passed by value and within functionsare semantically equivalent to variables.It is an error to refer to an argument numbered greater than thenumber of arguments passed to the routine. The error checkingis done dynamically, however, so a routine may have variable numbersof arguments if initial arguments affect the number of argumentsto be referenced (as in C's @[email protected])..PPFunctions and procedures may recurse, but the stack has limited depth(about a hundred calls). The following shows a.Ihocdefinition of Ackermann's function:.ix Ackermann's~function.DS.ft CW.ix [ack]~function.S $ "hoc.S "func ack() {.S " if ($1 == 0) return $2+1.S " if ($2 == 0) return ack($1-1, 1).S " return ack($1-1, ack($1, $2-1)).S "}.S "ack(3, 2) 29.S "ack(3, 3) 61.S "ack(3, 4)hoc: stack too deep near line 8&....ft.DE.bp.NHExamples.PPStirling's~formula:.ix Stirling's~formula.EQn! ~(ap~ sqrt {2n pi} (n/e) sup n (1+ 1 over 12n ).EN.DS.ft CW.S $ hoc.S "func stirl() {.S " return sqrt(2*$1*PI) * ($1/E)"$1*(1 + 1/(12*$1)) .S "}.S "stirl(10) 3628684.7.S stirl(20) 2.4328818e+18.ft R.DE.PPFactorial function, @[email protected]:.ix [fac]~function.DS. S "func fac() if ($1 <= 0) return 1 else return $1 * fac($1-1).ft R.DE.PPRatio of factorial to Stirling approximation:.DS.S "i = 9.S "while ((i = i+1) <= 20) {.S print i, " ", fac(i)/stirl(i), "en".S "} .ft CW10 1.000031811 1.000026512 1.000022413 1.000019214 1.000016615 1.000014616 1.000012817 1.000011418 1.000010219 1.000009220 1.0000083.ft.DE3.7.14
hoc.y%{#include "hoc.h"#define code2(c1,c2) code(c1); code(c2)#define code3(c1,c2,c3) code(c1); code(c2); code(c3)%}%union { Symbol *sym; /* symbol table pointer */ Inst *inst; /* machine instruction */
