small medium large xlarge

Dave_gnome_head_isolated_pragsmall
15 Jul 2013, 03:42
Dave Thomas (344 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</summary>

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

</details>

200-g_pragsmall
27 Aug 2013, 04:28
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.

Casual - sqr_pragsmall
16 Sep 2013, 02:57
Ryan Cromwell, Sr (4 posts)

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

Generic-user-small
09 Dec 2013, 05:55
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.

Photo-4_pragsmall
12 Dec 2013, 13:16
antonio lorusso (1 post)

I got it as each line is separate statement too.

Generic-user-small
05 Jan 2014, 17:17
Federico Tomassetti (5 posts)

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

Hoodie_hacker_small_pragsmall
02 Dec 2014, 05:05
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.

Smee2_pragsmall
20 Dec 2014, 02:39
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