Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lab5-metaprogramming-and-debugging-lab
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Oscar Järpehult
lab5-metaprogramming-and-debugging-lab
Commits
24236a7e
Commit
24236a7e
authored
5 years ago
by
oscja033
Browse files
Options
Downloads
Patches
Plain Diff
...
parent
bde35858
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
julia/dowhile.jl
+20
-3
20 additions, 3 deletions
julia/dowhile.jl
julia/run.jl
+7
-2
7 additions, 2 deletions
julia/run.jl
with
27 additions
and
5 deletions
julia/dowhile.jl
+
20
−
3
View file @
24236a7e
...
...
@@ -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
This diff is collapsed.
Click to expand it.
julia/run.jl
+
7
−
2
View file @
24236a7e
"""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
==
1
00
end
a
==
1
8
end
testDoWhile
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment