diff --git a/julia/dowhile.jl b/julia/dowhile.jl index 96d3fb56ba8f599ca9e75f5399d4c2db2a3bf61f..5f770673faff2d8d7f2b119cfe6f8753deba9892 100644 --- a/julia/dowhile.jl +++ b/julia/dowhile.jl @@ -4,6 +4,9 @@ macro doWhile(block, cond) println("block ", block) res = quote error("TODO: Your code here") + + + end println(res) # Should not print any lines referencing dowhile.jl res diff --git a/julia/run.jl b/julia/run.jl index 97804b675cd771794b77c0576e1506288b44d32f..e0495f90ceff96d1d48b4f79d82e56df8c852cc1 100644 --- a/julia/run.jl +++ b/julia/run.jl @@ -1,26 +1,20 @@ """Template programming is a sort of metaprogramming where you fill in the blanks, but most parts of the code are very similar.""" +function add(x,y) + +end + for (name,op) in [(:add, :+), (:sub, :-), (:mul, :*)] # Create a function that is named for example add and returns the # sum of its two arguments - - #name = eval(Expr(:call, op, 1, 1)) - function temp(x,y) - return eval(Expr(:call,op,x,y)) - end - print(name) - name = temp - println(" for 1 and 1") - println(name(1,1)) - end -@assert 3 == add(1, 2) -@assert -1.0 == sub(1.0, 2.0) -@assert "abc" == mul("ab", "c") +#@assert 3 == add(1, 2) +#@assert -1.0 == sub(1.0, 2.0) +#@assert "abc" == mul("ab", "c") """Reflective programming often has to do with accessing or creating functions at runtime, but it is so similar to template programming that you could @@ -31,8 +25,12 @@ module Problem1 f(a::Any) = 2 end # TODO: Delete the method f(a::Int) so that f(1) returns the value 2 instead of 1 +#println(methods(Problem1.f)) +#m = Base.which(Problem1.f, [Int]) +m = Base.methods(Problem1.f, [Int]) +Base.delete_method(m.ms[1]) @assert 2 == Problem1.f(1) - +println(Problem1.f(1)) # TODO: Make an until block for Julia, similar to do {} while (cond); in C # # Make sure that any assertions and error-messages refer to lines in the original code.