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 (8 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

  You must be logged in to comment