reset password
Author Message
Anon
Posts: 134
Posted 19:52 Nov 13, 2013 |

I am having trouble understanding what the double parenthesis is for a method. example: def encodeWithArchive(tree: CodeTree)(text: List[Char]): List[Bit] = {

what exactly is that doing?

Mike
Posts: 11
Posted 21:52 Nov 13, 2013 |

Last time we saw the double parenthesis, it was to pass one function to another. I'm not entirely sure why this wasn't done with both the tree and text being passed as two parameters in one parenthesis. This particular function generates a Map (key/value data structure) that allows you to look up the bit values using the char as a key.

archive += char -> encoding //where the map magic happens

Once you have this archive, you pass a List[char] (the actual text) to the "encode" function, which returns a List[Bit]. Something else that confuses me is the fact that we don't use the archive while assigning bit values to the List[Bit]. You'd think one could do a encodeAcc(plainText.tail, archive.getOrElse(plainText.head, throw new Error)::acc), since trouble was taken to make the Map.

 

Not sure if that helps. I'm sure we'll be able to trace through it tomorrow.