Annotation of researchv10no/cmd/hoc/hoc.1, revision 1.1.1.1

1.1       root        1: .TH HOC 1
                      2: .CT 1 numbers
                      3: .SH NAME
                      4: hoc \(mi interactive floating point language
                      5: .SH SYNOPSIS
                      6: .B hoc
                      7: [
                      8: .I file ...
                      9: ]
                     10: .SH DESCRIPTION
                     11: .I Hoc
                     12: interprets a simple language for floating point arithmetic,
                     13: at about the level of Basic, with C-like syntax and
                     14: functions.
                     15: .PP
                     16: The named
                     17: .IR file s
                     18: are read and interpreted in order.
                     19: If no
                     20: .I file
                     21: is given or if
                     22: .I file
                     23: is
                     24: .L -
                     25: .I hoc
                     26: interprets the standard input.
                     27: .PP
                     28: .I Hoc
                     29: input consists of
                     30: .I expressions
                     31: and
                     32: .IR statements .
                     33: Expressions are evaluated and their results printed.
                     34: Statements, typically assignments and function or procedure
                     35: definitions, produce no output unless they explicitly call
                     36: .IR print .
                     37: .PP
                     38: Variable names have the usual syntax, including 
                     39: .LR _ ;
                     40: the name 
                     41: .L _
                     42: by itself contains the value of the last expression evaluated.
                     43: Certain variables are already initialized:
                     44: .TP
                     45: .B E
                     46: base of natural logs
                     47: .PD0
                     48: .TP
                     49: .B PI
                     50: .TP
                     51: .B PHI
                     52: golden ratio
                     53: .TP
                     54: .B GAMMA 
                     55: Euler's constant
                     56: .TP
                     57: .B DEG 
                     58: 180/PI, degrees per radian
                     59: .TP
                     60: .B PREC
                     61: maximum number of significant digits in output, initially 15;
                     62: .B PREC=0
                     63: gives shortest `exact' values.
                     64: .PD
                     65: .PP
                     66: Expressions are formed with these C-like operators, listed by
                     67: decreasing precedence.
                     68: .TP
                     69: .B ^
                     70: exponentiation
                     71: .TP
                     72: .B ! - ++ --
                     73: .TP
                     74: .B * / %
                     75: .TP
                     76: .B + -
                     77: .TP
                     78: .B > >= < <= == !=
                     79: .TP
                     80: .B &&
                     81: .TP
                     82: .B ||
                     83: .TP
                     84: .B = += -= *= /= %=
                     85: .PP
                     86: Built in functions include
                     87: .BR abs ,
                     88: .BR acos ,
                     89: .B atan
                     90: (one argument),
                     91: .BR cos ,
                     92: .BR cosh ,
                     93: .BR erf ,
                     94: .BR erfc ,
                     95: .BR exp ,
                     96: .BR gamma ,
                     97: .BR int ,
                     98: .BR log ,
                     99: .BR log10 ,
                    100: .BR sin ,
                    101: .BR sinh ,
                    102: .BR sqrt ,
                    103: .BR tan ,
                    104: and
                    105: .BR tanh .
                    106: The function
                    107: .B read(x)
                    108: reads a value into the variable
                    109: .BR x ;
                    110: the statement
                    111: .B print
                    112: prints a list of expressions that may include
                    113: string constants such as
                    114: .B \&\&\&"hello\en".
                    115: .PP
                    116: Control flow statements are
                    117: .BR if - else ,
                    118: .BR while ,
                    119: and
                    120: .BR for ,
                    121: with braces for grouping.
                    122: Newline ends a statement.
                    123: Backslash-newline is equivalent to a space.
                    124: .PP
                    125: Functions and procedures are introduced by the words
                    126: .B func
                    127: and
                    128: .BR proc ;
                    129: .B return
                    130: is used to return with a value from a function.
                    131: Within a function or procedure,
                    132: arguments are referred to as
                    133: .BR $1 ,
                    134: .BR $2 ,
                    135: etc.; all other variables are global.
                    136: .SH EXAMPLES
                    137: .EX
                    138: func gcd() {
                    139:        temp = abs($1) % abs($2)
                    140:        if(temp == 0) return abs($2)
                    141:        return gcd($2, temp)
                    142: }
                    143: for(i=1; i<12; i++) print gcd(i,12)
                    144: .EE
                    145: .SH "SEE ALSO"
                    146: .IR bc (1),
                    147: .IR dc (1)
                    148: .br
                    149: B. W. Kernighan and R. Pike,
                    150: .I
                    151: The Unix Programming Environment,
                    152: Prentice-Hall, 1984
                    153: .SH BUGS
                    154: Error recovery is imperfect within function and procedure definitions.
                    155: .br
                    156: The treatment of newlines is not exactly user-friendly.

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.