Чтение онлайн

на главную - закладки

Жанры

UNIX — универсальная среда программирования
Шрифт:

atan(x) arc tangent of @x@

cos(x) @cos (x)@, cosine of @x@

exp(x) @e sup x@, exponential of @x@

int(x) integer part of @x@, truncated towards zero

log(x) @log (x)@, logarithm base @e@ of @x@

log10(x) @log sub 10 (x)@, logarithm base 10 of @x@

sin(x) @sin (x)@, sine of @x@

sqrt(x) @sqrt x@, @x sup half@

.ТЕ

.ix table~of [hoc] functions

.PP

Logical expressions have value 1.0 (true) and 0.0 (false).

As in C,

any non-zero value is taken to be true.

As is always the case with floating point numbers,

equality comparisons are inherently suspect. .PP

.I Hoc

also has a few built-in constants, shown in Table 3.

.TS

center, box;

c s s

lfCW n l.

\fBTable 3:\fP Built-in Constants

.sp .5

DEG 57.29577951308232087680 @180/ pi@, degrees per radian

E 2.71828182845904523536 @e@, base of natural logarithms

GAMMA 0.57721566490153286060 @gamma@, Euler-Mascheroni constant

PHI 1.61803398874989484820 @( sqrt 5 +1)/2@, the golden ratio

PI 3.14159265358979323846 @pi@, circular transcendental number

.ТЕ

.ix table~of [hoc] constants

.NH

Statements and Control Flow

.PP

.I Hoc

statements have the following grammar:

.DS

.I

stmt: expr

 | variable = expr

 | procedure ( arglist )

 | while ( expr ) stmt

 | if ( expr ) stmt

 | if ( expr ) stmt else stmt

 | { stmtlist }

 | print expr-list

 | return optional-expr

stmtlist: \fR(nothing)\fI

 | stmlist stmt

.R

.DE

An assignment is parsed by default as a statement rather than

an expression, so assignments typed interactively

do not print their value.

.PP

Note that semicolons are not special to

.ix [hoc] input~format

@hoc@: statements are terminated by newlines.

This causes some peculiar behavior.

The following are legal

.IT if

statements:

.DS

.ft CW

if (x < 0) print(y) else print(z)

if (x < 0) {

 print(y)

} else {

 print(z)

}

.ft

.DE

In the second example, the braces are mandatory:

the newline after the

.I if

would terminate the statement and produce a syntax error were

the brace omitted.

.PP

The syntax and semantics of @hoc@

control flow facilities are basically the same as in C.

The

.I while

and

.I if

statements are just as in C, except there are no @break@ or

@continue@ statements.

.NH

Input and Output: @read@ and @print@

.PP

.ix [hoc] [read]~statement

.ix [hoc] [print]~statement

The input function @read@, like the other built-ins,

takes a single argument. Unlike the built-ins, though, the argument

is not ал expression: it is the name of a variable.

The next number (as defined above) is read from the standard input

and assigned to the named variable.

The return value of @read@ is 1 (true) if a value was read, and 0 (false)

if @read@ encountered end of file or an error.

.PP

Output is generated with the ©print© statement.

The arguments to @print@ are a comma-separated list of expressions

and strings in double quotes, as in C.

Newlines must be supplied;

they are never provided automatically by @print@.

.PP

Note that @read@ is a special built-in function, and therefore takes

Поделиться:
Популярные книги

Путь Шедара

Кораблев Родион
4. Другая сторона
Фантастика:
боевая фантастика
6.83
рейтинг книги
Путь Шедара

Гримуар темного лорда IX

Грехов Тимофей
9. Гримуар темного лорда
Фантастика:
попаданцы
альтернативная история
аниме
фэнтези
5.25
рейтинг книги
Гримуар темного лорда IX

Песня Сван

МакКаммон Роберт Рик
Фантастика:
ужасы и мистика
9.00
рейтинг книги
Песня Сван

Я до сих пор не бог. Книга XXXVII

Дрейк Сириус
37. Дорогой барон!
Фантастика:
аниме
попаданцы
5.00
рейтинг книги
Я до сих пор не бог. Книга XXXVII

Брусилов

Слезкин Юрий Львович
1. Русские полководцы
Проза:
роман
5.00
рейтинг книги
Брусилов

Буря

Эренбург Илья Григорьевич
Проза:
военная проза
советская классическая проза
6.25
рейтинг книги
Буря

Белые погоны

Лисина Александра
3. Гибрид
Фантастика:
фэнтези
попаданцы
технофэнтези
аниме
5.00
рейтинг книги
Белые погоны

Карл Маркс

Серебрякова Галина Иосифовна
342. Жизнь замечательных людей
Документальная литература:
биографии и мемуары
5.00
рейтинг книги
Карл Маркс

Ранчо

Стил Даниэла
Любовные романы:
современные любовные романы
7.71
рейтинг книги
Ранчо

Группа крови на рукаве

Вязовский Алексей
1. ГК
Фантастика:
боевая фантастика
попаданцы
альтернативная история
6.40
рейтинг книги
Группа крови на рукаве

Инженерный Парадокс 9

Cyberdawn
9. Инженерный Парадокс
Фантастика:
боевая фантастика
юмористическое фэнтези
попаданцы
5.00
рейтинг книги
Инженерный Парадокс 9

Кодекс Охотника. Книга V

Винокуров Юрий
5. Кодекс Охотника
Фантастика:
фэнтези
попаданцы
аниме
4.50
рейтинг книги
Кодекс Охотника. Книга V

Холод смерти

Макдональд Росс
11. Лью Арчер
Детективы:
крутой детектив
5.00
рейтинг книги
Холод смерти

Ваше Сиятельство 3

Моури Эрли
3. Ваше Сиятельство
Фантастика:
фэнтези
попаданцы
аниме
5.00
рейтинг книги
Ваше Сиятельство 3