Hello everyone!
I'm trying to make an Spanish translated version of Julia, AKA Julieta, using JuliaParser.jl and I would love to hear your opinions (if this belongs to julie-users I'll move it there).
In order to make spanish aliases of identifiers, for functions a simple const assignement will do:
julia> const primos = Base.primes
primes (generic function with 2 methods)
For types using typealias:
julia> typealias Ent Int
Int64
For macros more macros:
julia> macro tiempo(ex) :(@time $ex) end
julia> @tiempo 1 + 1
0.000002 seconds (4 allocations: 160 bytes)
2
SubModules:
julia> Base.eval(:(const Prueba = Test))
Base.Test
julia> using Base.Prueba
For reserved keywords this is what I've been able to do so far:
_
_ _ _(_)_ | A fresh approach to technical computing
(_) | (_) (_) | Documentation: http://docs.julialang.org
_ _ _| |_ __ _ | Type "?help" for help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 0.5.0-dev+1526 (2015-11-30 04:16 UTC)
_/ |\__'_|_|_|\__'_| | Commit b775873 (18 days old master)
|__/ | x86_64-w64-mingw32
julia> cd(Pkg.dir("JuliaParser"))
shell> git branch
* Julieta
fix-tests
master
julia> using JuliaParser.Parser
julia> julieta_code = """
empezar
x = 42
fin
"""
" empezar\n x = 42\n fin\n"
julia> julia_code = """
begin
x = 42
end
"""
" begin\n x = 42\n end\n"
julia> Parser.parse(julieta_code)
quote
$(Expr(:line, 2, :none))
x = 42
end
julia> Base.parse(julia_code)
quote # none, line 2:
x = 42
end
julia> eval(Parser.parse(julieta_code)) == eval(Base.parse(julia_code))
true
A type:
julia> julieta_code = """
tipo Tablero
cols :: Ent
nodos :: Ent
diag45 :: Ent
diag135 :: Ent
soluciones :: Ent
Tablero() = nuevo(0, 0, 0, 0, 0)
fin
"""
" tipo Tablero\n cols :: Ent\n nodos :: Ent\n
diag45 :: Ent\n diag135 :: Ent\n soluciones :: Ent\n \n
Tablero() = nuevo(0, 0, 0, 0, 0)\n fin\n"
julia> Parser.parse(julieta_code)
:(type Tablero # , line 2:
cols::Ent # , line 3:
nodos::Ent # , line 4:
diag45::Ent # , line 5:
diag135::Ent # , line 6:
soluciones::Ent # , line 8:
Tablero() = begin
$(Expr(:line, 8, :none))
nuevo(0,0,0,0,0)
end
end)
julia> eval(ans)
ERROR: UndefVarError: Ent not defined
in eval at boot.jl:263
in eval at boot.jl:262
in eval at boot.jl:263
julia> typealias Ent Int
Int64
julia> Parser.parse(julieta_code)
:(type Tablero # , line 2:
cols::Ent # , line 3:
nodos::Ent # , line 4:
diag45::Ent # , line 5:
diag135::Ent # , line 6:
soluciones::Ent # , line 8:
Tablero() = begin
$(Expr(:line, 8, :none))
nuevo(0,0,0,0,0)
end
end)
julia> eval(ans)
julia> Tablero
Tablero
julia> Tablero()
ERROR: UndefVarError: nuevo not defined
in call at none:8
in eval at boot.jl:263
My first question is how does the implementation of `new` works? Where is it defined in the Julia source code (I'm not asking you to explain me JuliaParser code, but I feel that if I understand the Julia Implementation then I'll be able to understand JuliaParser) I don't see how to alias that one.
The second is how does the implementation of the Julia REPl works?
I just need some hints, please don't tell me to go read the source, I'm doing that (I wish it where better documented with comments), what I need is a way to instantiate another REPL, but make it use my hacked JuliaParser.Parser.parse instead of Base.parse. Ideally i would like to put in .juliarc.jl
using Julieta; julieta_repl()
My third question is, is there a better way to do this?
My last question is about how do you feel about the idea of Julia being fully i18n to several languages?, here is some reference:
*
https://en.wikipedia.org/wiki/Non-English-based_programming_languagesThis would be a tremendous help in the educational space, I don't think that English
must be a prerequisite in order to learn programming, which sadly is true today. I've been teaching children beggining Python lesons, we have to go slowly and I have to teach them some english along the way most times. And even the smart and motivated ones get slowed down by this, I have to show them pseudocode (which more and more resembles Julieta lately) in spanish and then do the thing in Python.
Imagine we had registered all identifiers, strings with errors, warnings, info and documentation and that their meanings could be programatically swapped by others, It could be done with "language extension packs".
Something that like:
$ export LANG=es_MX
$ julia # this starts in spanish!
I'm really interested in your opinions.
This is my mock example:
_
_ _ _(_)_ _ | Un nuevo enfoque para la computación técnica
(_) | (_) (_)| | | Documentación: http://docs.julialang.es.org
_ _ _| |_ ___| |_ __ _ | Tecleé "?ayuda" para la ayuda.
| | | | | | |/ _ \ __| _` | |
| | |_| | | | __/ || (_| | | Versión 1.0 (201?-??-?? ??:?? UTC)
_/ |\__'_|_|_|\___|_| \__'_| | Commit ??????? (? días detrás de master)
|__/ | x86_64-w64-mingw32
julieta> módulo NReinas
exportar solucionar
tipo Tablero
cols :: Ent
nodos :: Ent
diag45 :: Ent
diag135 :: Ent
soluciones :: Ent
Tablero() = nuevo(0, 0, 0, 0, 0)
fin
"Marca si está ocupada una casilla."
función marcar!(t::Tablero, k::Ent, j::Ent)
t.cols $= (1 << j)
t.diag135 $= (1 << (j + k))
t.diag45 $= (1 << (32 + j - k))
fin
"Prueba si una casilla está amenazada."
función probar(t::Tablero, k::Ent, j::Ent)
t.cols & (1 << j) +
t.diag135 & (1 << (j + k)) +
t.diag45 & (1 << (32 + j - k)) == 0
fin
"Solucionador de retroceso."
función solucionar!(t::Tablero, niv::Ent, dx::Ent)
si niv > 0
por i en 0:dx - 1
si probar(t, niv, i) == verdadero
marcar!(t, niv, i)
solucionar!(t, niv - 1, dx)
marcar!(t, niv, i)
fin
fin
sino
por i en 0:dx - 1
si probar(t, 0, i) == verdadero
t.soluciones += 1
fin
fin
fin
t.nodos += 1
t.soluciones
fin
"Soluciona el problema de las `N` reinas, en un tablero de $n × n$ casillas."
solucionar(n::Ent) = solucionar!(Tablero(), n - 1, n)
fin
julieta> usando NReinas
NReinas
julieta> solucionar(8)
92
julieta> @tiempo solucionar(15)
13.114574 segundos (6 asignaciones: 224 bytes)
2279184
ayuda?> solucionar
buscar: solucionar
Soluciona el problema de las N Reinas, en un tablero de n × n casillas.
julieta>