From 24236a7e0b81baa3102a04ba08b319d741929403 Mon Sep 17 00:00:00 2001
From: oscja033 <oscja033@su15-103.ad.liu.se>
Date: Wed, 9 Oct 2019 13:21:59 +0200
Subject: [PATCH] ...

---
 julia/dowhile.jl | 23 ++++++++++++++++++++---
 julia/run.jl     |  9 +++++++--
 2 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/julia/dowhile.jl b/julia/dowhile.jl
index 96d3fb5..f969d71 100644
--- a/julia/dowhile.jl
+++ b/julia/dowhile.jl
@@ -3,8 +3,25 @@ macro doWhile(block, cond)
   println("cond ", cond)
   println("block ", block)
   res = quote
-    error("TODO: Your code here")
+      while !($cond)
+       $block
+      end
   end
-  println(res) # Should not print any lines referencing dowhile.jl
-  res
+
+res=trav(res, __source__)
+println(res) # Should not print any lines referencing dowhile.jl
+
+function trav(expr, sub)
+count = 1
+  for i in expr.args
+    if isa(i, Expr)
+      trav(i, sub)
+
+    elseif isa(i, LineNumberNode) && i.file != sub.file
+      expr.args[count] = sub
+
+    end
+    count++
+  end
+  return expr
 end
diff --git a/julia/run.jl b/julia/run.jl
index 3728a8f..4d00c6d 100644
--- a/julia/run.jl
+++ b/julia/run.jl
@@ -1,9 +1,10 @@
 """Template programming is a sort of metaprogramming where you fill
 in the blanks, but most parts of the code are very similar."""
 
-for (name,op) in [(:add, :+), (:sub, :-), (:mul, :*)]
+for (name, op) in [(:add, :+), (:sub, :-), (:mul, :*)]
   # Create a function that is named for example add and returns the
   # sum of its two arguments
+  @eval $(name)(x,y) = $(Symbol(op))(x,y)
 end
 
 @assert 3 == add(1, 2)
@@ -19,6 +20,9 @@ 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
+
+Base.delete_method(which(Problem1.f,(Int,)))
+
 @assert 2 == Problem1.f(1)
 
 # TODO: Make an until block for Julia, similar to do {} while (cond); in C
@@ -26,6 +30,7 @@ end
 # Make sure that any assertions and error-messages refer to lines in the original code.
 # Hint: You can access a hidden input __source__ in a macro and use that to replace source information.
 # By having the macro in a separate file, you can check source locations that match dowhile.jl and replace them with __source__.
+
 include("dowhile.jl")
 function testDoWhile()
   local a = 5
@@ -33,6 +38,6 @@ function testDoWhile()
     @assert a < 18
     a += 1
     println(a)
-  end a==100
+  end a==18
 end
 testDoWhile()
-- 
GitLab