-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
assinment 3 #34
base: master
Are you sure you want to change the base?
assinment 3 #34
Conversation
def counter(value \\ 0) do | ||
|
||
receive do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2 layout
please indent the block of code under the {:next, from}
line.
end | ||
|
||
|
||
def new_counter(value) do | ||
pid = spawn(Ex01, :counter, [value]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2
This generates a warning
-1 layout
end | ||
|
||
|
||
def next_value(from) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2 layout
Layout is really an important part of programming, because it aids understanding.
# end | ||
|
||
|
||
test "counter using an agent" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-5
This code contains a race condition, because it does a get followed by an update. Imagine two processes getting the next value at the same time. Both do a get, and both receive the same value.
{:ok,count} = Agent.start_link(fn -> value end) | ||
end | ||
|
||
def new_counter(value) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-2 idiomatic
I'm not sure why you add an extra start_link
function.
Also, your new_counter
function returns {:ok, pid}
, but the :ok
is
not useful anywhere. It should rally just return the pid:
def new_counter(value) do
{:ok,count} = Agent.start_link(fn -> value end)
count
end
def pmap(collection, process_count, function) do | ||
« your code here » | ||
end | ||
count_value = Enum.count(collection)/process_count |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-4 idiomatic
You should use pipelines, rather than temporary variables here.
Hi Professor,
Please find the attached assignment
thank you
Shashi Tekula