Вход/Регистрация
UNIX — универсальная среда программирования
вернуться

Керниган Брайан Уилсон

Шрифт:

< <= less, less or equal,

\&== != equal, not equal (all same precedence)

&& logical AND (both operands always evaluated)

|| logical OR (both operands always evaluated)

\&= assignment, right associative

.ТЕ

.ix table~of [hoc] operators

.PP

Functions, as described later, may be defined by the user.

Function arguments are expressions separated by commas.

There are also a number of built-in functions,

all of which take a single argument,

described in Table 2.

.TS

center, box;

с s

lfCW l.

\fBTable 2:\fP Built-in Functions

.sp .5

abs(x) @| x |@, absolute value of @x@

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)

  • Читать дальше
  • 1
  • ...
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • ...

Ебукер (ebooker) – онлайн-библиотека на русском языке. Книги доступны онлайн, без утомительной регистрации. Огромный выбор и удобный дизайн, позволяющий читать без проблем. Добавляйте сайт в закладки! Все произведения загружаются пользователями: если считаете, что ваши авторские права нарушены – используйте форму обратной связи.

Полезные ссылки

  • Моя полка

Контакты

  • chitat.ebooker@gmail.com

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