Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Seggan committed Dec 13, 2023
1 parent fa9cda3 commit 19ca5c6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 33 deletions.
9 changes: 9 additions & 0 deletions docs/lang/core/bytes.papyri
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ index and has the given length.

@h2 Metamethods

@h3 { __band__(self, other: bytes): bytes }
Bitwise AND the bytes objects.

@h3 { __bor__(self, other: bytes): bytes }
Bitwise OR the bytes objects.

@h3 { __bxor__(self, other: bytes): bytes }
Bitwise XOR the bytes objects.

@h3 { __contains__(self, needle: number): boolean }
Check if the given byte is contained in the bytes object.

Expand Down
2 changes: 1 addition & 1 deletion docs/lang/core/number.papyri
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Divide a number by another number.
@h3 { __eq__(self, other: number): boolean }
Check if a number is equal to another number.

@h3 { __inclrange__(self, other: number): number }
@h3 { __inclRange__(self, other: number): number }
Create a range from a number to another number (inclusive).

@h3 { __minus__(self, other: number): number }
Expand Down
78 changes: 46 additions & 32 deletions docs/lang/index.papyri
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn printX()
print(x)
end

printX() // 5
printX() # 5
```

Upvalues can also be mutated:
Expand All @@ -65,7 +65,7 @@ fn addToX(y)
end

addToX(5)
print(x) // 10
print(x) # 10
```

If a function is called with missing arguments, the missing arguments are set to `null`:
Expand All @@ -77,7 +77,7 @@ fn add(a, b, c)
print(c)
end

add(1, 2) // 1, 2, null
add(1, 2) # 1, 2, null
```

This can be used to provide default values with the help of the `?:` operator:
Expand All @@ -92,7 +92,7 @@ fn add(a, b, c)
print(c)
end

add(1, 2) // 1, 2, 0
add(1, 2) # 1, 2, 0
```

If the first argument is named `self`, then that function is considered a @i {self function}. When getting
Expand All @@ -105,7 +105,7 @@ fn x.getA(self)
return self.a
end

print(x.getA()) // 1
print(x.getA()) # 1
```

@h2 { Anonymous Functions }
Expand All @@ -125,7 +125,7 @@ Functions are first class values, so they can be assigned to variables:
Metis has the following data types: `null`, `boolean`, `number`, `string`, `list`, `table`, `callable`,
`native`, `bytes`, `error`, and `coroutine`. You can use the `type` function to get the type of a value:

@metis `type(5) // "number"`
@metis `type(5) # "number"`

Data types may also have metatables, which are tables that are used to look up missing keys. Metatables
may also have metamethods, which are functions that are called when certain operations are performed on
Expand Down Expand Up @@ -193,7 +193,7 @@ created. List literals are enclosed in square brackets:

Lists can be indexed with `[]`:

@metis `x[0] // 1`
@metis `x[0] # 1`

Lists can be iterated over with `for`:

Expand All @@ -213,11 +213,11 @@ enclosed in curly braces:

Tables can be indexed with `[]`:

@metis `x["a"] // 1`
@metis `x["a"] # 1`

Alternatively, you can use the `.` operator:

@metis `x.a // 1`
@metis `x.a # 1`

Tables cannot be iterated over directly, but you can iterate over their keys or values:

Expand All @@ -240,7 +240,7 @@ can be called with `()`:

@metis ```
let x = fn(a, b) = a + b
x(1, 2) // 3
x(1, 2) # 3
```

@h3 Natives
Expand All @@ -257,7 +257,7 @@ created. Byte literals are enclosed in single quotes:

Bytes can be indexed with `[]`:

@metis `x[0] // 104`
@metis `x[0] # 104`

Bytes can be iterated over with `for`:

Expand All @@ -271,8 +271,8 @@ Bytes can be converted to strings using `decode`, and strings can be converted t

@metis ```
let x = 'hello'
let y = x:decode() // "hello"
let z = y:encode() // 'hello'
let y = x:decode() # "hello"
let z = y:encode() # 'hello'
```

@h3 Errors
Expand Down Expand Up @@ -311,45 +311,59 @@ end)

Coroutines can be run with `coroutine.run`:

@metis `x:run() // "hello"`
@metis `x:run() # "hello"`

@h2 { Operators }

Metis has a set of operators that may or may not be overloaded. They are listed in order of decreasing precedence:

`[]`, `()`, and `.`; these are used to index tables and call callables. There is no way to overload
calling, but as `.` is syntax sugar for `[]`, they can be overloaded using
`[]`, `()`, and `.`: these are used to index tables and call callables. There is no way to overload
calling, but as `.` is syntax sugar for `[]`, `.` and `[]` can be overloaded using
the metamethod `__index__`.

`not` and unary `-`; these are used to negate booleans and numbers. Only `-` can be overloaded using
`**`: this is used to raise a number to a power. It can be overloaded using `__pow__`.

`not` and unary `-`: these are used to negate booleans and numbers. Only `-` can be overloaded using
`__neg__`.

`*`, `/`, and `%`; these are used to multiply, divide, and modulo numbers. They can be overloaded using
`__times__`, `__div__`, and `__mod__`.
`*`, `/`, `//`, and `%`: these are used to multiply, divide, floor divide, and modulo numbers. They can
be overloaded using `__times__`, `__div__`, `__floordiv__`, and `__mod__`.

`+` and `-`; these are used to add and subtract numbers. `+` is also used for concatenating strings and
`+` and `-`: these are used to add and subtract numbers. `+` is also used for concatenating strings and
adding to lists and tables. They can be overloaded using `__plus__` and `__minus__`.

`..<` and `..=`; exclusive and inclusive range. Can be overloaded with `__range__` and `__inclrange__`.
`<<`, `>>`, and `>>>`: these are used to shift numbers left, right, and right with sign extension.
They can be overloaded using `__shl__`, `__shr__`, and `__shru__`.

`&`: this is used to compute the bitwise AND of numbers and bytes objects. It can be overloaded using
`__band__`.

`|`: this is used to compute the bitwise OR of numbers and bytes objects. It can be overloaded using
`__bor__`.

`^`: this is used to compute the bitwise XOR of numbers and bytes objects. It can be overloaded using
`__bxor__`.

`..<` and `..=`: exclusive and inclusive range. Can be overloaded with `__range__` and `__inclRange__`.

`?:`, also known as the elvis operator, is used to provide a default value in case a value is null.
For example, `x ?: 1` will return `1` is `x` is null, and `x` otherwise. It cannot be overloaded.

`in`, `not in`, `is`, and `is not`; these are used to check if a value is in a list or table, or if
`in`, `not in`, `is`, and `is not`: these are used to check if a value is in a list or table, or if
two values are the same exact object. `in` and `not in` can be overloaded using `__contains__`.

`<`, `<=`, `>`, and `>=`; these are used to compare values. They all use the same metamethod for overloading:
`<`, `<=`, `>`, and `>=`: these are used to compare values. They all use the same metamethod for overloading:
`__cmp__`. The metamethod should return a negative number if the left value is less than the right value,
a positive number if the left value is greater than the right value, and zero if the left value is equal
to the right value.

`==` and `!=`; these are used to check if two values are equal or not. They can be overloaded using
`==` and `!=`: these are used to check if two values are equal or not. They can be overloaded using
`__eq__`.

`and`; returns `true` if both values are true, and `false` otherwise. It cannot be overloaded. It also
`and`: returns `true` if both values are true, and `false` otherwise. It cannot be overloaded. It also
short circuits, so if the left value is false, the right value is not evaluated.

`or`; returns `true` if either value is true, and `false` otherwise. It cannot be overloaded. It also
`or`: returns `true` if either value is true, and `false` otherwise. It cannot be overloaded. It also
short circuits, so if the left value is true, the right value is not evaluated.

`? else` is the ternary operator. It is used as a shorter form of `if`:
Expand Down Expand Up @@ -451,7 +465,7 @@ for x in [1, 2, 3, 4]
print(x)
end

// Prints 1 and 2
# Prints 1 and 2
```

If you need to skip the rest of the loop body, you can use `continue`:
Expand All @@ -464,7 +478,7 @@ for x in [1, 2, 3, 4]
print(x)
end

// Prints 1, 2, and 4
# Prints 1, 2, and 4
```

@h1 Modules
Expand All @@ -487,15 +501,15 @@ This will load the module and assign it to a global variable with the same name
can be used for implementing transient modules as such:

@metis ```
// foo.metis
# foo.metis
global import bar

// bar.metis
# bar.metis
let global x = 1

// main.metis
# main.metis
import foo
print(foo.bar.x) // 1
print(foo.bar.x) # 1
```

@h1 { Standard Library }
Expand Down

0 comments on commit 19ca5c6

Please sign in to comment.