ESC
No recent searches
Search by
Standard Library  /  Pervasives

Pervasives

This module is automatically imported into every Grain program. You can think of it as the global environment. Although it is automatically imported, it can still be imported manually.

Edit on GitHub
Added in 0.1.0 No other changes yet.
from "pervasives" include Pervasives

Values

Functions and constants included in the Pervasives module.

Pervasives.(!)

Added in 0.1.0 No other changes yet.
(!) : (bool: Bool) => Bool

Computes the logical NOT (!) of the given operand. Inverts the given Boolean value.

Parameters:

bool: The operand

Returns:

Bool: The inverted value

Examples:

!true // false
!false // true

Pervasives.(&&)

Added in 0.1.0 No other changes yet.
(&&) : (left: Bool, right: Bool) => Bool

Computes the logical AND (&&) of the given operands.

If the first operand is false, returns false without evaluating the second operand. If the first operand is true, returns the value of the second operand.

Parameters:

left: The first operand
right: The second operand

Returns:

Bool: The first operand if it is false or the value of the second operand otherwise

Pervasives.(||)

Added in 0.1.0 No other changes yet.
(||) : (left: Bool, right: Bool) => Bool

Computes the logical OR || of the given operands.

If the first operand is true, returns true without evaluating the second operand. If the first operand is false, returns the value of the second operand.

Parameters:

left: The first operand
right: The second operand

Returns:

Bool: The first operand if it is true or the value of the second operand otherwise

Pervasives.(==)

Added in 0.1.0 No other changes yet.
(==) : (value1: a, value2: a) => Bool

Check that two values are equal. This checks for structural equality, so it also works for comparing things like tuples and lists.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Bool: true if the values are structurally equal or false otherwise

Pervasives.(!=)

Added in 0.2.0 No other changes yet.
(!=) : (value1: a, value2: a) => Bool

Check that two values are not equal. This checks for structural equality, so it also works for comparing things like tuples and lists.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Bool: false if the values are structurally equal or true otherwise

Pervasives.is

Added in 0.1.0 No other changes yet.
is : (left: a, right: a) => Bool

Checks that two values are physically equal. Use this operator if you don’t need or want structural equality.

Parameters:

left: The first operand
right: The second operand

Returns:

Bool: true if the values are physically equal or false otherwise

Pervasives.isnt

Added in 0.2.0 No other changes yet.
isnt : (value1: a, value2: a) => Bool

Checks that two values are not physically equal. Use this operator if you don’t need or want structural equality.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Bool: false if the values are physically equal or true otherwise

Pervasives.(<)

Added in 0.1.0 No other changes yet.
(<) : (num1: Number, num2: Number) => Bool

Checks if the first operand is less than the second operand.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Bool: true if the first operand is less than the second operand or false otherwise

Pervasives.(>)

Added in 0.1.0 No other changes yet.
(>) : (num1: Number, num2: Number) => Bool

Checks if the first operand is greater than the second operand.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Bool: true if the first operand is greater than the second operand or false otherwise

Pervasives.(<=)

Added in 0.1.0 No other changes yet.
(<=) : (num1: Number, num2: Number) => Bool

Checks if the first operand is less than or equal to the second operand.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Bool: true if the first operand is less than or equal to the second operand or false otherwise

Pervasives.(>=)

Added in 0.1.0 No other changes yet.
(>=) : (num1: Number, num2: Number) => Bool

Checks if the first operand is greater than or equal to the second operand.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Bool: true if the first operand is greater than or equal to the second operand or false otherwise

Pervasives.compare

Added in 0.5.3 No other changes yet.
compare : (num1: a, num2: a) => Number

Compares the first argument to the second argument and produces an integer result. Provides a consistent ordering over all types and is suitable for sorting and other kinds of ordering. compare treats NaN differently than the other comparison operators in that it considers NaN equal to itself and smaller than any other number.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: A negative integer if the first operand is less than the second operand, 0 if they are equal, or a positive integer otherwise

Pervasives.(+)

Added in 0.1.0 No other changes yet.
(+) : (num1: Number, num2: Number) => Number

Computes the sum of its operands.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: The sum of the two operands

Pervasives.(-)

Added in 0.1.0 No other changes yet.
(-) : (num1: Number, num2: Number) => Number

Computes the difference of its operands.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: The difference of the two operands

Pervasives.(*)

Added in 0.1.0 No other changes yet.
(*) : (num1: Number, num2: Number) => Number

Computes the product of its operands.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: The product of the two operands

Pervasives.(/)

Added in 0.1.0 No other changes yet.
(/) : (num1: Number, num2: Number) => Number

Computes the quotient of its operands.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: The quotient of the two operands

Pervasives.(%)

Added in 0.1.0 No other changes yet.
(%) : (num1: Number, num2: Number) => Number

Computes the remainder of the division of the first operand by the second. The result will have the sign of the second operand.

Parameters:

num1: The first operand
num2: The second operand

Returns:

Number: The modulus of its operands

Pervasives.(**)

Added in 0.6.0
versionchanges
0.5.4Originally existed in Number module
(**) : (base: Number, power: Number) => Number

Computes the exponentiation of the given base and power.

Parameters:

base: The base number
power: The exponent number

Returns:

Number: The base raised to the given power

Pervasives.incr

Added in 0.1.0 No other changes yet.
incr : (value: Number) => Number

Increments the value by one.

Parameters:

value: The value to increment

Returns:

Number: The incremented value

Pervasives.decr

Added in 0.1.0 No other changes yet.
decr : (value: Number) => Number

Decrements the value by one.

Parameters:

value: The value to decrement

Returns:

Number: The decremented value

Pervasives.(++)

Added in 0.2.0 No other changes yet.
(++) : (str1: String, str2: String) => String

Concatenate two strings.

Parameters:

str1: The beginning string
str2: The ending string

Returns:

String: The combined string

Examples:

"Foo" ++ "Bar" == "FooBar"

Pervasives.lnot

Added in 0.2.0 No other changes yet.
lnot : (value: Number) => Number

Computes the bitwise NOT of the operand.

Parameters:

value: The operand

Returns:

Number: Containing the inverted bits of the operand

Pervasives.(&)

Added in 0.3.0
versionchanges
0.2.0Originally named `land`
0.3.0Renamed to `&`
(&) : (value1: Number, value2: Number) => Number

Computes the bitwise AND (&) on the given operands.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Number: Containing a 1 in each bit position for which the corresponding bits of both operands are 1

Pervasives.(|)

Added in 0.3.0
versionchanges
0.2.0Originally named `lor`
0.3.0Renamed to `|`
(|) : (value1: Number, value2: Number) => Number

Computes the bitwise OR (|) on the given operands.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Number: Containing a 1 in each bit position for which the corresponding bits of either or both operands are 1

Pervasives.(^)

Added in 0.3.0
versionchanges
0.1.0The `^` operator was originally an alias of `unbox`
0.2.0Originally named `lxor`
0.3.0Renamed to `^`
(^) : (value1: Number, value2: Number) => Number

Computes the bitwise XOR (^) on the given operands.

Parameters:

value1: The first operand
value2: The second operand

Returns:

Number: Containing a 1 in each bit position for which the corresponding bits of either but not both operands are 1

Pervasives.(<<)

Added in 0.3.0
versionchanges
0.2.0Originally named `lsl`
0.3.0Renamed to `<<`
(<<) : (value: Number, amount: Number) => Number

Shifts the bits of the value left by the given number of bits.

Parameters:

value: The value to shift
amount: The number of bits to shift by

Returns:

Number: The shifted value

Pervasives.(>>>)

Added in 0.3.0
versionchanges
0.2.0Originally named `lsr`
0.3.0Renamed to `>>>`
(>>>) : (value: Number, amount: Number) => Number

Shifts the bits of the value right by the given number of bits, preserving the sign bit.

Parameters:

value: The value to shift
amount: The amount to shift by

Returns:

Number: The shifted value

Pervasives.(>>)

Added in 0.3.0
versionchanges
0.2.0Originally named `asr`
0.3.0Renamed to `>>`
(>>) : (value: Number, amount: Number) => Number

Shifts the bits of the value right by the given number of bits.

Parameters:

value: The value to shift
amount: The amount to shift by

Returns:

Number: The shifted value

Pervasives.toString

Added in 0.1.0 No other changes yet.
toString : (value: a) => String

Converts the given operand to a string. Provides a better representation of data types if those types are provided from the module.

Parameters:

value: The operand

Returns:

String: The operand, as a string

Pervasives.print

Added in 0.1.0
versionchanges
0.6.0Added support for custom suffixes
print : (value: a, ?suffix: String) => Void

Prints the given operand to the console. Works for any type. Internally, calls toString on the operand, so a better representation of data type will be printed if those types are provided from the module.

Parameters:

value: The operand
?suffix: The string to print after the argument

Pervasives.ignore

Added in 0.1.0 No other changes yet.
ignore : (value: a) => Void

Accepts any value and always returns void.

Parameters:

value: The value to ignore

Pervasives.assert

Added in 0.1.0 No other changes yet.
assert : (condition: Bool) => Void

Assert that the given Boolean condition is true.

Parameters:

condition: The condition to assert

Throws:

AssertionError

  • When the condition is false

Examples:

assert 3 > 2
assert true

Pervasives.throw

Added in 0.3.0 No other changes yet.
throw : (exn: Exception) => a

Throw an exception. Currently, exceptions cannot be caught and will crash your program.

Parameters:

exn: The exception to be thrown

Returns:

a: Anything and nothing—your program won’t continue past a throw

Pervasives.fail

fail : (message: String) => a

Unconditionally throw a Failure exception with a message. Currently, Exceptions cannot be caught and will crash your program.

Parameters:

message: The reason for the failure

Returns:

a: Anything and nothing—your program won’t continue past a fail expression

Pervasives.identity

Added in 0.2.0 No other changes yet.
identity : (value: a) => a

Provides the operand untouched.

Parameters:

value: The value to return

Returns:

a: The value untouched

Pervasives.box

Added in 0.1.0 No other changes yet.
box : (value: a) => Box<a>

Creates a box containing the given initial value. Values inside a box can be swapped out with the := operator. Generally, let mut expressions are preferable to using a Box.

Parameters:

value: The initial value inside the box

Returns:

Box<a>: The box containing the initial value

Pervasives.unbox

Added in 0.1.0 No other changes yet.
unbox : (value: Box<a>) => a

Retrieves the current value from a box.

Parameters:

value: The box to unwrap

Returns:

a: The value inside the box

Sign up for farm-to-inbox developer news

You can unsubscribe at any time. Read our privacy policy.

Copyright © 2024 The Grain Programming Language