Skip to content
Snippets Groups Projects
Commit 1be6d216 authored by Daniel Olsson's avatar Daniel Olsson
Browse files

Commit for first assignment

parent 5cd8e705
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
"""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.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment