1 / 6

Lab1 – Interesting lessons learned

Lab1 – Interesting lessons learned. Modeling Real world modeled onto the language at hand: Shunting station as a record: state(main:_ one:_ two:_) Wagons as atoms: a, b, c etc. Tracks as lists Etcetera…. Lab1 – Interesting lessons learned. Recursion {ApplyRules Ms}

Download Presentation

Lab1 – Interesting lessons learned

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lab1 – Interesting lessons learned • Modeling • Real world modeled onto the language at hand: • Shunting station as a record: state(main:_ one:_ two:_) • Wagons as atoms: a, b, c etc. • Tracks as lists • Etcetera… ali@sics.se

  2. Lab1 – Interesting lessons learned • Recursion • {ApplyRules Ms} • Make sure the recursion terminates. We knew ApplyRules terminated since it was called with a smaller list in each recursive call • Different solutions had different efficiency. {ApplyRule one(N1+N2)|Mr} vs. one(N1+N2) |{ApplyRule Mr} ali@sics.se

  3. Lab1 – Interesting lessons learned • Decompose problems into small functions • {SplitTrain Xs Y} simplified substantially • ApplyMoves was one of the tougher functions: fun {ApplyMoves S Ms} case Ms of nil then … [] M|Mr then S1 = case M of one(N) then if …then …else … end [] two(N) then if … then … else … end end in … end end • Could have been split into ApplyMove and ApplyMoves? Easier to write? ApplyMove could be reused in FindMove? ali@sics.se

  4. Lab2 – Interesting lessons learned • Abstract Data Types • Do not break the abstraction! I.e. do not directly access the underlying data in the tree, i.e. Tree.Frekvens, instead use your ADT {Byte Tree} • MakeTest can test your compression algorithm even though it doesn’t know how you implemented it. • TreeView can show you a visual representation of the tree and its contents regardless of your implementation. ali@sics.se

  5. Lab2 – Interesting lessons learned • Complexity • Carefully consider functions that your recursive functions are calling. • Using Append in HUF slows down recursive functions, particularly since the first argument is a large list. • In Traverse we call Append since we assume that our bit sequence for each symbol is relatively short! • Make your functions tail-recursive so that they use constant stack-space • If the function calls itself on several locations ali@sics.se

  6. Lab2 – Interesting lessons learned • Try to derive state-invariants • Use accumulator variables which are updated during the recursion and when the base case is true the accumulator holds the final result. • E.g. FrequencyMap and Bitmap/Traverse • Higher order programming simplify matters. Recursion can be avoided. • E.g. InitLeaves canuse Map to generate a list of leaves from a list of frequencies. ali@sics.se

More Related