Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples: improve grammar, better MD structure & fix some code #41

Merged
merged 10 commits into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions examples/arrays/functions.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,46 @@
# Array Functions

## `repeat`
## `repeat`

Syntax

```go
Type[element].repeat(number int)
array.repeat(number int)
```

Makes an array with the given element number of times.

```go
foo := int[1].repeat(7)
foo := [1, 2].repeat(5)
println(foo)
```

Output

```go
[1, 1, 1, 1, 1, 1, 1]
[1, 2, 1, 2, 1, 2, 1, 2, 1, 2]
```

## insert
## `insert`

Syntax

```go
array.insert(num int, data T)
```

Inserts the data at a given position and shifts the elements in the array
Inserts the data at a given position and shifts the elements in the array.

<!--
dhonx marked this conversation as resolved.
Show resolved Hide resolved
mut names := ['Samuel', 'John', 'Peter']
tom := 'Tom'
names.insert(2, &tom)
println(names)
-->

```go
names := ['Samuel', 'John', 'Peter']
names.insert(2,'Tom')
mut names := ['Samuel', 'John', 'Peter']
names.insert(2, 'Tom')
println(names)
```

Expand All @@ -50,7 +58,7 @@ Syntax
array.delete(element T)
```

Deletes the element present in the array
Deletes the element present in the array.

```go
even_numbers = [2, 4, 6, 8, 10]
Expand All @@ -72,7 +80,7 @@ Syntax
array.reverse()
```

Reverses the array
Reverses the array.

```go
float_num := [1.1, 1.3, 1.25, 1.4]
Expand All @@ -93,7 +101,7 @@ Syntax
array.clone()
```

Clones and returns a new array
Clones and returns a new array.

```go
foo := [1, 2, 4, 5, 4, 6]
Expand Down
8 changes: 4 additions & 4 deletions examples/conditional_statements/conditional_statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if john_height < maria_height {
}
```

In the above code, `fn println()` will only execute when the condition is true else no statement would be printed.
In the above code, `fn println()` will only execute when the condition is true else no statement would be printed.

## `else` statement

Expand All @@ -32,8 +32,7 @@ if joey_age > kevin_age {
}
```

In this example the block in else will execute because the condition in `if` evaluates to false.

In this example, the block in else will execute because the condition in `if` evaluates to false.

## `else if` statement

Expand Down Expand Up @@ -64,7 +63,7 @@ if tom_age < ashia_age {
} else {
println('tom_age >= 18 and younger than Ashia.')
}
}
}
else if tom_age > ashia_age {
println('$tom_age > $ashia_age')
} else {
Expand All @@ -90,6 +89,7 @@ print(s)
```

Output

```bash
Tom is the youngest
```
Expand Down
18 changes: 9 additions & 9 deletions examples/functions/functions.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Functions

A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.
A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing.

Ideally you should consider using the [single responsibility principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) (SOLID) which states that every module or function should have responsibility over a single part of the functionality provided by the software to keep your code maintainable.
Ideally, you should consider using the [single responsibility principle](https://en.wikipedia.org/wiki/Single_responsibility_principle) (SOLID) which states that every module or function should have responsibility for a single part of the functionality provided by the software to keep your code maintainable.

Like C and Go, functions cannot be overloaded.

Expand Down Expand Up @@ -30,11 +30,11 @@ fn full_name(first_name, last_name string) string {

## Variadic Functions

Functions can also be variadic i.e. accept infinite number of arguments. They are **not** arrays and cannot be returned.
Functions can also be variadic i.e. accept an infinite number of arguments. They are not arrays and cannot be returned.
dhonx marked this conversation as resolved.
Show resolved Hide resolved

```go
fn main() {
foo("V", "is", "the", "best", "lang" , "ever")
foo("V", "is", "the", "best", "lang" , "ever")
}

fn foo(test ...string) {
Expand All @@ -55,10 +55,10 @@ ever

## Multi-Return Functions

Similar to Go, functions in V can also return multiple and with different type.
Similar to Go, functions in V can also return multiple and with a different type.

```go
fn main() {
fn main() {
name, age := student("Tom", 15)
println(name, age)

Expand All @@ -77,15 +77,15 @@ Tom , 15

## High Order Functions

Functions can also take in another function which is usually needed to sort, map, fitler etc.
Functions in V can also take in another function which is usually needed to sort, map, fitler etc.

```go
fn square(num int) int {
return num * num
}

fn run(value int, op fn(int) int) int {
return op(value)
return op(value)
}

fn main() {
Expand All @@ -104,5 +104,5 @@ Output
1. Write a V program to find the square of any number using the function.
2. Write a V program to check a given number is even or odd using the function.
3. Write a V program to convert decimal number to binary number using the function.
4. Write a V program to check whether a number is a prime number or not using the function.
4. Write a V program to check whether a number is a prime number or not using the function.
5. Write a V program to get the largest element of an array using the function.