/library

Sentient Lang.

Integer methods

Integers are one of three types in the Sentient programming language. This document contains a reference of all integer operators and methods.

+ (operator)

Performs addition.

5 + 3    #=> 8
- (operator)

Performs subtraction.

5 - 3    #=> 2
* (operator)

Performs multiplication.

5 * 3    #=> 15
/ (operator)

Returns the quotient after division. See divmod.

% (operator)

Returns the remainder after division. See divmod.

-@ (operator)

Performs unary negation.

-(2 + 2)    #=> -4
== (operator)

Returns true if the integer on the left is equal to the right.

2 == 2    #=> true
2 == 3    #=> false
!= (operator)

Returns true if the integer on the left is not equal to the right.

2 != 2    #=> false
2 != 3    #=> true
< (operator)

Returns true if the integer on the left is less than the right.

2 < 1    #=> false
2 < 2    #=> false
2 < 3    #=> true
<= (operator)

Returns true if the integer on the left is less than or equal to the right.

2 <= 1    #=> false
2 <= 2    #=> true
2 <= 3    #=> true
> (operator)

Returns true if the integer on the left is greater than the right.

2 > 1    #=> true
2 > 2    #=> false
2 > 3    #=> false
>= (operator)

Returns true if the integer on the left is greater than or equal to the right.

2 >= 1    #=> true
2 >= 2    #=> true
2 >= 3    #=> false
abs

Returns the absolute value of the integer.

5.abs    #=> 5
-5.abs   #=> 5
between?

Returns true if the integer is between two integers (inclusive).

3.between?(1, 5)
#=> true

5.between?(1, 5)
#=> true

6.between?(1, 5)
#=> false

The order of arguments does not matter:

3.between?(5, 1)
#=> true
cube

Returns the cube of the integer.

3.cube    #=> 27
divmod

Performs integer Euclidean division, returning both quotient and remainder.

a, b = 9.divmod(2)    # a: 4, b: 1

The divisor must not be zero, else the program will have no solutions.

downto

Iterates from a start integer downto an end integer.

total = 0;

5.downto(3, function^ (i) {
  total += i;
});

# total: 12

This method only supports integer literals.

even?

Returns true if the integer is even.

0.even?    #=> true
1.even?    #=> false
2.even?    #=> true
negative?

Returns true if the integer is less than zero.

-1.negative?    #=> true
0.negative?     #=> false
next

Alias for succ.

odd?

Returns true if the integer is odd.

0.odd?    #=> false
1.odd?    #=> true
2.odd?    #=> false
positive?

Returns true if the integer is greater than zero.

1.positive?     #=> true
0.positive?     #=> false
pred

Returns the integer’s predecessor.

3.pred    #=> 2
prev

Alias for pred.

self

Returns the integer.

123.self
#=> 123
square

Returns the square of the integer.

3.square    #=> 9
succ

Returns the integer’s successor.

3.succ    #=> 4
times

Iterates up to one less than the integer, starting from 0.

total = 0;

5.times(function^ (i) {
  total += i;
});

# total: 10

This method only supports integer literals.

upto

Iterates from a start integer upto an end integer.

total = 0;

3.upto(5, function^ (i) {
  total += i;
});

# total: 12

This method only supports integer literals.

zero?

Returns true if the integer is zero.

0.zero?    #=> true
1.zero?    #=> false