Skip to content

Commit

Permalink
Finished enums.
Browse files Browse the repository at this point in the history
  • Loading branch information
DevReaper0 committed Feb 23, 2022
1 parent f3f7ff5 commit b4511b8
Show file tree
Hide file tree
Showing 30 changed files with 228 additions and 180 deletions.
4 changes: 3 additions & 1 deletion doc/00_vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ optional type, such as `int`,

For example:

`let mynum: int = 5;`
```typescript
let mynum: int = 5;
```

Creates a variable named mynum,
with a type of `int`, and assigns
Expand Down
4 changes: 2 additions & 2 deletions doc/10_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ We can declare our own functions, as well! This piece of
code would create our calculate function, which would simply
add the two given numbers together.

```javascript
```typescript
func calculate(first: int, second: int) {
return first + second;
};
Expand All @@ -30,7 +30,7 @@ Functions can also be used as expressions. This allows
us to reassign functions and swap out object methods at
runtime. For example, to swap out the calculate method:

```javascript
```typescript
calculate = func (first: int, second: int) {
return first * second;
}
Expand Down
2 changes: 1 addition & 1 deletion doc/16_operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ standard objects.

Here's an example of how you can use (and abuse) operator overloading

```javascript
```typescript
let Person = Type.extend({
instance = {
name
Expand Down
6 changes: 3 additions & 3 deletions doc/20_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ many different forms.
To create your own type, use the
syntax:

```javascript
```typescript
let Person: type = {
instance: {
name: str;
Expand All @@ -35,7 +35,7 @@ use.

For example:

```javascript
```typescript
let Person: type = {
instance: {
name: str;
Expand All @@ -49,7 +49,7 @@ let Person: type = {
```

In usage:
```javascript
```typescript
person_a = Person.new();
person_a.name = "Ron";

Expand Down
2 changes: 1 addition & 1 deletion doc/30_proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ functionality and not have to write the same code again twice.

Here is an example on how to create our `Customer` and `Employee` types.

```javascript
```typescript
let Customer: type = Person.extend({
instance = {
customer_id: str;
Expand Down
4 changes: 2 additions & 2 deletions doc/35_macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ the macro, you can use the `mixin` keyword along with a block of code
to tell the language to insert the code here.

Example:
```javascript
```typescript
macro print_times(text: str, times: int) {
for i in Range.new(0, times) {
mixin {
Expand All @@ -21,7 +21,7 @@ macro print_times(text: str, times: int) {
```

Usage:
```javascript
```typescript
print_times("hello world!", 5)();

// alternatively, this works
Expand Down
14 changes: 9 additions & 5 deletions doc/40_arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ Arrays can be iterated over one-by-one by using the
Here's an example of how to create an array and assign
it to a variable.

`let names = ['Jeffrey', 'Sam', 'Buddy'];`
```typescript
let names = ['Jeffrey', 'Sam', 'Buddy'];
```

The `names` array holds three strings, each
representing a name.

If you want to loop over these names, you can use `for`.

```javascript
```typescript
for name in names {
print(name);
}
```

Prints:
```
```bash
Jeffrey
Sam
Buddy
Expand All @@ -42,13 +44,15 @@ Buddy
To access a specific item in an array by index, use the
access operator (square brackets)

`print(names[1]); // prints 'Sam'`
```typescript
print(names[1]); // prints 'Sam'
```

Arrays have multiple methods, including ways of checking whether
an object is contained by the array, appending new items to
an array, and more.

```javascript
```typescript
names.contains('Buddy'); // true
names.append('Tiffany'); // names is now ['Jeffrey', 'Sam', 'Buddy', 'Tiffany']

Expand Down
25 changes: 17 additions & 8 deletions doc/41_dictionaries.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
### Dictionary operations

In your code, you may want to store multiple
contiguous objects together, indexed by *keys* that can be any type. Unlike arrays, which are indexed by a range of numbers, dictionaries are indexed by those *keys*. Dictionaries let you do this in a way that won't clutter up your code with
lots of related variable names.
contiguous objects together, indexed by *keys* that can
be any type. Unlike arrays, which are indexed by a
range of numbers, dictionaries are indexed by those *keys*.
Dictionaries let you do this in a way that won't clutter
up your code with lots of related variable names.

Here's an example of how to create a dictionary and assign
it to a variable.

`let names = ['Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White'];`
```typescript
let names = ['Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White'];
```

The `names` dictionary holds three strings, each
representing a name.

If you want to loop over these names, you can use `for`.

```javascript
```typescript
for name in names {
print(name);
}
```

Prints:
```
```bash
['Jeffrey', 'Williams']
['Sam', 'Johnson']
['Buddy', 'White']
Expand All @@ -31,18 +36,22 @@ Creating an *empty* dictionary is a little different.
Here's an example of how to create an empty dictionary
and assign it to a variable.

`let names = [:];`
```typescript
let names = [:];
```

To access a specific item in a dictionary by index, use the
access operator (square brackets)

`print(names["Sam"]); // prints ['Sam', 'Johnson']`
```typescript
print(names["Sam"]); // prints ['Sam', 'Johnson']
```

Dictionary have multiple methods, including ways of checking whether
an object is contained by the dictionary, appending new items to
a dictionary, and more.

```javascript
```typescript
names.contains('Buddy'); // true

names.append(['Tiffany', 'Jones']); // names is now {'Jeffrey': 'Williams', 'Sam': 'Johnson', 'Buddy': 'White', 'Tiffany': 'Jones'}
Expand Down
2 changes: 1 addition & 1 deletion doc/50_iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ While the `for` loop is powerful, in some instances you may want to allow your o

If you look at the `__iterate__` method in `std/types/array.para` you'll see how the `Array` type handles for loops.

```javascript
```typescript
// std/types/array.para

func __iterate__(self, cb: Func) {
Expand Down
2 changes: 1 addition & 1 deletion doc/55_random.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ number from a predefined range of your choice.

Example:

```javascript
```typescript
import "std/math/random.para";
print(random.range(25, 1, 1337)); /* prints 10 -- try with a different seed! */
```
8 changes: 6 additions & 2 deletions doc/60_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ Say you want to write some text to the console.
You can use our standard `random` package, provided
with the language, by writing this line of code:

`import "std/math/random.para";`
```typescript
import "std/math/random.para";
```

Easy, right? Now you can generate random numbers using the
`random` object. Try this:

Try it for yourself:
`print(random.random(999));`
```typescript
print(random.random(999));
```
9 changes: 6 additions & 3 deletions doc/70_console.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ import any modules manually in order to start using
it.

To print to the console:
`io.write('your string here');`
```typescript
io.write('your string here');
```


And to read input from the console:

```javascript
```typescript
let response = io.read(); // read user input and store in `response`
io.write(response); // print it back out to the console
```

You can also print to the console in a few different colors!
Here's an example on how to do that:

```javascript
```typescript
io.write_color(Console.BLUE, "I'm blue ba ba dee ba ba die");
```
22 changes: 11 additions & 11 deletions doc/80_files.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,57 @@ you want to write, as well as the content you want to write
to the file.

Example:
```javascript
```typescript
File.write('file.txt', 'Hello world');
```

To append a string to a file, use the `File.append` method.

Example:
```javascript
```typescript
File.append('file.txt', 'Hello world');
```

To create a file, use the `File.create` method.

Example:
```javascript
```typescript
File.create('file.txt');
```

To delete a file, use the `File.delete` method. (Also works with directories)

Example:
```javascript
```typescript
File.delete('file.txt');
```

To delete a directory, use the `File.deletedir` method.

Example:
```javascript
```typescript
File.deletedir('directory');
```

To check if a file exists, use the `File.exists` method.

Example:
```javascript
```typescript
Console.write(File.exists('directory'));
```

To check if a file is a file, and not a directory, use the `File.isfile` method.

Example:
```javascript
```typescript
Console.write(File.isfile('file.txt')); // true
Console.write(File.isfile('directory')); // false
```

To check if a file is a directory, and not a file, use the `File.isdir` method.

Example:
```javascript
```typescript
Console.write(File.isdir('directory')); // true
Console.write(File.isdir('file.txt')); // false
```
Expand All @@ -80,7 +80,7 @@ well as the actual data it holds.

Here is an example of how to read a file into a variable.

```javascript
```typescript
let file = File.open('file.txt');
let content = file.data;

Expand All @@ -89,14 +89,14 @@ Console.write(content); // write output to console

And here is another example of how to read a file into a variable.

```javascript
```typescript
let content = File.read('file.txt');

Console.write(content); // write output to console
```

To read the lines of a file into an array use File.readlines.
```javascript
```typescript
let content = File.readlines('file.txt');

Console.write(content); // write output to console
Expand Down
Loading

0 comments on commit b4511b8

Please sign in to comment.