{"id":521,"date":"2013-08-02T16:01:00","date_gmt":"2013-08-02T16:01:00","guid":{"rendered":"https:\/\/staging.infragistics.com\/blogs\/?p=521"},"modified":"2025-02-25T13:19:30","modified_gmt":"2025-02-25T13:19:30","slug":"systematic-programming-week-6","status":"publish","type":"post","link":"https:\/\/www.infragistics.com\/blogs\/systematic-programming-week-6","title":{"rendered":"Introduction to Systematic Programming \u2013 Week 6"},"content":{"rendered":"\n<p>It seems to happen in all of my classes around now \u2013 I\u2019ve been plugging along dutifully, but without the \u201cpressure\u201d of assigned class times, a professor checking in on my work, classmates who I converse with, I always seem to struggle about a month and a half into my online courses. Never fear, though, I made it through week 6 and I\u2019m bringing to you, as always a thorough summary! Week 6 in Introduction to Systematic Program Design addresses the idea of Mutual Reference\u2026 Here we go!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-1-more-helpers-mutual-helpers\">Lesson 1: More Helpers &amp; Mutual Helpers<\/h2>\n\n\n\n<p>At the start of this lesson, we\u2019re reminded that the purpose of the HtDF recipe is to break your large, seemingly insurmountable problems down into smaller more manageable ones. This reminder makes more sense a moment later, because this week will explain how to not only break down problems, but datatypes and functions as well! The course instructor explains that although previously in the course we have always kept datatypes and functions whole, in week 6 we\u2019re going to learn how to break them up, similar to how we\u2019ve broken up all of our problems. We\u2019re also informed that we\u2019ll be learning a new kind of arbitrary sized data that is complete with its own integrated helpers.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-2-more-helpers-function-composition\">Lesson 2: More Helpers \u2013 Function Composition<\/h2>\n\n\n\n<p>This lesson begins a large practice problem that spans several lessons \u2013 for that reason, my notes are a bit sparse here, because detailing every step of the practice problem just seems a touch redundant and uninteresting. \ud83d\ude09<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/community\/cfs-filesystemfile.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/d-coding\/2548.video2_5F00_image2.png\" alt=\"More Helpers \u2013 Function Composition\" title=\"More Helpers \u2013 Function Composition\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In respect to the concept from Lesson 1 regarding breaking a function into multiple parts, this is a perfect example. When you consider a problem as broken down into smaller, internal problems, this is what\u2019s known in HtDF as a Function Composition Problem (aka when there are two distinct operations on the data that is to be consumed). Apparently, this is incredibly easy to achieve, because, you guessed it, there\u2019s a template for that! Racket has a Function Composition Template, which lesson 2 then walks us through the use of. Here\u2019s a quick example: (define (arrange-images loi) (layout-images (sort-images loi)))<\/p>\n\n\n\n<p>As you can see in the above, there are two functions built into one definition. After writing the definition, as always, we\u2019re instructed to write our wish-list entries so nothing is forgotten. J<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-3-laying-out-a-list-of-images\">Lesson 3: Laying Out a List of Images<\/h2>\n\n\n\n<p>This lesson continues the example from the previous lesson. The most important thing that\u2019s reviewed in this lesson is to make sure that your MATCHING check-expects pass after you write your function. Note: If the check-expects from an incomplete function fail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-4-more-helpers-operating-on-a-list\">Lesson 4: More Helpers \u2013 Operating on a List<\/h2>\n\n\n\n<p>Again, one nice and short tidbit from this lesson!<\/p>\n\n\n\n<p>In the case of coding a function, when you need to operate on a list, you need to create a new helper function.<\/p>\n\n\n\n<p>Yep, that\u2019s it for lesson 4!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-5-more-helpers-domain-knowledge-shift\">Lesson 5: More Helpers \u2013 Domain Knowledge Shift<\/h2>\n\n\n\n<p>This lesson has a very interesting focus \u2013 shifting knowledge areas in the midst of programming in Racket requires that you create helper functions. I know, what?! Let\u2019s try this: \u201cWhen changing from sorting images to comparing the size of an image, this is a domain knowledge shift.\u201d So, in essence, when you\u2019re doing something DIFFERENT with the items in your list, you make a new function. Granted, this is one of my least favorite things about this course, because I feel that it results in lots and lots of extra code, that could be more\u2026 compact?, I do understand that it breaks out the logic of programming and makes it easier for beginners. (Did I just say that? Does that mean I\u2019m not a beginner anymore? Gosh I hope not! Haha.)<\/p>\n\n\n\n<p>Additional Notes:<\/p>\n\n\n\n<p>If you use an item repeatedly for testing, just make it a constant! It\u2019s easier and helps avoid mistakes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-6-more-helpers-wrap-up\">Lesson 6: More Helpers \u2013 Wrap Up<\/h2>\n\n\n\n<p>In theory, this is where the magic of helpers happens. Once you write your last helper function and run your code, all of your tests should magically pass, because your original function was just waiting for the helpers to be written!<\/p>\n\n\n\n<p>No?<\/p>\n\n\n\n<p>Well, then you should check your tests for mistakes first, because you might simply have a typo. If that\u2019s not the issue, well, then, you have to debug your functions.<\/p>\n\n\n\n<p>Also! Since this is the end of the \u201cfirst half\u201d of Week 6, there were some small wrap-up notes:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Remember all of these new helper rules that we learned this week! We\u2019ll need them for later.<\/li>\n\n\n\n<li>Don\u2019t be afraid to utilize Macro Notion \u2013 Split work from main functions using helper rules and make your life easier!!<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-7-list-abbreviations\">Lesson 7: List Abbreviations<\/h2>\n\n\n\n<p>I. Loved. This. Lesson.<\/p>\n\n\n\n<p>Seriously, list writing in Racket so far has been an abomination! In this lesson, we\u2019re instructed to move our language definition in Dr. Racket from \u201cBasic Student Language\u201d to \u201cBasic Student Language with List Abbreviations.\u201d Thank. Goodness.<\/p>\n\n\n\n<p>What this means as far as programming is that when you write a list, you don\u2019t need cons anymore!! Lists will now make sense!!! When writing a list, it can now be composed as such: (list \u201ca\u201d \u201cb\u201d \u201cc\u201d). SCORE!<\/p>\n\n\n\n<p>However, it\u2019s important to note that you still *can* use cons, and in some cases, it will make more sense. If you\u2019re adding to a list, for example, you would still want to say:<\/p>\n\n\n\n<p>(define L1 (list \u201cb\u201d \u201cc\u201d))<br>(cons \u201ca\u201d L1)<\/p>\n\n\n\n<p>In order to produce: (list \u201ca\u201d \u201cb\u201d \u201cc\u201d).<\/p>\n\n\n\n<p>The reason for this is if you try and use append, you need to input two LISTS, which will then produce one list with the elements of both of them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-8-mutually-recursive-data\">Lesson 8: Mutually Recursive Data<\/h2>\n\n\n\n<p>Mutually recursive data is defined in Racket as data with two cycles in the type comment. This type is known as an arbitrary arity tree, as all of the elements are able to also contain sub-elements. This arbitrary quality means that the elements can be both arbitrary in both elements extending through width and height. Here\u2019s an example of what I\u2019m talking about:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"\/community\/cfs-filesystemfile.ashx\/__key\/CommunityServer.Blogs.Components.WeblogFiles\/d-coding\/1452.video8_5F00_arbitraryaritytree.png\" alt=\"Mutually Recursive Data\" title=\"Mutually Recursive Data\"\/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>In Racket, when building an arbitrary arity tree, you use\u2026. Lists! (Shocking, right?)<\/p>\n\n\n\n<p>For example, going from description of element to ListOfElement (cycle) is a mutual reference, which can be understood as an \u201carbitrary\u201d cycle. So, when you go through a reference cycle, and the arrows return to the place where the reference cycle began, this is known as a \u201cmutual reference,\u201d because they point back to one another!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-9-templating-mutual-recursion\">Lesson 9: Templating Mutual Recursion<\/h2>\n\n\n\n<p>One major tip here and that\u2019s it!<\/p>\n\n\n\n<p>Write your templates for mutually recursive datatypes together when writing your program. Why? It\u2019s easier! Plain and simple. J<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-10-functions-on-mutually-recursive-data-part-1\">Lesson 10: Functions on Mutually Recursive Data \u2013 Part 1<\/h2>\n\n\n\n<p>When there are 2+ functions that operate on mutually recusirve data, you shouldn\u2019t only write them together, but write them all right away, with the same examples, signature, and purpose!<\/p>\n\n\n\n<p>Here\u2019s an example:<\/p>\n\n\n\n<p>(define (sum-data\u2014element e) 0)<br>(define (sum-data\u2014loe loe) 0)<\/p>\n\n\n\n<p>When you\u2019re doing this\u2026 don\u2019t forget your base case examples and also remember to rename all of your mutually recursive and self-referencing calls right away. Both of these items will save you a *ton* of headache and heartache later. Promise.<\/p>\n\n\n\n<p>Again\u2026 as always\u2026 REMEMBER TO TRUST THE NATURAL RECURSION.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-11-functions-on-mutually-recursive-data-part-2\">Lesson 11: Functions on Mutually Recursive Data \u2013 Part 2<\/h2>\n\n\n\n<p>Two big takeaways here:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Your base case is where you reference cycles stop. (I thought this was very poignant, I didn\u2019t ever think about it this way before, but it\u2019s so true!)<\/li>\n\n\n\n<li>Beware of naming conventions with two functions. Be clear and STAY ORGANIZED.<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"lesson-12-backtracking-search\">Lesson 12: Backtracking Search<\/h2>\n\n\n\n<p>Here\u2019s one last function for the week using arbitrary arity trees\u2026. Backtracking search!<\/p>\n\n\n\n<p>What is that? It\u2019s when you search a tree for an element with a given value\/name. It\u2019s important to remember here that the leaves of the tree are searched AFTER the ones above, so they\u2019re &nbsp;found \u201cin\u201d their parents. Backtracking search comes into play here because if you get to the end of a branch in your tree and don\u2019t find the element you\u2019re looking for (known as a \u201cfailing leaf\u201d), you have to traverse BACK UP in the tree in order to go down a different branch, you can\u2019t just jump around. This repeats through navigation of the entire tree, until you run out of branches and leaves!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"week-6-summary\">Week 6 Summary<\/h2>\n\n\n\n<p>This week was ALL over the place, and as I mentioned, a hard one for me to simply get through. However, I think that overall the concepts are definitely manageable, and I\u2019m looking forward to the last two weeks of class. Wish me luck!!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"questions-comments\">Questions\/Comments?<\/h2>\n\n\n\n<p>Feel free to comment here on my blog, or find me on Twitter <a href=\"https:\/\/twitter.com\/DokiDara\" rel=\"noopener\">@DokiDara<\/a>.<\/p>\n\n\n\n<p><a href=\"https:\/\/plus.google.com\/102021025995449539449?rel=author\" rel=\"noopener\">By Dara Monasch<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Week 6 is definitely when I\u2019m starting to feel the burnout of MOOC. <\/p>\n","protected":false},"author":21,"featured_media":2366,"comment_status":"publish","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-521","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to"],"_links":{"self":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/521","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/comments?post=521"}],"version-history":[{"count":2,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/521\/revisions"}],"predecessor-version":[{"id":2123,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/posts\/521\/revisions\/2123"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media\/2366"}],"wp:attachment":[{"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/media?parent=521"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/categories?post=521"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.infragistics.com\/blogs\/wp-json\/wp\/v2\/tags?post=521"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}