From 0848498d9c4ba2d2d723f51ede3e85e5b825406a Mon Sep 17 00:00:00 2001 From: Jhon James Quintero Date: Tue, 11 Feb 2020 21:34:13 -0500 Subject: [PATCH 1/2] Start spanish version --- README.md | 2 +- es/README.md | 1 + es/examples/README.md | 69 ++++++++++ es/examples/section_1/README.md | 1 + es/examples/section_1/comment.md | 14 ++ es/examples/section_1/hello_world.md | 50 +++++++ es/examples/section_1/keywords.md | 13 ++ es/examples/section_1/primitives.md | 47 +++++++ es/examples/section_1/strings.md | 93 +++++++++++++ es/examples/section_1/variables.md | 80 +++++++++++ es/examples/section_2/README.md | 1 + es/examples/section_2/if-else.md | 114 +++++++++++++++ es/examples/section_2/loops.md | 113 +++++++++++++++ es/examples/section_2/match.md | 112 +++++++++++++++ es/examples/section_2/operator.md | 117 ++++++++++++++++ es/examples/section_3/README.md | 1 + es/examples/section_3/arrays.md | 168 +++++++++++++++++++++++ es/examples/section_3/functions.md | 128 +++++++++++++++++ es/examples/section_3/methods.md | 59 ++++++++ es/examples/section_3/struct.md | 122 ++++++++++++++++ es/examples/section_4/README.md | 1 + es/examples/section_4/array-functions.md | 63 +++++++++ es/examples/section_4/files.md | 80 +++++++++++ es/examples/section_4/json.md | 67 +++++++++ es/examples/section_4/testing.md | 64 +++++++++ 25 files changed, 1579 insertions(+), 1 deletion(-) create mode 100644 es/README.md create mode 100644 es/examples/README.md create mode 100644 es/examples/section_1/README.md create mode 100644 es/examples/section_1/comment.md create mode 100644 es/examples/section_1/hello_world.md create mode 100644 es/examples/section_1/keywords.md create mode 100644 es/examples/section_1/primitives.md create mode 100644 es/examples/section_1/strings.md create mode 100644 es/examples/section_1/variables.md create mode 100644 es/examples/section_2/README.md create mode 100644 es/examples/section_2/if-else.md create mode 100644 es/examples/section_2/loops.md create mode 100644 es/examples/section_2/match.md create mode 100644 es/examples/section_2/operator.md create mode 100644 es/examples/section_3/README.md create mode 100644 es/examples/section_3/arrays.md create mode 100644 es/examples/section_3/functions.md create mode 100644 es/examples/section_3/methods.md create mode 100644 es/examples/section_3/struct.md create mode 100644 es/examples/section_4/README.md create mode 100644 es/examples/section_4/array-functions.md create mode 100644 es/examples/section_4/files.md create mode 100644 es/examples/section_4/json.md create mode 100644 es/examples/section_4/testing.md diff --git a/README.md b/README.md index ae80b12..0abe42c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # V by Example -[Brazilian Portuguese](/pt-br/README.md) | [Deutsch](/de/README.md) | [English](README.md) | [Bahasa Indonesia](/id/README.md) | [Chinese](cn/examples/README.md) +[Brazilian Portuguese](/pt-br/README.md) | [Deutsch](/de/README.md) | [English](README.md) | [Bahasa Indonesia](/id/README.md) | [Chinese](cn/examples/README.md) | [Spanish](es/examples/README.md) > Learn V by Examples V by Example is a direct introduction to V by using annotated program examples. diff --git a/es/README.md b/es/README.md new file mode 100644 index 0000000..df635b4 --- /dev/null +++ b/es/README.md @@ -0,0 +1 @@ +# Examples diff --git a/es/examples/README.md b/es/examples/README.md new file mode 100644 index 0000000..895b484 --- /dev/null +++ b/es/examples/README.md @@ -0,0 +1,69 @@ +# V by Example + +[Portugues Brasil](/pt-br/README.md) | [Alemán](/de/README.md) | [Inglés](README.md) | [Bahasa Indonesia](/id/README.md) | [Chino](cn/examples/README.md) | + +> Aprendiendo V con Ejemplos + +V por ejemplos es una introducción directa al lenguaje V usando ejemplos con comentarios. + +- [Ejemplos](#examples) +- [Contribuyendo](#contributing) +- [Licencia](#license) + +Discord: [https://discord.gg/d3Qk65J](https://discord.gg/d3Qk65J) + +## Section 1 + +Introduction to V by presenting a few basic examples and exercises. + +- [Hola Mundo](es/examples/section_1/hello_world.md) +- [Palabras clave de V](en/examples/section_1/keywords.md) +- [Primitivas](en/examples/section_1/primitives.md) +- [Variables](en/examples/section_1/variables.md) +- [Cadenas](en/examples/section_1/strings.md) +- [Comentarios](en/examples/section_1/comment.md) + +## Section 2 + +This section discusses the main operators and conditional statements in V. + +- [Operator](en/examples/section_2/operator.md) +- [If-else](en/examples/section_2/if-else.md) +- [Match](en/examples/section_2/match.md) +- [Loops](en/examples/section_2/loops.md) + +## Section 3 + +A study on functions and methods and in the most important data structures in V: arrays and struct. + +- [Functions](en/examples/section_3/functions.md) +- [Arrays](en/examples/section_3/arrays.md) +- [Struct](en/examples/section_3/struct.md) +- [Methods](en/examples/section_3/methods.md) + +## Section 4 + +In this section, we dive deeper and study the features inside the Array object. Other examples like JSON, Writing/reading files and Testing are covered. + +- [Array Functions](en/examples/section_4/array-functions.md) +- [Testing](en/examples/section_4/testing.md) +- [Files](en/examples/section_4/files.md) +- [JSON](en/examples/section_4/json.md) + +## Team + +Current list of maintainers/authors: + +- [Don Alfons Nisnoni](https://github.com/dhonx) +- [Ivo-Balbaert](https://github.com/ibalbaert) +- [Sven Patrick Meier](https://github.com/SuicideS3ason) +- [Swastik Baranwal](https://github.com/Delta456) +- [Vitor Oliveira](https://github.com/vbrazo) + +## Contributing + +See our [CONTRIBUTING.md](CONTRIBUTING.md) and start contributing today. We usually elect new maintainers based on contributions. + +## License + +[MIT](LICENSE) diff --git a/es/examples/section_1/README.md b/es/examples/section_1/README.md new file mode 100644 index 0000000..7c2fd43 --- /dev/null +++ b/es/examples/section_1/README.md @@ -0,0 +1 @@ +# Section 1 diff --git a/es/examples/section_1/comment.md b/es/examples/section_1/comment.md new file mode 100644 index 0000000..aa6bd0e --- /dev/null +++ b/es/examples/section_1/comment.md @@ -0,0 +1,14 @@ +# Comments + +V supports single line comments `//` and multi-line comments `/* */`. +They should be used for documenting the code for letting the other users know how the code works. +It can also be used for temporarily commenting the code which has to be used later on. + +```v +// This is a single line comment + +/* This is a +* multi-line comment +* /* This could be nested as well*/ +*/ +``` diff --git a/es/examples/section_1/hello_world.md b/es/examples/section_1/hello_world.md new file mode 100644 index 0000000..89ab46c --- /dev/null +++ b/es/examples/section_1/hello_world.md @@ -0,0 +1,50 @@ +# Mostrando información con formato + +Para mostrar información se utilizan varias funciones de Entrada/Salida. Se debe saber cual de ellas usar de acuerdo a las necesidades. + +- `print`: Para imprimir un mensaje en el stdout (pantalla) sin nueva linea. + +- `println`: Igual que `print` pero se añade una nueva linea al final. + +- `eprint`: Igual que `print` pero el mensaje va la salida de errores (stderr). + +- `eprintln`: Igual que `eprint` pero el mensaje va la salida de errores (stderr). + +- `panic`: Imprime un mensaje y termina el programa. + +```v +print('Hello World') +print('Hello V') +``` + +Lo anterior mostrará `Hello WorldHello V` en la salida estándar. + +Si se desea agregar un salto de linea se deba añadir `\n`. + +```v +print('Hello World \n') +print('Hello V ') +``` + +Si no se desea usar `\n` mejor se puede utilizar la función `println`. + +## Comments + +V soporta comentarios de una linea `//` y multilinea `/* */`. +Se usan para documentar el código para que los usuarios sepan cómo funciona. + +También se usan para comentarios temporales. + + +```v +// This is a single line comment + +/* This is a +* multi-line comment +* /* This could be nested as well*/ +*/ +``` + +## Ejercicios + +Elimine los comentarios en `hello.v` y observe que pasa. diff --git a/es/examples/section_1/keywords.md b/es/examples/section_1/keywords.md new file mode 100644 index 0000000..7e03dd9 --- /dev/null +++ b/es/examples/section_1/keywords.md @@ -0,0 +1,13 @@ +# Keywords + +V is a very small language so it has few keywords. There are around 25 keywords. + +| Keywords | in | V | Programming | Language | +| -------- | ------ | --- | ----------- | --------- | +| break | const | as | continue | defer | +| else | enum | fn | for | struct | +| go | goto | if | import | return | +| type | pub | mut | in | interface | +| match | module | or | none | | + +Like other languages, they cannot be used as a variable. diff --git a/es/examples/section_1/primitives.md b/es/examples/section_1/primitives.md new file mode 100644 index 0000000..41d700d --- /dev/null +++ b/es/examples/section_1/primitives.md @@ -0,0 +1,47 @@ +# Primitives + +V has less primitive types than Go. + +## Basic Types + +- bool either `true` or `false` + +- string + +- integer type `int` + +- float type `float` + +- rune (Unicode string) + +## Compound Types + +- arrays `[]` + +- map `{}` + +- struct + +## Integer + +Integer is sub-classified into `signed` and `unsigned`. `signed` means positive or negative and `unsigned` means positive only. + +### Signed Integer + +| Type | Size | Range | +| ------ | :------: | --------------------------------------: | +| int8 | 8 bits | -128 to 27 -1 | +| int16 | 16 bits | -215 to 215 - 1 | +| int | 32 bits | -231 to 231 - 1 | +| int64 | 64 bits | -263 to 263 - 1 | +| int128 | 128 bits | -2127 to 2127 - 1 | + +### Unsigned Integer + +| Type | Size | Range | +| ---- | :------: | -----------------------: | +| byte | 8 bits | 0 to 27 -1 | +| u16 | 16 bits | 0 to 215 - 1 | +| u32 | 32 bits | 0 to 231 - 1 | +| u64 | 64 bits | 0 to 263 - 1 | +| u128 | 128 bits | 0 to 2127 - 1 | diff --git a/es/examples/section_1/strings.md b/es/examples/section_1/strings.md new file mode 100644 index 0000000..8994d48 --- /dev/null +++ b/es/examples/section_1/strings.md @@ -0,0 +1,93 @@ +# Strings + +In V one can define strings using the `:=` operator. Strings (like other variables) are immutable by default. One is free to use `""` or `''` to denote a string. When using `vfmt` all double-quoted strings will be converted to single-quoted ones unless it contains a single quote character. + +```go +name := 'Bob' +println(name) // Bob +println(name.len) // 3 +``` + +Getting the length of a string works with `.len`. + +## Interpolation + +It is possible to do string interpolation with `$` in front of the variable: + +```go +name:= 'Bob' +println('Hello $name!') // Hello Bob! +``` + +One can have more complex expressions with interpolation syntax by using `${}`: + +```go +struct User { + name string + age int +} +bob := User { + name: 'Bob' + age: 17 +} +println('Say Hello to a new User: ${bob.name}, ${bob.age}') // Say Hello to new User: Bob, 17 +println('${bob.name}s age is higher or equal to 18: ${bob.age >= 18}') // 0 <=> number representation for false +``` + +## Concatenation + +Strings can be concatenated with the `+` operator. + +```go +text := 'Hello' +concatenated_text := text + ' World!' +println(text) // Hello +println(text + ' World!') // Hello World! +println(concatenated_text) // Hello World! +``` + +Appending to a string works with concatenation as well as with `+=` operator. Since strings are immutable by default it is only possible to do this if they are declared with `mut`. + +```go +mut hello := 'Hello ' +hello += 'from V!' // appends 'from V!' to the string stored in hello. +println(hello) // Hello from V! +``` + +In V, string data is encoded using UTF-8 and the string itself is a read-only array of bytes. This makes slicing possible, which means we can access single-character literals or slices of a string variable. + +```go +robert := 'Robert' +bert := robert[2..robert.len] // bert +rob := robert[0..3] // Rob +println('The persons of interest are: $robert, $bert, $rob') // The persons of interest are: Robert, bert, Rob +``` + +### Notes + +When using `some_string[start..end]` syntax the `end` is **not** inclusive. + +All operators in V must have values of the same type on both sides. The code below will not compile because `age` is an `int`: + +```go +age := 25 +println('age = ' + age) +``` + +We therefore need to convert it to string by using `.str()` or use string interpolation (preferred): + +```go +age := 25 +println('age = ' + age.str()) // age = 25 +println('age = $age') // age = 25 +``` + +To define character literals use: ` `` `. Raw strings can be defined as prepending `r`. They are not escaped. + +```go +hello := 'Hello\nWorld' +println(hello) // Hello + // World +raw_hello := r'Hello\nWorld' +println(raw_hello) // Hello\nWorld +``` diff --git a/es/examples/section_1/variables.md b/es/examples/section_1/variables.md new file mode 100644 index 0000000..878a7bb --- /dev/null +++ b/es/examples/section_1/variables.md @@ -0,0 +1,80 @@ +# Variables + +In V variables can be declared and initialized with the `:=` operator. Variables can only be declared this way in V, this means all variables have an initial value. The type of a variable is inferred from the value on the right hand side. By default variables in V are immutable. + +```go +age := 23 // int +name := 'Alice' // string +is_adult := age > 21 // bool + +println(age_str) // 23 +println(name) // Alice +println(is_adult) // true +``` + +> Note: Variables can only be defined in a function. There are no global variables and no global state in V. + +To change the value of a variable, it needs to be mutable. This can be done using the `mut` keyword when declaring the variable. To assign a new value to a variable use `=`. + +```go +mut age := 20 // declare the mutable variable age and assign it to the value 20. +println(age) // 20 +age = 21 // assign a new value to age +println(age) // 21 +``` + +Leaving out the `mut` keyword here would result in an error because the value of an immutable variable cannot be changed. + +```go +fn main() { + age = 20 + println(age) +} +``` + +The code above would result in an error during compilation because the variable `age` is not declared, + +```go +fn main() { + mut age := 20 // we declare the mutable variable age and assign it to the value 20. + println(age) // 20 + age := 21 // ERROR +} +``` + +here `age := 21` will result in another error while compiling because the variable `age` is already defined in the scope. It's very simple to remember, just declare value with `:=` and assign value with `=`. + +Like Go, You can also use `_` for ignoring values when it is not needed. Usually used in multi return functions. + +```go +_ := "I don't need this value" +println(_) // ERROR: Cannot use `_` as value +``` + +## Naming Rules + +The following are the rules which should be kept in mind while naming variables. + +- Name should not contain Uppercase letters like `AlphaTest` +- Use underscores as separators like `hello_world` +- Name should be descriptive as possible +- Name should not contain `__` +- Name should not contain any space +- If the name is longer than 11 then it must use `_` as separator + +These rules are from [`Snake_Case`](https://en.wikipedia.org/wiki/Snake_case). V uses Snake Case and prefers it because it is more easy to read, write and understand. + +### Valid Names + +```go +boby +john_dads +myfamily_number +``` + +### Invalid Names + +```go +IamNotValid +new Make +``` diff --git a/es/examples/section_2/README.md b/es/examples/section_2/README.md new file mode 100644 index 0000000..c50eccb --- /dev/null +++ b/es/examples/section_2/README.md @@ -0,0 +1 @@ +# Section 2 diff --git a/es/examples/section_2/if-else.md b/es/examples/section_2/if-else.md new file mode 100644 index 0000000..78f5dd0 --- /dev/null +++ b/es/examples/section_2/if-else.md @@ -0,0 +1,114 @@ +# If statement + +## The `if` statement + +An `if` statement is a programming conditional statement that, if proved true, executes the code given in the block. Below is a general example of an if statement in V: + +```go +john_height := 100 +maria_height := 178 + +if john_height < maria_height { + println("Maria is taller than John") +} +``` + +In the above code, `println()` will only execute when the condition is true. +There are no parentheses needed for surrounding the condition, and the braces are always required. + +## The `else` statement + +An `else` statement is a programming conditional statement in which when `if` evaluates to false then the code in `else` block executes. + +```go +joey_age := 12 +kevin_age := 15 + +if joey_age > kevin_age { + println("Joey is older") +} else { + println("Kevin is older") +} +``` + +In this example, the code inside the `else` block will execute because the condition in `if` evaluates to `false`. + +## The `else if` statement + +The `if...else` statement executes two different codes depending upon whether the test expression is `true` or `false`. Sometimes, a choice has to be made from more than 2 possibilities. The `if...else if...else` ladder allows you to check between multiple test expressions and execute different statements. + +```go +tom_age := 20 +ashia_age := 38 + +if tom_age < ashia_age { + println("Tom is younger than Ashia") +} else if tom_age > ashia_age { + println("Tom is older than Ashia") +} else { + println("Tom and Ashia are the same age") +} +``` + +Output + +```console +Tom is younger than Asia +``` + +## Nested `if..else` statement + +It is always a good practice to nest `if...else` statements which means you can use one `if`, `else` or `else...if` statement inside another `if` or `else...if` statement. + +```go +tom_age := 20 +ashia_age := 38 + +if tom_age < ashia_age { + if tom_age < 18 { + println("tom_age < 18 and younger than Ashia.") + } else { + println("tom_age >= 18 and younger than Ashia.") + } +} else if tom_age > ashia_age { + println("$tom_age > $ashia_age") +} else { + println("$tom_age == $ashia_age") +} +``` + +Output + +```console +tom_age >= 18 and younger than Ashia. +``` + +## Using `if..else` as expression + +The `if..else` can also be used as an expression: + +```go +tom_age := 20 +ashia_age := 38 + +s := if tom_age < ashia_age { + "Tom is the youngest" +} else { + "Ashia is the youngest" +} + +print(s) +``` + +Output + +```console +Tom is the youngest +``` + +## Exercises + +1. Write a V program to accept two integers and check whether they are equal or not. +2. Write a V program to check whether a given number is even or odd. +3. Write a V program to check whether a given number is positive or negative. +4. Write a V program to find whether a given year is a leap year or not. diff --git a/es/examples/section_2/loops.md b/es/examples/section_2/loops.md new file mode 100644 index 0000000..b461e90 --- /dev/null +++ b/es/examples/section_2/loops.md @@ -0,0 +1,113 @@ +# Looping Constructs + +There's only one type of loop in V language, like Go which can be used in many ways. + +## `for` loop + +`for` loops offer a quick and easy way to do something repeatedly. +They're handy, if you want to run the same code over and over again, each time with a different value. +You can think of a loop as a computerized version of the game where you tell someone to take X steps in one direction then Y steps in another; +for example, the idea "Go five steps to the east" could be expressed this way as a loop: + +```go +for i := 0; i < 5; i++ { + println('Walking one step') +} +``` + +V has the `for` looping construct and the loop can be written in different ways: + +- `in` operator for array/map + +```go +ages := [18, 25, 32, 43, 50] + +for age in ages { + println(age) +} +``` + +> Note: The value is read-only. + +- `for` loop with a condition + +This is a control flow statement that allows code to be executed repeatedly based on a given Boolean condition. +There are no parentheses surrounding the condition, and the braces are always required. + +```go +mut factorial := 1 +mut counter := 1 + +for { + counter++ + if counter > 5 { + println(factorial) + break + } + factorial = factorial * counter +} + +println(counter) +``` + +Output + +```console +120 +6 +``` + +A for loop with a break statement can always be made shorter by placing the inverse condition right after for, making it equivalent with the while statement in other languages. + +```go +mut factorial := 1 +mut counter := 1 + +for counter <= 5 { + factorial = factorial * counter + counter++ +} +println(factorial) +println(counter) +``` + +Output + +```console +120 +6 +``` + +- Traditional C style + +```go +mut factorial := 1 +mut counter := 1 + +for counter = 1; counter < 6; counter++ { + factorial = factorial * counter + if counter == 5 { + print(factorial) + continue + } + println(counter) +} +``` + +- Infinite Loop + +`for` loop can also be infinite + +```go +for { + println('foo') +} +``` + +## Exercises + +1. Write a V program to display the first 10 natural numbers. +2. Write a V program to find the sum of first 10 natural numbers. +3. Write a V program to print the integers inside an array and also print their mean. +4. Write a V program to read 10 numbers from keyboard and find their sum and average. +5. Write a V program to display the cube of the number upto given an integer. diff --git a/es/examples/section_2/match.md b/es/examples/section_2/match.md new file mode 100644 index 0000000..9ca3509 --- /dev/null +++ b/es/examples/section_2/match.md @@ -0,0 +1,112 @@ +# Match + +## The `match` statement + +A match statement is a short-hand way for `if - else`. +If the input is matched the statement block of the first matching branch will be executed and its last expression will be returned. +The `else` branch will be executed when there is no other matching branch. + +```v +num := 1 +match num % 2 == 0 { + true { print('The input number is even.') } + else { print('The input number is odd.') } +} +``` + +One can also initialize variables using `match` to have different values according to a condition. + +```v +num := 3 +s := match num { + 1 { 'one' } + 2 { 'two' } + else { + 'many' + } +} +``` + +Examples: + +```v +fn even(num int) bool { + match num % 2 == 0 { + true { print('The input number is even.') } + else { print('The input number is odd.') } + } +} + +fn num_to_str(num int) int { + match num { + 1 { 'one' } + 2 { 'two' } + else { + 'many' + } + } +} + +fn main() { + println(even(14)) // 'The input number is even.' + println(even(3)) // 'The input number is odd.' + println(num_to_str(1)) // 'one' + println(num_to_str(2)) // 'two' + println(num_to_str(352)) // 'many' +} +``` + +### Enums + +One can also match on `enum` values (variants) as branches by using the `.variant_here` syntax: + +```v +enum Animal { + cat + dog + goldfish + pig +} + +fn makes_miau(a Animal) bool { + return match a { + .cat { true } + else { false } + } +} + +fn is_land_creature(a Animal) bool { + return match a { + .cat { true } + .dog { true } + .pig { true } + else { + false + } + } +} +// OR LIKE THAT +fn is_land_creature_alt(a Animal) bool { + return match a { + .goldfish { false } + else { + true + } + } +} + +fn main() { + my_cat := Animal.cat + my_goldfish := Animal.goldfish + + println(makes_miau(my_cat)) // true + println(is_land_creature(my_cat)) // true + println(is_land_creature(my_goldfish)) // false +} +``` + +### Exercises + +1. Write a V program that creates an array of all even numbers from 1 to 50. +2. Write a V program that, given an array of numbers, returns the maximum value. +3. Write a V program that determines whether color (enum) is red or blue diff --git a/es/examples/section_2/operator.md b/es/examples/section_2/operator.md new file mode 100644 index 0000000..8f0ad2f --- /dev/null +++ b/es/examples/section_2/operator.md @@ -0,0 +1,117 @@ +# Operators + +V supports the following operators: + +## Basic Operators + +- `+` (addition) for int, float and string + +- `-` (subtraction) for int and float + +- `*` (multiplication) for int and float + +- `/` (division) for int and float + +- `%` (modulos) for int + +- `=` (assignment) for changing values + +- `:=` for initialising values + +```v +println(3 + 5) +println(2.0 + 5.0) +println('hello' + 'world') + +println(9 - 10) +println(7.0 - 5.0) + +println(3 * 5) +println(2.0 * 4) + +println(23 / 3) +println(25.0 / 5.0) + +println(27 % 5) +println(27 % 3) +``` + +Output + +```v +8 +7.0 +hello world + +-1 +2.0 + +15 +8.0 + +7 +5.0 + +2 +0 +``` + +> Note: Unlike other languages, V doesn't allow modulus with float. + +## Comparison Operators + +- `>` greater than + +- `<` lesser than + +- `==` equal to + +- `>=` greater than or equal to + +- `<=` lesser than or equal to + +- `!=` not equal to + +## Boolean Operators + +- `&&` and + +- `||` or + +- `!` not + +## Bitwise Operators + +- `<<` left bitshift + +- `>>` right bitshift + +- `&` bitwise and + +- `|` bitwise or + +- `^` bitwise xor + +## Assignments Operators + +- `+=` same as `foo = foo + var` + +- `-=` same as `foo = foo - var` + +- `*=` same as `foo = foo * var` + +- `/=` same as `foo = foo / var` + +- `&=` same as `foo = foo & var` + +- `|=` same as `foo = foo | var` + +- `>>=` same as `foo = foo >> var` + +- `<<=` same as `foo = foo << var` + +## Special Operators + +- `in` for membership + +- `none` for optional diff --git a/es/examples/section_3/README.md b/es/examples/section_3/README.md new file mode 100644 index 0000000..4ddd0ea --- /dev/null +++ b/es/examples/section_3/README.md @@ -0,0 +1 @@ +# Section 3 diff --git a/es/examples/section_3/arrays.md b/es/examples/section_3/arrays.md new file mode 100644 index 0000000..2f4a71c --- /dev/null +++ b/es/examples/section_3/arrays.md @@ -0,0 +1,168 @@ +# Arrays + +An array is a collection of items stored in contiguous memory locations. It's an aggregate data structure that is designed to store a group of objects of the same type. It's the most efficient data structure for storing and accessing a sequence of objects. + +## How to declare an array + +**Create an array that holds integer values:** + +```go +mut ages := [18, 25, 37] + +println(ages) +``` + +Output + +```console +[18, 25, 37] +``` + +**Or create an array that holds string values:** + +```go +mut users := ['vbrazo', 'donnisnoni95', 'Delta456'] + +println(users) +``` + +Output + +``` +['vbrazo', 'donnisnoni95', 'Delta456'] +``` + +> Note: All elements must have the same type. The following code will not compile. + +```go +mut users := ['vbrazo', 'donnisnoni95', 'Delta456', 0] +``` + +Output + +``` +~/main.v:2:43: bad array element type `int` instead of `string` +``` + +## Create an empty array + +If you want to create a new empty array, just declare `[]` followed by the data type. + +```go +mut names := []string +mut numbers := []int +``` + +## Accessing element of the array + +```go +mut users := ['vbrazo', 'donnisnoni95', 'Delta456'] + +println(users[0]) +println(users[2]) +println(users[1]) +``` + +Output + +```go +vbrazo +Delta456 +donnisnoni95 +``` + +## Append a value to an array + +`<<` is an operator that appends a value to the end of the array. + +```go +mut ages := [18] +ages << 47 + +println(ages) +``` + +Output + +```go +[18, 47] +``` + +It can also append an entire array. + +```go +mut ages := [18] +ages << [47, 49] + +println(ages) +``` + +Output + +``` +[18, 47, 49] +``` + +## Length/size of an array + +`.len` method returns the length of the array. + +```go +mut names := ['Thiago', 'John'] + +println(names.len) +``` + +Output + +``` +2 +``` + +## In operator + +`in` check if an element is inside an array. + +```go +mut names := ['Thiago', 'Alex', 'Joe'] + +println('Vitor' in names) +println('Thiago' in names) +``` + +Output + +``` +false +true +``` + +## Slicing an array + +It's easy to slice an array in V. You can slice an array with the default +V slicing feature without having to call the `slice ()` method. +The syntax is like this `my_array[start..end]` + +```go +animals := ['lion', 'goose', 'chicken', 'turkey', 'tiger'] +poultry := animals[1..4] +println(poultry) // ["goose", "chicken", "turkey"] +``` + +If you want to slice from the start of the index, just ignore it to put `0` and using instead `my_array[..end]` or `my_array[start..]`. + +```go +x := ['h', 'e', 'l', 'l', 'o'] +y := x[..x.len-1] +z := x[1..] +println(y) // ['h', 'e', 'l', 'l'] +println(z) // ['e', 'l', 'l', '0'] +``` + +## Exercises + +1. Write a V program to store elements in an array and print it. +2. Write a V program to read n number of values in an array and display it in reverse order. +3. Write a V program to find the sum of all elements of the array. +4. Write a V program to copy the elements of one array into another array. +5. Write a V program to count a total number of duplicate elements in an array. diff --git a/es/examples/section_3/functions.md b/es/examples/section_3/functions.md new file mode 100644 index 0000000..5bc1258 --- /dev/null +++ b/es/examples/section_3/functions.md @@ -0,0 +1,128 @@ +# 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. + +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. + +```go +fn sum(x, y int) int { + return x + y +} + +println(sum(77, 33)) // 110 +``` + +> Note: The type comes after the argument's name. + +```go +fn full_name(first_name, last_name string) string { + return first_name + ' ' + last_name +} + +println(full_name("Vitor", "Oliveira")) // Vitor Oliveira +``` + +## Variadic Functions + +Functions can also be variadic i.e. accept an infinite number of arguments. +They are not arrays and cannot be returned. + +```go +fn foo(test ...string) { + for txt in test { + println(txt) + } +} + +foo("V", "is", "the", "best", "lang" , "ever") +``` + +Output + +```console +V +is +the +best +lang +ever +``` + +## Multi-Return Functions + +Similar to Go, functions in V can also return multiple and with a different type. + +```go +fn student(name string, age int) (string, int) { + return name, age +} + +name, age := student("Tom", 15) +println(name1) +println(age1) +``` + +Output + +```console +Tom, 15 +``` + +## High Order Functions + +Functions in V can also take in another function as a parameter which is usually +needed for something like sort, map, filter, etc. + +```go +fn square(num int) int { + return num * num +} + +fn run(value int, op fn(int) int) int { + return op(value) +} + +println(run(10, square)) // 100 +``` + +## Naming Rules + +The following are the rules which should be kept in mind while naming functions. + +- Name should not contain Uppercase letters like `AlphaTest` +- Use underscores as separators like `hello_world` +- Name should not start with `_` +- Name should be descriptive as possible +- Name should not contain `__` +- Name should not contain any space + +These rules are from [`Snake_Case`](https://en.wikipedia.org/wiki/Snake_case). V uses Snake Case and prefers it because it is more easy to read, write and understand. + +### Valid Names + +```go +fn i_am_valid() +fn thisworkstoo() +fn print_values_through_struct() +``` + +### Invalid Names + +```go +fn IamNotValid() +fn _print() +fn print__logs() +fn new Make Lexer() +``` + +## Exercises + +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. +5. Write a V program to get the largest element of an array using the function. diff --git a/es/examples/section_3/methods.md b/es/examples/section_3/methods.md new file mode 100644 index 0000000..740e5e6 --- /dev/null +++ b/es/examples/section_3/methods.md @@ -0,0 +1,59 @@ +# Methods + +V does not have classes. But one can define methods for types. +A method is a function that has a special receiver argument, +only a receiver of the specified type can execute this function. +The receiver has its own argument list between `fn` and the method name. + +```go +struct User { + name string + email string +mut: + age int +} + +fn (u User) can_register() bool { + return u.age > 15 +} + +fn (u mut User) has_birthday() { + u.age += 1 +} + +fn main() { + mut bob := User { + name: 'Bob' + email: 'bob@bob.com' + age: 15 + } + alice := User { + name: 'Alice' + email: 'alice@alice-mail.com' + age: 17 + } + println(bob.can_register()) + println("Bob needs to be 16 to register, but he only is ${bob.age}.") + println(alice.can_register()) + bob.has_birthday() + println(bob.age) +} +``` + +Output + +```console +false +Bob needs to be 16 to register, but he only is 15. +true +16 +``` + +This code above realizes two methods for receivers `u` of type `User`. +Note that the method `has_birthday()` has a `mut` receiver, this is needed here since we want to change its data. +The convention of V is not to use receiver names like `self`, `this` or similar things but a short, preferably one letter long, name. + +## Exercises + +1. Create a method for the type `Person` that determines whether a person is underage or not. +2. Create a method that determines whether an `Animal` has fur or not. diff --git a/es/examples/section_3/struct.md b/es/examples/section_3/struct.md new file mode 100644 index 0000000..9eab485 --- /dev/null +++ b/es/examples/section_3/struct.md @@ -0,0 +1,122 @@ +# Struct + +A struct is a composite data type (or record) declaration that defines a physically grouped list of variables under one name in a block of memory, allowing different variables to be accessed via a single pointer or by the struct declared name which returns the same address. + +For people coming from [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming) languages, it can be thought as `class` but with more restrictions. + +```go +struct User { + name string + email string + country string +} + +fn main() { + user := User { + name: "V developers" + email: "developers@vlang.io" + country: "Canada" + } + + println(user.country) +} +``` + +> Note: Structs are allocated on the stack. + +You can use a comma to separate each field when creating a new instance of the struct. It's useful when you want to create a new instance on a single line. + +```go +user := User { name: "V developers", email: "developers@vlang.io", country: "Canada" } +``` + +## The `&` prefix + +You can also allocate a struct on the heap and get a reference to it by using the `&` prefix as follows: + +```go +user := &User{"V developers", "developers@vlang.io", "Canada"} +println(user.name) +``` + +The type of `user` is `&User`. It's a reference to `User`. + +## Access modifiers + +Struct fields are `private` and `immutable` by default. Their access modifiers can be changed with `pub` and `mut`. + +```go +struct User { + email string // private and immutable (default) +} +``` + +You can define them as `private mutable`. + +```go +struct User { + email string +mut: + first_name string // private mutable + last_name string // (you can list multiple fields with the same access modifier) +} +``` + +You can also define them as `public immmutable` (readonly). + +```go +struct User { + email string +mut: + first_name string + last_name string +pub: + sin_number int // public immutable (readonly) +} +``` + +or as `public`, but `mutable` only in the parent module. + +```go +struct User { + email string +mut: + first_name string + last_name string +pub: + sin_number int +pub mut: + phone int // public, but mutable only in parent module +} +``` + +or `public` and `mutable` both inside and outside parent module. + +```go +struct User { + email string +mut: + first_name string + last_name string +pub: + sin_number int +pub mut: + phone int +__global: + address_1 string // public and mutable both inside and outside parent module + address_2 string // (not recommended to use, that's why the 'global' keyword + city string // starts with __) + country string + zip string +} +``` + +## Naming Rules + +- The name of the `struct` should always be capital. +- Use [`Snake_Case`](https://github.com/v-community/v_by_example/blob/master/en/examples/section_1/variables.md#naming-rules) for variable naming. + +## Exercises + +1. Create a struct that stores and displays `User` information. +2. Create a `Point` struct that holds `x` and `y` field and guard them with private and public. diff --git a/es/examples/section_4/README.md b/es/examples/section_4/README.md new file mode 100644 index 0000000..1ce77c7 --- /dev/null +++ b/es/examples/section_4/README.md @@ -0,0 +1 @@ +# Section 4 diff --git a/es/examples/section_4/array-functions.md b/es/examples/section_4/array-functions.md new file mode 100644 index 0000000..97a34c5 --- /dev/null +++ b/es/examples/section_4/array-functions.md @@ -0,0 +1,63 @@ +# Array Functions + +## `repeat` + +Syntax + +```go +array.repeat(number type) +``` + +Makes an array with the given element number of times. + +```go +foo := [1, 2].repeat(5) +println(foo) // [1, 2, 1, 2, 1, 2, 1, 2, 1, 2] +``` + +## `delete` + +Syntax + +```go +array.delete(ix type) +``` + +Deletes the element present in the array at index `ix`. + +```go +mut even_numbers := [2, 4, 6, 8, 10] +even_numbers.delete(3) +println(even_numbers) // [2, 4, 6, 10] +``` + +## `reverse` + +Syntax + +```go +array.reverse() +``` + +Reverses the array. + +```go +float_num := [1.1, 1.3, 1.25, 1.4] +float_num.reverse() // [1.4, 1.25, 1.3, 1.1] +``` + +## `clone` + +Syntax + +```go +array.clone() +``` + +Clones and returns a new array. + +```go +foo := [1, 2, 4, 5, 4, 6] +foo1 := foo.clone() +println(foo1) // [1, 2, 4, 5, 4, 6] +``` diff --git a/es/examples/section_4/files.md b/es/examples/section_4/files.md new file mode 100644 index 0000000..bd2ba5b --- /dev/null +++ b/es/examples/section_4/files.md @@ -0,0 +1,80 @@ +# Files + +A File in V is an abstraction of any file object accessible by the program and is closely associated with `os` library. + +## Reading Files + +Reading a file is an important task to tackle several different problems in computer science. In order to accomplish this task you can use the V native library `os` as described below: + +```go +import os + +fn main() { + mut fp := flag.new_flag_parser(os.args) + generator := fp.string('generator', '', 'generator name') + method := fp.string('method', '', 'generator method name') + path := './data/$generator/$method' + + if os.file_exists(path) { + print_generator_sample(path) + } else { + println('File does not exist') + return + } +} + +fn print_generator_sample(path string) { + contents := os.read_file(path.trim_space()) or { + println('Failed to open $path') + return + } + + lines := contents.split_into_lines() + length := lines.len + + print_random_element(lines, length) +} + +fn print_random_element(lines []string, length int) { + rand.seed(time.now().uni) + + println(lines[rand.next(length-1)]) +} +``` + +## Writing files + +Writing files in V is similar to read files. + +```go +import os + +fn main() { + path := './data/file.txt' + text := 'Full text description.' + + if contents := os.write_file(path, text) or { + println('Failed while creating file') + return + } + + content_lines = read_file(path) + print(content_lines) +} + +fn read_file(path string) { + contents := os.read_file(path.trim_space()) or { + println('Failed to open $path') + return + } + + return contents.split_into_lines() +} +``` + +## Exercises + +1. Write a V program to create a new file with content. +2. Write a V program to read 2 different files and display their content. +3. Read how the `os` library works in V and understand how you could use it. +4. Encode a nested json string and write a new file with the result. diff --git a/es/examples/section_4/json.md b/es/examples/section_4/json.md new file mode 100644 index 0000000..1c6d11d --- /dev/null +++ b/es/examples/section_4/json.md @@ -0,0 +1,67 @@ +# JSON + +JavaScript Object Notation (JSON) is a lightweight data-interchange format that is easy for humans to read and write. Furthermore, equally simple for machines to generate and/or parse. +JSON is completely language agnostic and that's why it's the ideal interchange format. + +To read more about JSON visit: [json.org](http://json.org). + +## Parsing JSON + +To parse a JSON string received by another application or generated within your existing application: + +```go +import json + +struct Customer { + first_name string + last_name string + hometown string +} + +fn main() { + customers_string := '[{ "first_name": "Vitor", "last_name": "Oliveira", "hometown": "Rio de Janeiro" }, { "first_name": "Don", "last_name": "Nisnoni", "hometown": "Kupang" }]' + customers := json.decode([]Customer, customers_string) or { + eprintln('Failed to parse json') + return + } + + // Print the list of customers + for customer in customers { + println('$customer.first_name $customer.last_name: $customer.hometown') + } +} +``` + +## Generating JSON + +Creating a JSON string for communication or serialization is just as simple. We decode and encode in the example below: + +```go +import json + +struct Customer { + first_name string + last_name string + hometown string +} + +fn main() { + customer_string := '[{ "first_name": "Vitor", "last_name": "Oliveira", "hometown": "Rio de Janeiro"}]' + + customer := json.decode([]Customer, customer_string) or { + eprintln('Failed to parse json') + return + } + + encoded_json := json.encode(customer) + + println(encoded_json) +} +``` + +## Exercises + +1. Compare how you handle JSON in your favorite language and V. +2. Build an `Address` struct that contains address information. +3. Use the `Address` struct to decode and encode a string that contains JSON format. +4. Create 2 structs: `Address` and `User` where a user has many addresses. Now receive a string with a nested JSON like `'[{ "first_name": "Vitor", "last_name": "Oliveira", "hometown": "Rio de Janeiro", "addresses": [{ street_name: "Rua Princesa Isabel", city: "Rio de Janeiro", country: "Brazil" }] }]'`, decode and encode it. diff --git a/es/examples/section_4/testing.md b/es/examples/section_4/testing.md new file mode 100644 index 0000000..3b5c85e --- /dev/null +++ b/es/examples/section_4/testing.md @@ -0,0 +1,64 @@ +# Testing + +Testing in software development is a process that aims to evaluate the functionality of an application with an intent to find whether the code met the specified requirements or not as well as identifying the problems to ensure that the product has expected quality. + +## Automated tests + +Automated tests follow the process of testing the software using an automation tool to find the defects. In this process, programmers execute the test scripts and generate the test results automatically by using automation tools. + +## Tests in V + +In V, all test files have to be named with the following format: `*_test.v` and the functions should start with `test_*`. + +```go +// sum.v in subfolder sum +module sum + +pub fn sum(a, b int) int { + return a + b +} +``` + +```go +// sum_test.v +import sum + +fn test_sum() { + assert sum.sum(2, 3) == 5 + // assert sum.sum(2, 3) == 777 // => sum_test.v:6: FAILED assertion +} +``` + +To execute the test, you should run `v test_sum.v`. + +### Examples + +1. Testing JSON structures: + +```go +import json + +fn test_encode_customer(){ + customer := Customer{ first_name: "Vitor", last_name: "Oliveira" } + expected := '{ "first_name": "Vitor", "last_name": "Oliveira" }' + + encoded_json := json.encode(customer) + assert encoded_json == expected +} +``` + +2. Testing files: + +```go +import os + +fn test_file_creation() { + file_name := './new_file.txt' + content := 'text' + + os.write_file(file_name, content) + assert content.len == os.file_size(file_name) + + os.rm(file_name) +} +``` From 21883c3452936be2f7cd35922761c437a42effd9 Mon Sep 17 00:00:00 2001 From: Jhon James Quintero Date: Thu, 13 Feb 2020 18:52:34 -0500 Subject: [PATCH 2/2] More work in spanish version --- README.md | 1 + es/examples/README.md | 45 ++++++++++++++++---------------- es/examples/section_1/strings.md | 32 ++++++++++++----------- 3 files changed, 41 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 0abe42c..934719f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # V by Example [Brazilian Portuguese](/pt-br/README.md) | [Deutsch](/de/README.md) | [English](README.md) | [Bahasa Indonesia](/id/README.md) | [Chinese](cn/examples/README.md) | [Spanish](es/examples/README.md) + > Learn V by Examples V by Example is a direct introduction to V by using annotated program examples. diff --git a/es/examples/README.md b/es/examples/README.md index 895b484..936ea05 100644 --- a/es/examples/README.md +++ b/es/examples/README.md @@ -12,9 +12,9 @@ V por ejemplos es una introducción directa al lenguaje V usando ejemplos con co Discord: [https://discord.gg/d3Qk65J](https://discord.gg/d3Qk65J) -## Section 1 +## Sección 1 -Introduction to V by presenting a few basic examples and exercises. +Introducción al lenguaje V usando algunos ejemplos básicos y ejercicios. - [Hola Mundo](es/examples/section_1/hello_world.md) - [Palabras clave de V](en/examples/section_1/keywords.md) @@ -23,36 +23,37 @@ Introduction to V by presenting a few basic examples and exercises. - [Cadenas](en/examples/section_1/strings.md) - [Comentarios](en/examples/section_1/comment.md) -## Section 2 +## Sección 2 -This section discusses the main operators and conditional statements in V. +Esta sección discute los principales operadores y las sentencias condicionales en V. -- [Operator](en/examples/section_2/operator.md) +- [Operadores](en/examples/section_2/operator.md) - [If-else](en/examples/section_2/if-else.md) - [Match](en/examples/section_2/match.md) -- [Loops](en/examples/section_2/loops.md) +- [Ciclos](en/examples/section_2/loops.md) -## Section 3 +## Sección 3 -A study on functions and methods and in the most important data structures in V: arrays and struct. +Un estudio de funciones y métodos y de las estructuras de datos más importantes en V: +arreglos y estructuras -- [Functions](en/examples/section_3/functions.md) -- [Arrays](en/examples/section_3/arrays.md) -- [Struct](en/examples/section_3/struct.md) -- [Methods](en/examples/section_3/methods.md) +- [Funciones](en/examples/section_3/functions.md) +- [Arreglos](en/examples/section_3/arrays.md) +- [Estructuras](en/examples/section_3/struct.md) +- [Métodos](en/examples/section_3/methods.md) -## Section 4 +## Sección 4 -In this section, we dive deeper and study the features inside the Array object. Other examples like JSON, Writing/reading files and Testing are covered. +En esta sección, discutimos a profundidad las características de los Objetos typo Arreglo. Otros ejemplos como JSON, Escritura/Lectura de archivos y Pruebas. -- [Array Functions](en/examples/section_4/array-functions.md) -- [Testing](en/examples/section_4/testing.md) -- [Files](en/examples/section_4/files.md) +- [Funciones de Arreglos](en/examples/section_4/array-functions.md) +- [Pruebas](en/examples/section_4/testing.md) +- [Archivos](en/examples/section_4/files.md) - [JSON](en/examples/section_4/json.md) -## Team +## Equipo -Current list of maintainers/authors: +Lista de autores y colaboradores: - [Don Alfons Nisnoni](https://github.com/dhonx) - [Ivo-Balbaert](https://github.com/ibalbaert) @@ -60,10 +61,10 @@ Current list of maintainers/authors: - [Swastik Baranwal](https://github.com/Delta456) - [Vitor Oliveira](https://github.com/vbrazo) -## Contributing +## Colaborando -See our [CONTRIBUTING.md](CONTRIBUTING.md) and start contributing today. We usually elect new maintainers based on contributions. +Revisa [CONTRIBUTING.md](CONTRIBUTING.md) y empieza a ayudar desde hoy. Generalmente se seleccionan los nuevos colaboradores con base in las contribuciones. -## License +## Licencia [MIT](LICENSE) diff --git a/es/examples/section_1/strings.md b/es/examples/section_1/strings.md index 8994d48..23a71b3 100644 --- a/es/examples/section_1/strings.md +++ b/es/examples/section_1/strings.md @@ -1,6 +1,7 @@ -# Strings +# Cadenas -In V one can define strings using the `:=` operator. Strings (like other variables) are immutable by default. One is free to use `""` or `''` to denote a string. When using `vfmt` all double-quoted strings will be converted to single-quoted ones unless it contains a single quote character. + +En V se pueden definir las cadenas usando el operador `:=`. Las cadenas (como las variables de los otros tipos) son inmutables por defecto. Se puede usar `""` o `''` para denotar los literales tipo cadena. Cuando se usa `vfmt` todas los literales definidos usando comillas dobles se convierten a literales de comillas simples. ```go name := 'Bob' @@ -8,18 +9,19 @@ println(name) // Bob println(name.len) // 3 ``` -Getting the length of a string works with `.len`. +Para objetner la longitud de una cadena se usa `.len`. + +## Interpolación -## Interpolation +Es posible hacer la interpolación de cadenas usando `$` antes del nombre de la variable: -It is possible to do string interpolation with `$` in front of the variable: ```go name:= 'Bob' println('Hello $name!') // Hello Bob! ``` -One can have more complex expressions with interpolation syntax by using `${}`: +Se pueden tener expresiones más complejas con la interpolación usando `${}`: ```go struct User { @@ -34,9 +36,9 @@ println('Say Hello to a new User: ${bob.name}, ${bob.age}') // Say H println('${bob.name}s age is higher or equal to 18: ${bob.age >= 18}') // 0 <=> number representation for false ``` -## Concatenation +## Concatenación -Strings can be concatenated with the `+` operator. +Las cadenas se concatenan con `+` operator. ```go text := 'Hello' @@ -46,7 +48,7 @@ println(text + ' World!') // Hello World! println(concatenated_text) // Hello World! ``` -Appending to a string works with concatenation as well as with `+=` operator. Since strings are immutable by default it is only possible to do this if they are declared with `mut`. +Las cadenas se pueden concatenar también con el operador `+=`. Dado que las cadenas son inmutables por defecto esto es sólo posible si la variable se ha declarado `mut`.. ```go mut hello := 'Hello ' @@ -54,7 +56,7 @@ hello += 'from V!' // appends 'from V!' to the string stored in hello. println(hello) // Hello from V! ``` -In V, string data is encoded using UTF-8 and the string itself is a read-only array of bytes. This makes slicing possible, which means we can access single-character literals or slices of a string variable. +En V, las cadenas son codificadasd usando UTF-8 y las cadenas en si mismas son un arreglo de bytes de sólo lectura. Esto hace que se posible hacer slicing, es decir es posible acceder a los caracteres de forma individual o a slices de la variable typo cadena. ```go robert := 'Robert' @@ -63,18 +65,18 @@ rob := robert[0..3] // Rob println('The persons of interest are: $robert, $bert, $rob') // The persons of interest are: Robert, bert, Rob ``` -### Notes +### Notas -When using `some_string[start..end]` syntax the `end` is **not** inclusive. +Cuando se usa `some_string[start..end]`, `end` es **no** inclusivo. -All operators in V must have values of the same type on both sides. The code below will not compile because `age` is an `int`: +Todos los operadores en V tienen que tener valores del mismo tipo en ambos lados. El código siguiente no compila correctamente, debido a que `age` es de tipo `int`: ```go age := 25 println('age = ' + age) ``` -We therefore need to convert it to string by using `.str()` or use string interpolation (preferred): +Es necesario convertir el valor a cadena usando `.str()` o usar interpolación de cadenas (preferido): ```go age := 25 @@ -82,7 +84,7 @@ println('age = ' + age.str()) // age = 25 println('age = $age') // age = 25 ``` -To define character literals use: ` `` `. Raw strings can be defined as prepending `r`. They are not escaped. +Para definir literales tipo caracter se usa: ` `` `. Cadenas planas se pueden definir usando `r` entes del literal tipo cadena. De este modo la cadena no es escapada. ```go hello := 'Hello\nWorld'