From 435c09382fcc72a40416c1eb1ce50ecba67b983d Mon Sep 17 00:00:00 2001
From: simsc266 <simsc266@southfork1-112.ad.liu.se>
Date: Tue, 8 Oct 2019 15:00:29 +0200
Subject: [PATCH] commiting 1 and 2

---
 debugging/dividearrays.cpp |  9 ++++++++-
 julia/dowhile.jl           | 17 ++++++++++++++---
 julia/run.jl               | 16 ++++++++++++++++
 profiling/test.jl          |  9 ++++++++-
 4 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/debugging/dividearrays.cpp b/debugging/dividearrays.cpp
index a674586..1e13326 100644
--- a/debugging/dividearrays.cpp
+++ b/debugging/dividearrays.cpp
@@ -9,7 +9,14 @@ int main(int argc, char **argv)
   for (int i=0; i<1024; i++) {
     int nom = intdist(generator);
     int denom = intdist(generator);
-    res[i] = nom / denom;
+   
+      res[i] = nom / denom;
   }
   return 0;
 }
+/*Program received signal SIGFPE, Arithmetic exception.
+0x0000555555554bb9 in main (argc=1, argv=0x7fffffffd688) at dividearrays.cpp:13
+13	      res[i] = nom / denom;
+
+cant divide if denom = 0. Solve by checking if denom == 0.*/
+
diff --git a/julia/dowhile.jl b/julia/dowhile.jl
index 96d3fb5..084bb24 100644
--- a/julia/dowhile.jl
+++ b/julia/dowhile.jl
@@ -1,10 +1,21 @@
 macro doWhile(block, cond)
+
   println("__source__ ", __source__)
   println("cond ", cond)
   println("block ", block)
   res = quote
-    error("TODO: Your code here")
+      while true
+       $(esc(block))
+        if $(esc(cond))
+       	   break
+        end
+      end
   end
-  println(res) # Should not print any lines referencing dowhile.jl
-  res
+
+   
+  
+  # println(res) # Should not print any lines referencing dowhile.jl
+  res.args[1].striplines
+
+
 end
diff --git a/julia/run.jl b/julia/run.jl
index 3728a8f..bf6be00 100644
--- a/julia/run.jl
+++ b/julia/run.jl
@@ -1,11 +1,18 @@
 """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, :*)]
   # Create a function that is named for example add and returns the
   # sum of its two arguments
+  @eval $name(x,y) = $op(x,y)
+  
 end
 
+
+
+
 @assert 3 == add(1, 2)
 @assert -1.0 == sub(1.0, 2.0)
 @assert "abc" == mul("ab", "c")
@@ -18,7 +25,13 @@ module Problem1
   f(a::Int) = 1
   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 +39,9 @@ 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
diff --git a/profiling/test.jl b/profiling/test.jl
index cdb378a..9ac19b1 100644
--- a/profiling/test.jl
+++ b/profiling/test.jl
@@ -1,16 +1,23 @@
+using Profile
 using BenchmarkTools
 using Random
 
 function f()
+	 
   lst = rand(50000)
+  
   for i in lst
-    s = "List entry $(i)\r" # The \r makes it so the terminal isn't filled
+   s = "List entry $(i)\r" # The \r makes it so the terminal isn't filled
     if i > 0.99
+    
       print(s)
     end
   end
 end
 
+@profile f()
+Profile.print()
+
 f()
 @time f()
 x = @benchmark f()
-- 
GitLab