In [2]:
genero = :hombre


Out[2]:
:hombre

In [3]:
typeof(genero)


Out[3]:
Symbol

In [4]:
?Symbol


search: Symbol

Out[4]:
Symbol(x...) -> Symbol

Create a Symbol by concatenating the string representations of the arguments together.


In [5]:
?collect


search: collect Collections

Out[5]:
collect(element_type, collection)

Return an Array with the given element type of all items in a collection or iterable. The result has the same shape and number of dimensions as collection.

jldoctest
julia> collect(Float64, 1:2:5)
3-element Array{Float64,1}:
 1.0
 3.0
 5.0
collect(collection)

Return an Array of all items in a collection or iterator. For associative collections, returns Pair{KeyType, ValType}. If the argument is array-like or is an iterator with the HasShape() trait, the result will have the same shape and number of dimensions as the argument.

Example

jldoctest
julia> collect(1:2:13)
7-element Array{Int64,1}:
  1
  3
  5
  7
  9
 11
 13

In [8]:
randn(1)


Out[8]:
1-element Array{Float64,1}:
 -0.815157

In [9]:
# Se pueden hacer operaciones en una misma linea, pero hay que separarlas con ;
resultado = a=20;a*2


Out[9]:
40

In [11]:
#Para desplegar un error es con el comando error("Mensaje de error")
α = 10
if α > 10
    println("Todo bien")
else 
    error("Algo ha salido mal")
    println("Después")
end


Algo ha salido mal

Stacktrace:
 [1] error(::String) at ./error.jl:21
 [2] include_string(::String, ::String) at ./loading.jl:522

In [12]:
# También se pueden sacar mensajes de advertencia, que no obligan al programa detenerse

α = 10
if α > 10
    println("Todo bien")
else 
    warn("Algo ha salido mal")
    println("Después")
end


Después
WARNING: Algo ha salido mal

In [16]:
try
    open("archivoInexistente.txt")
catch ex
    showerror(STDOUT,ex)
    warn("Ciertas cosas no podrán funcionar sin este archivo")
end
println("\nDespués del error")


SystemError: opening file archivoInexistente.txt: No such file or directory
Después del error
WARNING: Ciertas cosas no podrán funcionar sin este archivo

In [25]:
# Para poder dejar asignar los parametros por nombre tienen que ir después de un ;
function prueba(;x=1,y=2,z=3)
    println(x+y+z)
end
prueba(x=2)


7

In [29]:
# Julia también tiene List Comprehension 
arr1 = randn(10)
arr2 = round.([x*100 for x in arr1])


Out[29]:
10-element Array{Float64,1}:
  -41.0
   79.0
  141.0
  106.0
  -55.0
 -263.0
   19.0
   -5.0
   96.0
  -28.0

In [37]:
# Diccionarios en Julia

diccionario = Dict("Numero 1" => 10,
    "Num 2" => 20,
    true => 30)

println(diccionario[true])
diccionario[:true] = 40
diccionario[true]


30
Out[37]:
40

In [38]:
# Para obtener las llaves del diccionario en un array:
llavesDic = keys(diccionario)

# Para obtener los valores del diccionario en un array:
valuesDic = values(diccionario)


Out[38]:
Base.ValueIterator for a Dict{Any,Int64} with 3 entries. Values:
  20
  10
  40

In [ ]: