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

Start spanish version #156

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
[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.
Expand Down
1 change: 1 addition & 0 deletions es/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Examples
70 changes: 70 additions & 0 deletions es/examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 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)

## Sección 1

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)
- [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)

## Sección 2

Esta sección discute los principales operadores y las sentencias condicionales en V.

- [Operadores](en/examples/section_2/operator.md)
- [If-else](en/examples/section_2/if-else.md)
- [Match](en/examples/section_2/match.md)
- [Ciclos](en/examples/section_2/loops.md)

## Sección 3

Un estudio de funciones y métodos y de las estructuras de datos más importantes en V:
arreglos y estructuras

- [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)

## Sección 4

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.

- [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)

## Equipo

Lista de autores y colaboradores:

- [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)

## Colaborando

Revisa [CONTRIBUTING.md](CONTRIBUTING.md) y empieza a ayudar desde hoy. Generalmente se seleccionan los nuevos colaboradores con base in las contribuciones.

## Licencia

[MIT](LICENSE)
1 change: 1 addition & 0 deletions es/examples/section_1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Section 1
14 changes: 14 additions & 0 deletions es/examples/section_1/comment.md
Original file line number Diff line number Diff line change
@@ -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*/
*/
```
50 changes: 50 additions & 0 deletions es/examples/section_1/hello_world.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 13 additions & 0 deletions es/examples/section_1/keywords.md
Original file line number Diff line number Diff line change
@@ -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.
47 changes: 47 additions & 0 deletions es/examples/section_1/primitives.md
Original file line number Diff line number Diff line change
@@ -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 2<sup>7</sup> -1 |
| int16 | 16 bits | -2<sup>15</sup> to 2<sup>15</sup> - 1 |
| int | 32 bits | -2<sup>31</sup> to 2<sup>31</sup> - 1 |
| int64 | 64 bits | -2<sup>63</sup> to 2<sup>63</sup> - 1 |
| int128 | 128 bits | -2<sup>127</sup> to 2<sup>127</sup> - 1 |

### Unsigned Integer

| Type | Size | Range |
| ---- | :------: | -----------------------: |
| byte | 8 bits | 0 to 2<sup>7</sup> -1 |
| u16 | 16 bits | 0 to 2<sup>15</sup> - 1 |
| u32 | 32 bits | 0 to 2<sup>31</sup> - 1 |
| u64 | 64 bits | 0 to 2<sup>63</sup> - 1 |
| u128 | 128 bits | 0 to 2<sup>127</sup> - 1 |
95 changes: 95 additions & 0 deletions es/examples/section_1/strings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Cadenas


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'
println(name) // Bob
println(name.len) // 3
```

Para objetner la longitud de una cadena se usa `.len`.

## Interpolación

Es posible hacer la interpolación de cadenas usando `$` antes del nombre de la variable:


```go
name:= 'Bob'
println('Hello $name!') // Hello Bob!
```

Se pueden tener expresiones más complejas con la interpolación usando `${}`:

```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
```

## Concatenación

Las cadenas se concatenan con `+` operator.

```go
text := 'Hello'
concatenated_text := text + ' World!'
println(text) // Hello
println(text + ' World!') // Hello World!
println(concatenated_text) // Hello World!
```

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 '
hello += 'from V!' // appends 'from V!' to the string stored in hello.
println(hello) // Hello from V!
```

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'
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
```

### Notas

Cuando se usa `some_string[start..end]`, `end` es **no** inclusivo.

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)
```

Es necesario convertir el valor a cadena usando `.str()` o usar interpolación de cadenas (preferido):

```go
age := 25
println('age = ' + age.str()) // age = 25
println('age = $age') // age = 25
```

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'
println(hello) // Hello
// World
raw_hello := r'Hello\nWorld'
println(raw_hello) // Hello\nWorld
```
80 changes: 80 additions & 0 deletions es/examples/section_1/variables.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions es/examples/section_2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Section 2
Loading