15 Jul 2013, 03:42
Dave_gnome_head_isolated_pragsmall

Dave Thomas (338 posts)

  • If you assume the variable a initially contains the value 2, which of the following will match?

    • [ a, b, a ] = [ 1, 2, 3 ]
    • [ a, b, a ] = [ 1, 1, 2 ]
    • a = 1
    • ^a = 2
    • ^a = 1
    • ^a = 2 - a
A Possible Solution
a = 2           #=> a → 2

[ a, b, a ] = [ 1, 2, 3 ]
# ** (MatchError) no match of right hand side value: [1, 2, 3]
#     :erl_eval.expr/3

[ a, b, a ] = [ 1, 1, 2 ]
# ** (MatchError) no match of right hand side value: [1, 1, 2]
#     :erl_eval.expr/3

a = 1           #=> a → 1

^a = 2
# ** (MatchError) no match of right hand side value: 2
#    :erl_eval.expr/3

^a = 1          #=> matches. a still 1

^a = 2 - a      #=> matches. a still 1
27 Aug 2013, 04:28
200-g_pragsmall

Aleksey Gureiev (11 posts)

From the task, it’s not clear that those matches should be performed sequentially. In other words, when I got to ^a = 2 I assumed we still have 2 in a, and so it would be a match.

16 Sep 2013, 02:57
Casual - sqr_pragsmall

Ryan Cromwell, Sr (4 posts)

I too thought each line was independent. As if a multiple choice question.

09 Dec 2013, 05:55
Generic-user-small

John Marcus (1 post)

Another vote for clarifying that each line was a separate question, as I assumed the variable ‘2’ was assigned for each line.

12 Dec 2013, 13:16
Photo-4_pragsmall

antonio lorusso (1 post)

I got it as each line is separate statement too.

05 Jan 2014, 17:17
Generic-user-small

Federico Tomassetti (5 posts)

Me too, I was expecting therefore ^a=2 to match

02 Dec 2014, 05:05
Hoodie_hacker_small_pragsmall

Stephen Aghaulor (1 post)

The question is worded such that it suggests multiple choice. Perhaps it should be rephrased to clarify it’s intent. However, as Dave’s posts suggests, the solution is only a possible solution. Another possible solution is that if not run sequentially, then both a = 1 and ^a = 2 match.

20 Dec 2014, 02:39
Smee2_pragsmall

Gerard de brieder (1 post)

Same here I assuned a to be 2 and then parse each statement as if a was freshly assigned without the history of the previous statement.

  You must be logged in to comment