====================== How to Design Programs ====================== The Book -------- The `How to Design Programs Book`_ (HtDP) is the book that has most changed the way I think about, see and do programming. I have previously gone through the `How to Code: Systematic Program Design Course on EDX`_ (part 1, 2 and 3, free, later updated and renamed to How To Code) which is based on the HtDP book. During the course -- which also meant I perused the book a lot -- I learned in practice what it means to use TDD to guide the design of programs (together with other concepts), and how tests serve as specification and documentation as much as they serve as tests proper. This is the number one book I recommend to my friends (online or otherwise), coworkers, alien species, or other creatures I have the chance to do so šŸ˜…. By the way, the authors of the book sometimes answer questions on the `racket-users`_ google group. I'm slowly (as time permits) studying the book (not the course this time). My previous solutions from the course exercises are in my `htcspd gitlab repository`_. There is also the `HtDP Plus`_ page with additional material that further extends the topics covered in the book. .. _`How to Design Programs Book`: https://htdp.org/ .. _`How to Code: Systematic Program Design Course on EDX`: https://learning.edx.org/course/course-v1:UBCx+SPD1x+2T2016/home .. _`htcspd gitlab repository`: https://gitlab.com/fernandobasso/htcspd .. _racket-users: https://groups.google.com/g/racket-users .. _`HtDP Plus`: https://felleisen.org/matthias/htdp-plus.html Design Recipes and Examples --------------------------- - `CSC120 - How to Design Data Definitions (HtDD) `_. - `The Program Design Recipe `_. - `Design Recipes | SPD1x | edX `_. Racket and BSL -------------- - `A Taste of Racket `__ - `Docs Racket Lang HTDP `__ - `The Little JavaScripter `__ -- Douglas Crockford post. - https://github.com/pkrumins/the-little-schemer - `Racket guide on how to run .rkt files `__. - `Racket docs on Racket scripts `__. - `How to set language to htdp/bsl in REPL `__ - `How to use htpd/bsl from emacs or command line (my gist) `__ - `htdp/sbl support? `__ (issue I openned for Geiser) - `Emacs key bindings in DrRacket? `__ - `The DrScheme repl isnā€™t the one in Emacs `__ -- Some rationale why DrScheme (now DrRacket) is not a REPL like in other Lisps. 1. Add the repos to ``.emacs`` or ``init.el`` as described in https://melpa.org/#/getting-started. 2. Run ``M-x RET package-refresh-contents RET`` (they donā€™t mention it in the tutorial). 3. Run ``M-x RET package-install geiser RET``. Geiser info pages: :: C-h i m Geiser RET Read about installation notes for `Chicken Scheme stuff `__. :: M-x run-geiser Open a ``.rkt`` file in Emacs. Whether you have Geiser repl running or not, hit ``C-c C-a`` and all functions and other definitions inside the ``.rkt`` file will be available for use in the Geiser REPL. In geiser REPL you can do :: (enter! "foo.rkt") (enter! "projs/main.rkt") to load code on those files into the REPL. It seems the files must start with **``#lang racket``** or something like that. Or, if you are editing a ``.rkt`` file and want to ā€œenterā€ it into the REPL: :: C-c C-a http://www.nongnu.org/geiser/geiser_5.html https://docs.racket-lang.org/reference/interactive.html Teaching Languages ā€” htdp/bsl šŸ“– ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :: #lang htdp/bsl `Topic about images in htdp/bsl that shows some useful things. `_ To run tests like those with ``check-expect``, your ``.rkt`` file must start with one of these (beginner/intermediate/advanced student languages. The ā€œ+ā€ a few more features. :: #lang htdp/bsl #lang htdp/bsl+ #lang htdp/isl #lang htdp/isl+ #lang htdp/asl or ``#reader(lib "htdp-beginner-reader.ss" "lang")((modname area-tests) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f () #f)))`` Emacs, Geiser ~~~~~~~~~~~~~ ``C-u C-c C-z`` or ``C-c C-a`` brings one to the REPL in the current module/file. It DISPLAYS IMAGES! šŸ’–ļø ``C-c C-k`` runs fine with the http languages (``C-c C-a`` seems not work for the teaching languages). But not both. Then, from ``racket-mode``, do ``C-c C-t`` (runs ``racket-test`` and be happy. From the command line, :: $ raco test file.rkt Racket Mode ~~~~~~~~~~~ https://racket-mode.com/ Docs for thing at point: ``C-c C-d``. Insert lambda: ``C-m-y``. Other libs used in the book ~~~~~~~~~~~~~~~~~~~~~~~~~~~ - `2htdp/image `__ ā†’ ``bitmap`` - `2htdp/universe `__ ā†’ ``animate`` DrRacket ~~~~~~~~ - `DrRacket Keyboard Shortcuts `__ (Emacs!!! ā­ļø) ``C-x o`` to move from interactions to definition window. **TIP**: To use ``(bitmap "../images/foo.png")`` make sure the file is saved so the relative path works, otherwise, with an unsaved buffer, DrRacket will try to load images relative to your home directory. **WARNING**: If you paste/insert images through Racketā€™s UI, or your you set the language through the UI, you end up with unreadable source code files. Use a header like one of these and see the next tip about ā€œDetermine language from sourceā€. **TIP**: To allow the line ``#lang htdp/``, make sure ā€œdetermine language from sourceā€ is selected in DrRacketā€™s bottom left corner. **TIP**: On wide screens, you may find it useful to display the interactions pane on the right side (instead of at the bottom). Go to ā€œView ā†’ Use Horizontal Layoutā€. There is a setting in Preferences too. Naming Source Files ~~~~~~~~~~~~~~~~~~~ Name each source file incrementally and append a descriptive name: e001e-function.rkt (example from the book, note ā€œe???eā€¦ā€) e002e-images.rkt e070p49-rocket-cond.rkt e071p50-tests-traffic-light.rkt ā€œnā€ is the exercise number, like ā€œe070p49-rocket-cond.rktā€, meaing we are at the file 70 written so far, but the practice exercise is 49. For ā€œWorld Programsā€, use a ā€œwpā€ as well, like in ā€œe075p51-wp-traffic-light.rktā€. Images ------ - `Drawing Animals Using Simple Shapes `__ Other Links ----------- Racket Mode https://racket-mode.com/#Completion The Animated Guide to Paredit http://danmidwood.com/content/2014/11/21/animated-paredit.html Other Peopleā€™s Notes and Solutions ---------------------------------- - `EDX Systematic Program Design Part 1 Summary `__ - `eareese solutions `__ (gh) seems to have every single exercise solved - `adaliu-gh `__ (gh) seems to have the main exercises solved in code - `HtDP2e-solutions `__ - `adaliu-gh/htdp: COMPLETE! My solutions to exercises in htdp-2ed (most of them) `__ - `eareese/htdp-exercises HTDP2e exercise solutions `__ ------------------------------------------------------------------------ .. toctree:: :maxdepth: 6 :caption: Topics Page updated on <2021-09-27 Mon>.