Skip to content
Snippets Groups Projects
Verified Commit c15bd2e0 authored by Martin Sjölund's avatar Martin Sjölund
Browse files

Added a Julia lab

parents
Branches
Tags
No related merge requests found
*.tar.gz
julia-1.0.4
.PHONY: run
run: julia-1.0.4/bin/julia
$< run.jl
julia-1.0.4/bin/julia: julia-1.0.4-linux-x86_64.tar.gz
tar xzf $<
touch $@
julia-1.0.4-linux-x86_64.tar.gz:
wget https://julialang-s3.julialang.org/bin/linux/x64/1.0/julia-1.0.4-linux-x86_64.tar.gz
macro doWhile(block, cond)
println("__source__ ", __source__)
println("cond ", cond)
println("block ", block)
res = quote
error("TODO: Your code here")
end
println(res) # Should not print any lines referencing dowhile.jl
res
end
"""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
end
@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
try to delete a function instead."""
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
@assert 2 == 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.
# 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
@doWhile begin
@assert a < 18
a += 1
println(a)
end a==100
end
testDoWhile()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment