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

julia 1.4 upgrade #507

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 9 additions & 6 deletions impls/julia/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:vivid
FROM ubuntu:18.04
MAINTAINER Joel Martin <[email protected]>

##########################################################
Expand All @@ -22,8 +22,11 @@ WORKDIR /mal
##########################################################

# Julia
RUN apt-get -y install software-properties-common
RUN apt-add-repository -y ppa:staticfloat/juliareleases
RUN apt-get update -y
RUN apt-get -y install julia

RUN apt-get -y install wget unzip
RUN \
mkdir -p /opt && cd /opt && \
wget https://julialang-s3.julialang.org/bin/linux/x64/1.4/julia-1.4.1-linux-x86_64.tar.gz && \
tar zxpf julia-1.4.1-linux-x86_64.tar.gz && \
ln -s /opt/julia-1.4.1/bin/julia /usr/bin/julia

ENV HOME /mal
52 changes: 26 additions & 26 deletions impls/julia/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,26 +68,26 @@ function with_meta(obj, meta)
end

ns = Dict{Any,Any}(
symbol("=") => (a,b) -> types.equal_Q(a, b),
Symbol("=") => (a,b) -> types.equal_Q(a, b),
:throw => (a) -> throw(types.MalException(a)),

symbol("nil?") => (a) -> a === nothing,
symbol("true?") => (a) -> a === true,
symbol("false?") => (a) -> a === false,
symbol("string?") => string_Q,
symbol("symbol") => (a) -> symbol(a),
symbol("symbol?") => (a) -> typeof(a) === Symbol,
symbol("keyword") => (a) -> a[1] == '\u029e' ? a : "\u029e$(a)",
symbol("keyword?") => keyword_Q,
symbol("number?") => (a) -> isa(a, AbstractFloat) || isa(a, Int64),
symbol("fn?") => (a) -> isa(a, Function) || (isa(a, types.MalFunc) && !a.ismacro),
symbol("macro?") => (a) -> isa(a, types.MalFunc) && a.ismacro,

symbol("pr-str") => (a...) -> join(map((e)->pr_str(e, true),a)," "),
Symbol("nil?") => (a) -> a === nothing,
Symbol("true?") => (a) -> a === true,
Symbol("false?") => (a) -> a === false,
Symbol("string?") => string_Q,
Symbol("Symbol") => (a) -> Symbol(a),
Symbol("Symbol?") => (a) -> typeof(a) === Symbol,
Symbol("keyword") => (a) -> a[1] == '\u029e' ? a : "\u029e$(a)",
Symbol("keyword?") => keyword_Q,
Symbol("number?") => (a) -> isa(a, AbstractFloat) || isa(a, Int64),
Symbol("fn?") => (a) -> isa(a, Function) || (isa(a, types.MalFunc) && !a.ismacro),
Symbol("macro?") => (a) -> isa(a, types.MalFunc) && a.ismacro,

Symbol("pr-str") => (a...) -> join(map((e)->pr_str(e, true),a)," "),
:str => (a...) -> join(map((e)->pr_str(e, false),a),""),
:prn => (a...) -> println(join(map((e)->pr_str(e, true),a)," ")),
:println => (a...) -> println(join(map((e)->pr_str(e, false),a)," ")),
symbol("read-string") => (a) -> reader.read_str(a),
Symbol("read-string") => (a) -> reader.read_str(a),
:readline => readline_mod.do_readline,
:slurp => (a) -> readall(open(a)),

Expand All @@ -97,30 +97,30 @@ ns = Dict{Any,Any}(
:>= => >=,
:+ => +,
:- => -,
symbol("*") => *,
Symbol("*") => *,
:/ => div,
symbol("time-ms") => () -> round(Int, time()*1000),
Symbol("time-ms") => () -> round(Int, time()*1000),

:list => (a...) -> Any[a...],
symbol("list?") => (a) -> isa(a, Array),
Symbol("list?") => (a) -> isa(a, Array),
:vector => (a...) -> tuple(a...),
symbol("vector?") => (a) -> isa(a, Tuple),
symbol("hash-map") => types.hash_map,
symbol("map?") => (a) -> isa(a, Dict),
Symbol("vector?") => (a) -> isa(a, Tuple),
Symbol("hash-map") => types.hash_map,
Symbol("map?") => (a) -> isa(a, Dict),
:assoc => (a, b...) -> merge(a, types.hash_map(b...)),
:dissoc => (a, b...) -> foldl((x,y) -> delete!(x,y),copy(a), b),
:get => (a,b) -> a === nothing ? nothing : get(a,b,nothing),
symbol("contains?") => haskey,
Symbol("contains?") => haskey,
:keys => (a) -> [keys(a)...],
:vals => (a) -> [values(a)...],

symbol("sequential?") => types.sequential_Q,
Symbol("sequential?") => types.sequential_Q,
:cons => (a,b) -> [Any[a]; Any[b...]],
:concat => concat,
:nth => (a,b) -> b+1 > length(a) ? error("nth: index out of range") : a[b+1],
:first => (a) -> a === nothing || isempty(a) ? nothing : first(a),
:rest => (a) -> a === nothing ? Any[] : Any[a[2:end]...],
symbol("empty?") => isempty,
Symbol("empty?") => isempty,
:count => (a) -> a == nothing ? 0 : length(a),
:apply => do_apply,
:map => do_map,
Expand All @@ -129,9 +129,9 @@ ns = Dict{Any,Any}(
:seq => do_seq,

:meta => (a) -> isa(a,types.MalFunc) ? a.meta : nothing,
symbol("with-meta") => with_meta,
Symbol("with-meta") => with_meta,
:atom => (a) -> types.Atom(a),
symbol("atom?") => (a) -> isa(a,types.Atom),
Symbol("atom?") => (a) -> isa(a,types.Atom),
:deref => (a) -> a.val,
:reset! => (a,b) -> a.val = b,
:swap! => (a,b,c...) -> a.val = do_apply(b, a.val, c),
Expand Down
2 changes: 1 addition & 1 deletion impls/julia/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module env

export Env, env_set, env_find, env_get

type Env
struct Env
outer::Any
data::Dict{Symbol,Any}
end
Expand Down
6 changes: 3 additions & 3 deletions impls/julia/printer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ function pr_str(obj, print_readably=true)
":$(obj[3:end])"
elseif _r
str = replace(replace(replace(obj,
"\\", "\\\\"),
"\"", "\\\""),
"\n", "\\n")
"\\" => "\\\\"),
"\"" => "\\\""),
"\n" => "\\n")
"\"$(str)\""
else
obj
Expand Down
20 changes: 10 additions & 10 deletions impls/julia/reader.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export read_str

import types

type Reader
mutable struct Reader
tokens
position::Int64
end
Expand Down Expand Up @@ -33,15 +33,15 @@ end

function read_atom(rdr)
token = next(rdr)
if ismatch(r"^-?[0-9]+$", token)
if match(r"^-?[0-9]+$", token) !== nothing
parse(Int,token)
elseif ismatch(r"^-?[0-9][0-9.]*$", token)
elseif match(r"^-?[0-9][0-9.]*$", token) !== nothing
float(token)
elseif ismatch(r"^\"(?:\\.|[^\\\"])*\"$", token)
replace(token[2:end-1], r"\\.", (r) -> get(Dict("\\n"=>"\n",
elseif match(r"^\"(?:\\.|[^\\\"])*\"$", token) !== nothing
replace(token[2:end-1], r"\\." => (r) -> get(Dict("\\n"=>"\n",
"\\\""=>"\"",
"\\\\"=>"\\"), r, r))
elseif ismatch(r"^\".*$", token)
elseif match(r"^\".*$", token) !== nothing
error("expected '\"', got EOF")
elseif token[1] == ':'
"\u029e$(token[2:end])"
Expand All @@ -52,7 +52,7 @@ function read_atom(rdr)
elseif token == "false"
false
else
symbol(token)
Symbol(token)
end
end

Expand Down Expand Up @@ -95,14 +95,14 @@ function read_form(rdr)
[[:unquote]; Any[read_form(rdr)]]
elseif token == "~@"
next(rdr)
[[symbol("splice-unquote")]; Any[read_form(rdr)]]
[[Symbol("splice-unquote")]; Any[read_form(rdr)]]
elseif token == "^"
next(rdr)
meta = read_form(rdr)
[[symbol("with-meta")]; Any[read_form(rdr)]; Any[meta]]
[[Symbol("with-meta")]; Any[read_form(rdr)]; Any[meta]]
elseif token == "@"
next(rdr)
[[symbol("deref")]; Any[read_form(rdr)]]
[[Symbol("deref")]; Any[read_form(rdr)]]

elseif token == ")"
error("unexpected ')'")
Expand Down
4 changes: 2 additions & 2 deletions impls/julia/readline_mod.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export do_readline

function do_readline(prompt)
print(prompt)
flush(STDOUT)
line = readline(STDIN)
flush(stdout)
line = readline(stdin)
if line == ""
return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion impls/julia/step1_read_print.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ while true
println("Error: $(string(e))")
end
bt = catch_backtrace()
Base.show_backtrace(STDERR, bt)
Base.show_backtrace(stderr, bt)
println()
end
end
2 changes: 1 addition & 1 deletion impls/julia/step3_env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function EVAL(ast, env)
# apply
if :def! == ast[1]
env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand Down
4 changes: 2 additions & 2 deletions impls/julia/step4_if_fn_do.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function EVAL(ast, env)
# apply
if :def! == ast[1]
env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand All @@ -51,7 +51,7 @@ function EVAL(ast, env)
else
EVAL(ast[3], env)
end
elseif symbol("fn*") == ast[1]
elseif Symbol("fn*") == ast[1]
(args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...]))
else
el = eval_ast(ast, env)
Expand Down
4 changes: 2 additions & 2 deletions impls/julia/step5_tco.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function EVAL(ast, env)
# apply
if :def! == ast[1]
return env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand All @@ -60,7 +60,7 @@ function EVAL(ast, env)
ast = ast[3]
# TCO loop
end
elseif symbol("fn*") == ast[1]
elseif Symbol("fn*") == ast[1]
return MalFunc(
(args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...])),
ast[3], env, ast[2])
Expand Down
6 changes: 3 additions & 3 deletions impls/julia/step6_file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function EVAL(ast, env)
# apply
if :def! == ast[1]
return env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand All @@ -60,7 +60,7 @@ function EVAL(ast, env)
ast = ast[3]
# TCO loop
end
elseif symbol("fn*") == ast[1]
elseif Symbol("fn*") == ast[1]
return MalFunc(
(args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...])),
ast[3], env, ast[2])
Expand Down Expand Up @@ -92,7 +92,7 @@ end
# core.jl: defined using Julia
repl_env = Env(nothing, core.ns)
env_set(repl_env, :eval, (ast) -> EVAL(ast, repl_env))
env_set(repl_env, symbol("*ARGV*"), ARGS[2:end])
env_set(repl_env, Symbol("*ARGV*"), ARGS[2:end])

# core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
Expand Down
8 changes: 4 additions & 4 deletions impls/julia/step7_quote.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function quasiquote(ast)
[[:quote]; Any[ast]]
elseif ast[1] == :unquote
ast[2]
elseif ispair(ast[1]) && ast[1][1] == symbol("splice-unquote")
elseif ispair(ast[1]) && ast[1][1] == Symbol("splice-unquote")
[[:concat]; Any[ast[1][2]]; Any[quasiquote(ast[2:end])]]
else
[[:cons]; Any[quasiquote(ast[1])]; Any[quasiquote(ast[2:end])]]
Expand Down Expand Up @@ -51,7 +51,7 @@ function EVAL(ast, env)
# apply
if :def! == ast[1]
return env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand Down Expand Up @@ -81,7 +81,7 @@ function EVAL(ast, env)
ast = ast[3]
# TCO loop
end
elseif symbol("fn*") == ast[1]
elseif Symbol("fn*") == ast[1]
return MalFunc(
(args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...])),
ast[3], env, ast[2])
Expand Down Expand Up @@ -113,7 +113,7 @@ end
# core.jl: defined using Julia
repl_env = Env(nothing, core.ns)
env_set(repl_env, :eval, (ast) -> EVAL(ast, repl_env))
env_set(repl_env, symbol("*ARGV*"), ARGS[2:end])
env_set(repl_env, Symbol("*ARGV*"), ARGS[2:end])

# core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
Expand Down
8 changes: 4 additions & 4 deletions impls/julia/step8_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function quasiquote(ast)
[[:quote]; Any[ast]]
elseif ast[1] == :unquote
ast[2]
elseif ispair(ast[1]) && ast[1][1] == symbol("splice-unquote")
elseif ispair(ast[1]) && ast[1][1] == Symbol("splice-unquote")
[[:concat]; Any[ast[1][2]]; Any[quasiquote(ast[2:end])]]
else
[[:cons]; Any[quasiquote(ast[1])]; Any[quasiquote(ast[2:end])]]
Expand Down Expand Up @@ -71,7 +71,7 @@ function EVAL(ast, env)

if :def! == ast[1]
return env_set(env, ast[2], EVAL(ast[3], env))
elseif symbol("let*") == ast[1]
elseif Symbol("let*") == ast[1]
let_env = Env(env)
for i = 1:2:length(ast[2])
env_set(let_env, ast[2][i], EVAL(ast[2][i+1], let_env))
Expand Down Expand Up @@ -107,7 +107,7 @@ function EVAL(ast, env)
ast = ast[3]
# TCO loop
end
elseif symbol("fn*") == ast[1]
elseif Symbol("fn*") == ast[1]
return MalFunc(
(args...) -> EVAL(ast[3], Env(env, ast[2], Any[args...])),
ast[3], env, ast[2])
Expand Down Expand Up @@ -139,7 +139,7 @@ end
# core.jl: defined using Julia
repl_env = Env(nothing, core.ns)
env_set(repl_env, :eval, (ast) -> EVAL(ast, repl_env))
env_set(repl_env, symbol("*ARGV*"), ARGS[2:end])
env_set(repl_env, Symbol("*ARGV*"), ARGS[2:end])

# core.mal: defined using the language itself
REP("(def! not (fn* (a) (if a false true)))")
Expand Down
Loading