829 lines
26 KiB
Markdown
829 lines
26 KiB
Markdown
---
|
|
Title: C Complete Operator Reference
|
|
Prev: Complete Trait Reference
|
|
Next: Grammar Summary
|
|
---
|
|
|
|
## Appendix C: Complete Operator Reference
|
|
|
|
This appendix provides a complete alphabetical reference of all operators in the language.
|
|
|
|
### Operator List
|
|
|
|
`!=`, `%`, `*`, `+`, `-`, `/`, `<`, `<=`, `==`, `>`, `>=`, `^`, `abs`, `acos`, `asin`, `assert`, `at`, `atan`, `atan2`, `bitand`, `bitnot`, `bitor`, `bitxor`, `break`, `ceil`, `concat`, `continue`, `cos`, `depth`, `drop`, `dup`, `each`, `ends_with`, `enum`, `enumerate`, `eval`, `filter`, `find`, `floor`, `foldl`, `foldr`, `for`, `format`, `get`, `if`, `impl`, `implements`, `inher`, `lambda`, `length`, `ln`, `log`, `logb`, `map`, `match`, `max`, `mean`, `min`, `not`, `or`, `over`, `pick`, `rand`, `reduce`, `replace`, `reverse`, `roll`, `rot`, `round`, `seed`, `set`, `shl`, `shr`, `sin`, `slice`, `split`, `sqrt`, `starts_with`, `struct`, `substr`, `sum`, `swap`, `tan`, `trait`, `transpose`, `trim`, `type_of`, `union`, `while`, `window`, `zip`
|
|
|
|
### Alphabetical Operator Reference
|
|
|
|
#### !=
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Equatable Equatable -- bool)`
|
|
**Trait**: Equatable
|
|
**Description**: Test if two values are not equal.
|
|
**Example**: `5 3 != // => true`
|
|
**See Also**: ==, <, >
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### %
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Multiplyable Multiplyable -- Multiplyable)`
|
|
**Trait**: Multiplyable
|
|
**Description**: Remainder after division (modulo).
|
|
**Example**: `17 5 % // => 2`
|
|
**See Also**: /, *
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### *
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Multiplyable Multiplyable -- Multiplyable)`
|
|
**Trait**: Multiplyable
|
|
**Description**: Multiply two values.
|
|
**Example**: `5 6 * // => 30`
|
|
**See Also**: /, +, -
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### +
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Addable Addable -- Addable)`
|
|
**Trait**: Addable
|
|
**Description**: Add two values.
|
|
**Example**: `3 4 + // => 7`
|
|
**See Also**: -, *, /
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### -
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Addable Addable -- Addable)`
|
|
**Trait**: Addable
|
|
**Description**: Subtract second value from first.
|
|
**Example**: `10 3 - // => 7`
|
|
**See Also**: +, *, /
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### /
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Multiplyable Multiplyable -- Multiplyable)`
|
|
**Trait**: Multiplyable
|
|
**Description**: Divide first value by second.
|
|
**Example**: `20 4 / // => 5`
|
|
**See Also**: *, %, +
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### <
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Orderable Orderable -- bool)`
|
|
**Trait**: Orderable
|
|
**Description**: True if first value is less than second.
|
|
**Example**: `3 5 < // => true`
|
|
**See Also**: <=, >, >=
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### <=
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Orderable Orderable -- bool)`
|
|
**Trait**: Orderable
|
|
**Description**: True if first value is less than or equal to second.
|
|
**Example**: `5 5 <= // => true`
|
|
**See Also**: <, >, >=
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### ==
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Equatable Equatable -- bool)`
|
|
**Trait**: Equatable
|
|
**Description**: Test if two values are equal.
|
|
**Example**: `5 5 == // => true`
|
|
**See Also**: !=, <, >
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### >
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Orderable Orderable -- bool)`
|
|
**Trait**: Orderable
|
|
**Description**: True if first value is greater than second.
|
|
**Example**: `5 3 > // => true`
|
|
**See Also**: >=, <, <=
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### >=
|
|
**Operator Type**: Comparison
|
|
**Signature**: `(Orderable Orderable -- bool)`
|
|
**Trait**: Orderable
|
|
**Description**: True if first value is greater than or equal to second.
|
|
**Example**: `5 5 >= // => true`
|
|
**See Also**: >, <, <=
|
|
**Section**: 4.3 (Comparison Operators)
|
|
|
|
#### ^
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Exponentiable Exponentiable -- Exponentiable)`
|
|
**Trait**: Exponentiable
|
|
**Description**: Raise first value to power of second (exponentiation).
|
|
**Example**: `2 8 ^ // => 256`
|
|
**See Also**: log, ln, sqrt
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### abs
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Return absolute value of number.
|
|
**Example**: `-42 abs // => 42`
|
|
**See Also**: min, max
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### acos
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate arc cosine in radians.
|
|
**Example**: `1.0 acos // => 0.0`
|
|
**See Also**: cos, asin, atan
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### and
|
|
**Operator Type**: Logical
|
|
**Signature**: `(Logical Logical -- Logical)`
|
|
**Trait**: Logical
|
|
**Description**: Logical AND - returns first if falsy, else second.
|
|
**Example**: `true false and // => false`
|
|
**See Also**: or, not
|
|
**Section**: 4.4 (Logical Operators)
|
|
|
|
#### asin
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate arc sine in radians.
|
|
**Example**: `1.0 asin // => ~1.5708`
|
|
**See Also**: sin, acos, atan
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### assert
|
|
**Operator Type**: Testing
|
|
**Signature**: `(TokenString TokenString --)`
|
|
**Description**: Evaluate expression and condition, halt if condition is false.
|
|
**Example**: `{ 2 3 + } { 5 == } assert`
|
|
**See Also**: type_of, implements
|
|
**Section**: 11.3 (Testing and Assertions)
|
|
|
|
#### at
|
|
**Operator Type**: Container Access
|
|
**Signature**: `(Selectable<T> Size -- T)`
|
|
**Trait**: Selectable<T>
|
|
**Description**: Access element at given index.
|
|
**Example**: `[10 20 30] 1 at // => 20`
|
|
**See Also**: slice, length
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### atan
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate arc tangent in radians.
|
|
**Example**: `1.0 atan // => ~0.7854`
|
|
**See Also**: tan, atan2, asin
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### atan2
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Two-argument arc tangent using signs to determine quadrant.
|
|
**Example**: `1.0 1.0 atan2 // => ~0.7854`
|
|
**See Also**: atan, tan
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### bitand
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise Bitwise -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Bitwise AND of two values.
|
|
**Example**: `0xFF 0x0F bitand // => 0x0F`
|
|
**See Also**: bitor, bitxor, bitnot
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### bitnot
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Bitwise NOT (complement) of value.
|
|
**Example**: `0xFF bitnot // => (inverted bits)`
|
|
**See Also**: bitand, bitor, bitxor
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### bitor
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise Bitwise -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Bitwise OR of two values.
|
|
**Example**: `0xF0 0x0F bitor // => 0xFF`
|
|
**See Also**: bitand, bitxor, bitnot
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### bitxor
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise Bitwise -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Bitwise XOR of two values.
|
|
**Example**: `0xFF 0x0F bitxor // => 0xF0`
|
|
**See Also**: bitand, bitor, bitnot
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### break
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(--)`
|
|
**Description**: Exit the current loop immediately.
|
|
**Example**: `{ true } { condition { break } { } if } while`
|
|
**See Also**: continue, while, for
|
|
**Section**: 6.4 (Loop Control)
|
|
|
|
#### ceil
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Round number up to nearest integer.
|
|
**Example**: `3.14 ceil // => 4.0`
|
|
**See Also**: floor, round
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### concat
|
|
**Operator Type**: Container
|
|
**Signature**: `(Concatenable Concatenable -- Concatenable)`
|
|
**Trait**: Concatenable
|
|
**Description**: Concatenate two containers or strings.
|
|
**Example**: `[1 2 3] [4 5 6] concat // => [1 2 3 4 5 6]`
|
|
**See Also**: slice, reverse
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### continue
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(--)`
|
|
**Description**: Skip to the next iteration of the current loop.
|
|
**Example**: `1 10 { dup 2 % 0 == { continue } { print } if } for`
|
|
**See Also**: break, while, for
|
|
**Section**: 6.4 (Loop Control)
|
|
|
|
#### cos
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate cosine of angle in radians.
|
|
**Example**: `0.0 cos // => 1.0`
|
|
**See Also**: sin, tan, acos
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### depth
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(-- Size)`
|
|
**Trait**: Stackable
|
|
**Description**: Push current stack depth onto the stack.
|
|
**Example**: `1 2 3 depth // => 1 2 3 3`
|
|
**See Also**: pick, roll
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### drop
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Self --)`
|
|
**Trait**: Stackable
|
|
**Description**: Remove and discard the top item from the stack.
|
|
**Example**: `5 10 drop // => 5`
|
|
**See Also**: dup, swap
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### dup
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Self -- Self Self)`
|
|
**Trait**: Stackable
|
|
**Description**: Duplicate the top item on the stack.
|
|
**Example**: `5 dup // => 5 5`
|
|
**See Also**: drop, over
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### each
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> TokenString --)`
|
|
**Description**: Apply function to each element (side effects).
|
|
**Example**: `[1 2 3] { print } each`
|
|
**See Also**: map, filter, reduce
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### ends_with
|
|
**Operator Type**: String
|
|
**Signature**: `(String String -- bool)`
|
|
**Trait**: String
|
|
**Description**: Check if string ends with given suffix.
|
|
**Example**: `"hello" "lo" ends_with // => true`
|
|
**See Also**: starts_with, find
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### enum
|
|
**Operator Type**: Definition
|
|
**Signature**: `(TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Define an enumeration type.
|
|
**Example**: `{ Pending: Active: Complete: } ::Status enum`
|
|
**See Also**: struct, union, trait
|
|
**Section**: 7.3 (Enums)
|
|
|
|
#### enumerate
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<T> -- ArrayOf<Pair<Size T>>)`
|
|
**Description**: Add indices to array elements.
|
|
**Example**: `["a" "b" "c"] enumerate // => [[0 "a"] [1 "b"] [2 "c"]]`
|
|
**See Also**: zip, map
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### eval
|
|
**Operator Type**: Meta
|
|
**Signature**: `(TokenString --)`
|
|
**Trait**: Implementable
|
|
**Description**: Parse and execute TokenString as code.
|
|
**Example**: `"2 3 +" eval // => 5`
|
|
**See Also**: lambda
|
|
**Section**: 11.1 (Dynamic Code Evaluation)
|
|
|
|
#### filter
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> TokenString -- ArrayOf<T>)`
|
|
**Description**: Keep only elements matching predicate.
|
|
**Example**: `[1 2 3 4 5] { 2 % 0 == } filter // => [2 4]`
|
|
**See Also**: map, reduce, each
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### find
|
|
**Operator Type**: String
|
|
**Signature**: `(String String -- Option<Size>)`
|
|
**Trait**: String
|
|
**Description**: Find position of substring.
|
|
**Example**: `"hello world" "world" find // => Option::Some(6)`
|
|
**See Also**: starts_with, ends_with
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### floor
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Round number down to nearest integer.
|
|
**Example**: `3.14 floor // => 3.0`
|
|
**See Also**: ceil, round
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### fn
|
|
**Operator Type**: Definition
|
|
**Signature**: `(TypeTuple TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Define a function.
|
|
**Example**: `(Number -- Number) { dup * } ::square fn`
|
|
**See Also**: lambda, trait, impl
|
|
**Section**: 5.2 (Defining Functions)
|
|
|
|
#### foldl
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> U TokenString -- U)`
|
|
**Description**: Left fold array with accumulator function.
|
|
**Example**: `[1 2 3 4] 0 { + } foldl // => 10`
|
|
**See Also**: foldr, reduce
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### foldr
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> U TokenString -- U)`
|
|
**Description**: Right fold array with accumulator function.
|
|
**Example**: `[1 2 3 4] 0 { + } foldr // => 10`
|
|
**See Also**: foldl, reduce
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### for
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(Size Size TokenString --)`
|
|
**Description**: Loop from start to end, pushing counter each iteration.
|
|
**Example**: `1 10 { dup print } for`
|
|
**See Also**: while, break, continue
|
|
**Section**: 6.3 (For Loops)
|
|
|
|
#### format
|
|
**Operator Type**: String
|
|
**Signature**: `(String Iterable<Stringifiable> -- String)`
|
|
**Trait**: String
|
|
**Description**: Format string with values, replacing placeholders.
|
|
**Example**: `"x=%d, y=%d" [5 10] format // => "x=5, y=10"`
|
|
**See Also**: to_str, concat
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### get
|
|
**Operator Type**: Struct Access
|
|
**Signature**: `(Struct Identifier -- FieldValue)`
|
|
**Description**: Get field value from struct (consumes struct and field identifier).
|
|
**Example**: `point ::x get`
|
|
**See Also**: set
|
|
**Section**: 7.1 (Structs)
|
|
|
|
#### if
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(bool TokenString TokenString --)`
|
|
**Description**: Conditional execution - execute first block if true, second if false.
|
|
**Example**: `x 0 > { "positive" print } { "negative" print } if`
|
|
**See Also**: match, while
|
|
**Section**: 6.1 (Conditionals)
|
|
|
|
#### impl
|
|
**Operator Type**: Definition
|
|
**Signature**: `(Identifier TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Implement a trait for a type.
|
|
**Example**: `::Addable { ... } ::Point impl`
|
|
**See Also**: trait, inher
|
|
**Section**: 9.3 (Implementing Traits)
|
|
|
|
#### implements
|
|
**Operator Type**: Reflection
|
|
**Signature**: `(Self Identifier -- bool)`
|
|
**Description**: Check if value's type implements a specific trait.
|
|
**Example**: `42 ::Addable implements // => true`
|
|
**See Also**: type_of, assert
|
|
**Section**: 11.4 (Reflection)
|
|
|
|
#### inher
|
|
**Operator Type**: Definition
|
|
**Signature**: `(ArrayOf<Identifier> Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Declare trait inheritance.
|
|
**Example**: `[ ::Orderable ::Equatable ] ::Comparable inher`
|
|
**See Also**: trait, impl
|
|
**Section**: 9.4 (Trait Inheritance)
|
|
|
|
#### lambda
|
|
**Operator Type**: Meta
|
|
**Signature**: `(TokenString -- Callable)`
|
|
**Trait**: Implementable
|
|
**Description**: Convert TokenString to callable code block.
|
|
**Example**: `{ dup * } lambda ::square swap`
|
|
**See Also**: eval, fn
|
|
**Section**: 5.6 (Lambda Functions)
|
|
|
|
#### length
|
|
**Operator Type**: Container
|
|
**Signature**: `(Sized -- i64)`
|
|
**Trait**: Sized
|
|
**Description**: Get the number of elements in a container.
|
|
**Example**: `[1 2 3 4 5] length // => 5`
|
|
**See Also**: at, slice
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### ln
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Logarithmic -- Logarithmic)`
|
|
**Trait**: Logarithmic
|
|
**Description**: Natural logarithm (base e).
|
|
**Example**: `2.718 ln // => 1.0`
|
|
**See Also**: log, logb, ^
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### log
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Logarithmic -- Logarithmic)`
|
|
**Trait**: Logarithmic
|
|
**Description**: Logarithm base 10.
|
|
**Example**: `100 log // => 2.0`
|
|
**See Also**: ln, logb, ^
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### logb
|
|
**Operator Type**: Arithmetic
|
|
**Signature**: `(Logarithmic Logarithmic -- Logarithmic)`
|
|
**Trait**: Logarithmic
|
|
**Description**: Logarithm with custom base.
|
|
**Example**: `8 2 logb // => 3.0`
|
|
**See Also**: log, ln, ^
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### map
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> TokenString -- ArrayOf<U>)`
|
|
**Description**: Transform each element with function.
|
|
**Example**: `[1 2 3 4] { 2 * } map // => [2 4 6 8]`
|
|
**See Also**: filter, reduce, each
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### match
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(Value TokenString --)`
|
|
**Description**: Pattern match value against multiple patterns.
|
|
**Example**: `opt { Some(x) => { x print } None => { "Nothing" print } } match`
|
|
**See Also**: if
|
|
**Section**: 6.5 (Pattern Matching)
|
|
|
|
#### max
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Return the maximum of two values.
|
|
**Example**: `3 5 max // => 5`
|
|
**See Also**: min, abs
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### mean
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<Number> -- f64)`
|
|
**Description**: Calculate average of numeric array elements.
|
|
**Example**: `[1 2 3 4 5] mean // => 3.0`
|
|
**See Also**: sum, reduce
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### min
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Return the minimum of two values.
|
|
**Example**: `3 5 min // => 3`
|
|
**See Also**: max, abs
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### not
|
|
**Operator Type**: Logical
|
|
**Signature**: `(Logical -- Logical)`
|
|
**Trait**: Logical
|
|
**Description**: Logical NOT - inverts truthiness.
|
|
**Example**: `false not // => true`
|
|
**See Also**: and, or
|
|
**Section**: 4.4 (Logical Operators)
|
|
|
|
#### or
|
|
**Operator Type**: Logical
|
|
**Signature**: `(Logical Logical -- Logical)`
|
|
**Trait**: Logical
|
|
**Description**: Logical OR - returns first if truthy, else second.
|
|
**Example**: `true false or // => true`
|
|
**See Also**: and, not
|
|
**Section**: 4.4 (Logical Operators)
|
|
|
|
#### over
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Self Self -- Self Self Self)`
|
|
**Trait**: Stackable
|
|
**Description**: Copy the second item to the top of the stack.
|
|
**Example**: `5 10 over // => 5 10 5`
|
|
**See Also**: dup, swap, rot
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### pick
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Size -- Self)`
|
|
**Trait**: Stackable
|
|
**Description**: Copy nth item to top (0 = top, 1 = second, etc.).
|
|
**Example**: `1 2 3 4 2 pick // => 1 2 3 4 2`
|
|
**See Also**: roll, depth
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### rand
|
|
**Operator Type**: Randomness
|
|
**Signature**: `(-- f64)`
|
|
**Description**: Generate random f64 in range [0.0, 1.0).
|
|
**Example**: `rand // => 0.7234...`
|
|
**See Also**: seed
|
|
**Section**: 4.6 (Randomness)
|
|
|
|
#### reduce
|
|
**Operator Type**: Array Combinator
|
|
**Signature**: `(ArrayOf<T> T TokenString -- T)`
|
|
**Description**: Fold array with accumulator function.
|
|
**Example**: `[1 2 3 4] 0 { + } reduce // => 10`
|
|
**See Also**: map, filter, foldl
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### replace
|
|
**Operator Type**: String
|
|
**Signature**: `(String String String -- String)`
|
|
**Trait**: String
|
|
**Description**: Replace all occurrences of substring with replacement.
|
|
**Example**: `"hello world" "world" "Stack" replace // => "hello Stack"`
|
|
**See Also**: split, concat
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### reverse
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<T> -- ArrayOf<T>)`
|
|
**Description**: Reverse order of array elements.
|
|
**Example**: `[1 2 3] reverse // => [3 2 1]`
|
|
**See Also**: transpose, concat
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### roll
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Size Size --)`
|
|
**Trait**: Stackable
|
|
**Description**: Rotate n items, times times.
|
|
**Example**: `1 2 3 4 3 1 roll // => 1 3 4 2`
|
|
**See Also**: rot, pick
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### rot
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Self Self Self -- Self Self Self)`
|
|
**Trait**: Stackable
|
|
**Description**: Rotate the top three items.
|
|
**Example**: `1 2 3 rot // => 2 3 1`
|
|
**See Also**: swap, roll
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### round
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Round number to nearest integer.
|
|
**Example**: `3.7 round // => 4.0`
|
|
**See Also**: floor, ceil
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### seed
|
|
**Operator Type**: Randomness
|
|
**Signature**: `(u64 --)`
|
|
**Description**: Seed the random number generator with specific value.
|
|
**Example**: `12345 seed`
|
|
**See Also**: rand
|
|
**Section**: 4.6 (Randomness)
|
|
|
|
#### set
|
|
**Operator Type**: Struct Access
|
|
**Signature**: `(Value Identifier -- Struct)`
|
|
**Description**: Set field value in struct (consumes value and field identifier).
|
|
**Example**: `15.0 ::x set`
|
|
**See Also**: get
|
|
**Section**: 7.1 (Structs)
|
|
|
|
#### shl
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise Size -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Shift bits left by n positions.
|
|
**Example**: `4 2 shl // => 16`
|
|
**See Also**: shr, bitand, bitor
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### shr
|
|
**Operator Type**: Bitwise
|
|
**Signature**: `(Bitwise Size -- Bitwise)`
|
|
**Trait**: Bitwise
|
|
**Description**: Shift bits right by n positions.
|
|
**Example**: `16 2 shr // => 4`
|
|
**See Also**: shl, bitand, bitor
|
|
**Section**: 4.5 (Bitwise Operators)
|
|
|
|
#### sin
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate sine of angle in radians.
|
|
**Example**: `0.0 sin // => 0.0`
|
|
**See Also**: cos, tan, asin
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### slice
|
|
**Operator Type**: Container
|
|
**Signature**: `(Sliceable Size Size -- Sliceable)`
|
|
**Trait**: Sliceable
|
|
**Description**: Extract elements from start to end index.
|
|
**Example**: `[10 20 30 40] 1 3 slice // => [20 30]`
|
|
**See Also**: at, length
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### split
|
|
**Operator Type**: String
|
|
**Signature**: `(String String -- ArrayOf<String>)`
|
|
**Trait**: String
|
|
**Description**: Split string by delimiter.
|
|
**Example**: `"a,b,c" "," split // => ["a" "b" "c"]`
|
|
**See Also**: join, substr
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### sqrt
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate square root.
|
|
**Example**: `16 sqrt // => 4.0`
|
|
**See Also**: ^
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### starts_with
|
|
**Operator Type**: String
|
|
**Signature**: `(String String -- bool)`
|
|
**Trait**: String
|
|
**Description**: Check if string starts with given prefix.
|
|
**Example**: `"hello" "hel" starts_with // => true`
|
|
**See Also**: ends_with, find
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### struct
|
|
**Operator Type**: Definition
|
|
**Signature**: `(TypeTuple TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Define a struct type.
|
|
**Example**: `(T T --) { x: y: } ::Point<T> struct`
|
|
**See Also**: union, enum, get, set
|
|
**Section**: 7.1 (Structs)
|
|
|
|
#### substr
|
|
**Operator Type**: String
|
|
**Signature**: `(String Size Size -- String)`
|
|
**Trait**: String
|
|
**Description**: Extract substring from start to end index.
|
|
**Example**: `"hello" 1 3 substr // => "el"`
|
|
**See Also**: slice, split
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### sum
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<Number> -- Number)`
|
|
**Description**: Sum all numeric elements in array.
|
|
**Example**: `[1 2 3 4 5] sum // => 15`
|
|
**See Also**: mean, reduce
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### swap
|
|
**Operator Type**: Stack Manipulation
|
|
**Signature**: `(Self Self -- Self Self)`
|
|
**Trait**: Stackable
|
|
**Description**: Swap the top two items on the stack.
|
|
**Example**: `5 10 swap // => 10 5`
|
|
**See Also**: dup, rot
|
|
**Section**: 4.1 (Stack Operations)
|
|
|
|
#### tan
|
|
**Operator Type**: Mathematical
|
|
**Signature**: `(Math -- Math)`
|
|
**Trait**: Math
|
|
**Description**: Calculate tangent of angle in radians.
|
|
**Example**: `0.0 tan // => 0.0`
|
|
**See Also**: sin, cos, atan
|
|
**Section**: 4.2 (Arithmetic Operators)
|
|
|
|
#### trait
|
|
**Operator Type**: Definition
|
|
**Signature**: `(TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Define a new trait.
|
|
**Example**: `{ (Self -- ) draw: } ::Drawable trait`
|
|
**See Also**: impl, inher
|
|
**Section**: 9.2 (Defining Traits)
|
|
|
|
#### transpose
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<ArrayOf<T>> -- ArrayOf<ArrayOf<T>>)`
|
|
**Description**: Transpose a 2D array (swap rows and columns).
|
|
**Example**: `[[1 2] [3 4]] transpose // => [[1 3] [2 4]]`
|
|
**See Also**: reverse
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### trim
|
|
**Operator Type**: String
|
|
**Signature**: `(String -- String)`
|
|
**Trait**: String
|
|
**Description**: Remove leading and trailing whitespace.
|
|
**Example**: `" hello " trim // => "hello"`
|
|
**See Also**: split, replace
|
|
**Section**: 11.5 (String Operations)
|
|
|
|
#### type_of
|
|
**Operator Type**: Reflection
|
|
**Signature**: `(Self -- Identifier)`
|
|
**Description**: Return the type of a value as an identifier literal.
|
|
**Example**: `42 type_of // => ::i64`
|
|
**See Also**: implements, assert
|
|
**Section**: 11.4 (Reflection)
|
|
|
|
#### union
|
|
**Operator Type**: Definition
|
|
**Signature**: `(TypeTuple TokenString Identifier --)`
|
|
**Trait**: Implementable
|
|
**Description**: Define a union type with tagged variants.
|
|
**Example**: `(T --) { Some(T) None } ::Option<T> union`
|
|
**See Also**: struct, enum, match
|
|
**Section**: 7.2 (Unions)
|
|
|
|
#### while
|
|
**Operator Type**: Control Flow
|
|
**Signature**: `(TokenString TokenString --)`
|
|
**Description**: Loop while condition is truthy, executing body each iteration.
|
|
**Example**: `{ dup 10 < } { dup print 1 + } while`
|
|
**See Also**: for, break, continue, if
|
|
**Section**: 6.2 (While Loops)
|
|
|
|
#### window
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<T> Size -- ArrayOf<ArrayOf<T>>)`
|
|
**Description**: Create sliding windows of given size.
|
|
**Example**: `[1 2 3 4] 2 window // => [[1 2] [2 3] [3 4]]`
|
|
**See Also**: slice
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
#### zip
|
|
**Operator Type**: Array
|
|
**Signature**: `(ArrayOf<T> ArrayOf<U> -- ArrayOf<Pair<T U>>)`
|
|
**Description**: Combine two arrays element-wise into pairs.
|
|
**Example**: `[1 2 3] [4 5 6] zip // => [[1 4] [2 5] [3 6]]`
|
|
**See Also**: enumerate, map
|
|
**Section**: 7.4 (Arrays)
|
|
|
|
---
|