small medium large xlarge

Bryce_pragsmall
28 May 2013, 06:33
Bryce Darling (6 posts)

I am struggling with two of the problems from Exercise 5.4 using the &1,… notation.

Rewriting the list_concat function was easy. However, I am stuck on rewriting the sum and pair_tuple_to_list functions.

sum = &1 + &2 + &3

# ** (SyntaxError) iex:10: partial variable &3 cannot be defined without &1

I asked for help on IRC and got a better understanding of what is happening, which is similar (or the exact same?) as the parsing problem described right before these exercises were given on page 47 of the pdf.

Yet the solution to this exercise using the &1,… notation still eludes me.

And as for rewriting the pair_tuple_to_list function to use the &1,… notation I will admit that I am clueless. Here is my attempt:

pair_tuple_to_list = [elem(&1, 0), elem(&1, 1)]
# [#Function<erl_eval.6.17052888>,#Function<erl_eval.6.17052888>]
[ 8, 7 ] = pair_tuple_to_list.( { 8, 7 } )     
# ** (BadFunctionError) expected a function, got:
# [#Function<erl_eval.6.17052888>,#Function<erl_eval.6.17052888>]

I see that it is matching a list of two functions to pair_tuple_to_list rather than just a function that returns a list but I am not sure how to get it to do what I need.

Any help and direction would be much appreciated! :-)

Cheers, Bryce Darling

Bryce_pragsmall
28 May 2013, 16:05
Bryce Darling (6 posts)

These exercises appear to have been replaced in the most recent update. The new exercises are much easier.

It also seems as though using &1 + &2 + &3 is impossible. Primitive operators can only use two arguments like &1 + &2. Please correct me if I am wrong.

Thanks! Loving the book, can’t wait to tear through more of it.

Dave_gnome_head_isolated_pragsmall
29 May 2013, 05:18
Dave Thomas (366 posts)

Sorry about that—I messed up with a copy/paste in the first beta. The second is correct.