Skip to content

Instantly share code, notes, and snippets.

@smurphy8
Last active March 24, 2023 01:11
Show Gist options
  • Save smurphy8/f6ca49e895c543292caa91800fac50a3 to your computer and use it in GitHub Desktop.
Save smurphy8/f6ca49e895c543292caa91800fac50a3 to your computer and use it in GitHub Desktop.

Inferno Programming Language - Function Reference

Comments

Inferno supports two types of comments, // for single-line comments and /* ... */ for multi-line comments. Numeric Literals

Inferno supports both integer and floating-point literals. The type of the literal is inferred by the context in which it appears.

Examples:


3   // integer literal
-3  // negative integer literal
3.0 // floating-point literal
-3.0 // negative floating-point literal

Arithmetic

Inferno supports basic arithmetic operations on numeric types.

Addition

Addition is done using the + operator.

Example:

3 + 4 // evaluates to 7

Subtraction

Subtraction is done using the - operator.

Example:

3.0 - 2 // evaluates to 1.0

Division

Division is done using the / operator.

Example:

3.0 / 2 // evaluates to 1.5

Multiplication

Multiplication is done using the * operator.

3.14 * recip 3.14 // evaluates to 1.0

Power

Inferno supports exponentiation using the ** operator. The exp function calculates the exponential function and the ln function calculates the natural logarithm.

Examples:

14 ** 5 // evaluates to 537824
1.4 ** 2.5 // evaluates to 1.9843134832984438
exp 0 // evaluates to 1.0
exp (ln 1) // evaluates to 1.0

Logs

Inferno supports logarithmic functions. log calculates the logarithm in base 10, logBase calculates the logarithm with a given base, and ln calculates the natural logarithm.

Examples:

log 10 // evaluates to 1.0
logBase 10 100 // evaluates to 2.0
ln (exp 1) // evaluates to 1.0

Square Root

Inferno provides the sqrt function to calculate the square root of a number.

Examples:

sqrt 1.425 // evaluates to 1.1941939201359381
sqrt (-1.425) // evaluates to NaN

Negation

Inferno provides the unary - operator for negation.

Examples:

let x = 1425 in -x // evaluates to -1425
let x = 1.425 in -x // evaluates to -1.425

Absolute Value

Inferno provides the abs function for calculating the absolute value of a number.

Examples:

abs 1425 // evaluates to 1425
abs (-1425) // evaluates to 1425
abs 14.25 // evaluates to 14.25
abs (-14.25) // evaluates to 14.25

Modulus

Inferno provides the % operator for calculating the modulus of two integers.

Examples:

1425 % 5 // evaluates to 0
1426 % 5 // evaluates to 1
-3 % 5 // evaluates to 2

Floor and Ceiling

Inferno provides the floor and ceiling functions for rounding to the nearest integer in the appropriate direction. The round function rounds to the nearest integer, while roundTo and

Array Syntax

The language supports a variety of expressions that can be used to build complex programs with Array. Here is an example of an expression:


Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])

This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.

Expressions

Here are a few examples of expressions that can be evaluated using the language:

Array.sum

Array.sum (Array.keepSomes [Some 3.0, None, Some 4.0])

This expression calculates the sum of an array after filtering out the None values. The expected result of this expression is 7.0, which is a double.

h## Array.findFirstSome

Array.findFirstSome [None, Some 3.0, None, Some 4.0]

This expression finds the first element in an array that is not None. The expected result of this expression is a value that represents the found element.

Array.findLastSome


Array.findLastSome [None, Some 3.0, None, Some 4.0]

This expression finds the last element in an array that is not None. The expected result of this expression is a value that represents the found element.

Array.findFirstAndLastSome

Array.findFirstAndLastSome [None, Some 3.0, None, Some 4.0]

This expression finds both the first and last element in an array that is not None. The expected result of this expression is a tuple of two values, where each value represents the found element.

Option.map

Option.map (fun x -> x + 2) (Some 4.0)

This expression maps the given function to the value of the option, if it exists. The expected result of this expression is a value that represents the result of the mapping operation.

fromOption

fromOption 0 (Some 4.0)

This expression extracts the value of an option, or returns the default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.

Operator "?"

(Some 4.0) ? 0

This expression returns the value of the option if it exists, or the given default value if the option is None. The expected result of this expression is the value of the option or the default value, depending on the value of the option.

Option.reduce

Option.reduce (fun d -> d + 2) 0.0 (Some 4.0)

This expression applies the given binary function to the elements of the option and returns the result. The expected result of this expression is a value that represents the result of the reduction operation.

Bitwise Operations

0x5 && 0x9

This expression performs a bitwise AND operation on two values. The expected result of this expression is 1, which is the result of the bitwise operation.

0x5 XOR 0x6

This expression performs a bitwise XOR operation on two values. The expected result of this expression is 3, which is the result of the bitwise operation.

!(toWord16 0x1)

This expression performs a bitwise NOT operation on a value. The expected result of this expression is 65534, which is the result of the bitwise operation. Bit Manipulations

testBit (setBit 0x0 3) 3

This expression sets a bit in a value and then checks if it is set. The expected result of this expression is vTrue, indicating that the bit is set.

shift 0x1 3

This expression performs a bit shift operation on a value. The expected result of this expression is 8, which is the result of the bit shift operation.

fromWord #false

This expression converts a Boolean value to an integer. The expected result of this expression is 0.

Word Conversion

toWord16 #true

This expression converts a Boolean value to a 16-bit unsigned integer. The expected result of this expression is 1.

toWord16 (toWord64 77)

This expression converts a 64-bit unsigned integer to a 16-bit unsigned integer. The expected result of this expression is 77.

toWord16 (toWord64 (2**17 + 2))

This expression converts a large 64-bit unsigned integer to a 16-bit unsigned integer. The expected result of this expression is 2.

toWord32 (toWord64 77)

This expression converts a 64-bit unsigned integer to a 32-bit unsigned integer. The expected result of this expression is 77.

toWord32 (toWord64 (2**33 + 5))

This expression converts a large 64-bit unsigned integer to a 32-bit unsigned integer. The expected result of this expression is 5.

toWord64 (toWord16 (2**62 + 1))

This expression converts a large 16-bit unsigned integer to a 64-bit unsigned integer. The expected result of this expression is 1.

Word Size Conversion

fromWord (toWord64 (2**62))

This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 4611686018427387904.

fromWord (toWord32 (2**62 + 2**31))

This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 2147483648.

fromWord (toWord16 (2**31 + 2**3))

This expression converts a large unsigned integer to a signed integer. The expected result of this expression is 8.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment