Skip to content

Instantly share code, notes, and snippets.

@lazywithclass
Last active November 20, 2017 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lazywithclass/a945e91db858fed5a4639a6e18d4c3c2 to your computer and use it in GitHub Desktop.
Save lazywithclass/a945e91db858fed5a4639a6e18d4c3c2 to your computer and use it in GitHub Desktop.
[Teaching programming] Lesson four

[Teaching programming] Lesson four - lazyblog

On exercises

They are way too difficult. I've slowed the pace considerably due to a misjudgement of exercises difficulty.

On giving a method

It was her who raised this point and it actually makes a lot of sense, it's a shame I didn't think about this earlier on.

Right now we are solving problems using recursion, so for example for a given problem that reads

;; implement the nth function
;; which given a list and a number returns the item in the list at that position
;; for example
(nth '(1 2 3) 0) ;; 1
(nth '(1 2 3) 1) ;; 2
;; assume that you will be given a lat, provide meaningful return values for edge cases
(define nth
  (lambda (lat position)
    ;; ???  
    ))

a student might want to know how to get to the solution, in such a way that

  • it's easy to understand the first time they hear about it
  • it could be applied to the next problem with minimal changes

This implies that exercises have to stick to a common ground and that the method is damn robust.

I am not sure the method I have her is robust, but, we could always refine it over time and it worked when we wrote it down the first time and later used it with another problem.

The method

Method as we intend it is reasoning plus a way to write down what we just said.

  1. what should I do if I have an empty list? (as told us from the authors via The First Commandment)
  2. what is the user asking? Is there a way to tell them the answer they're looking for?
  3. how do I simplify the input so that I can get closer to what the user wants?

For example

(define (sum-all lat)
  (cond
    ((null? lat) 0)
    (else (+ (car lat) (sum-all (cdr lat))))))

((null? lat) 0) as the first question is where we usually terminate the recursion.

(+ (car lat) (sum-all (cdr lat))) is what the user wanted and a way to get simpler and simpler input to work on.

The expansion of the work the function has to do when using recursion ('(1 2 3) -> (+ 1 (+ 2 (+ 3 0)))), and the following simplification when there are no more function calls to perform is clear in her mind, or so I think as of now.

Thoughts

It's amazing to think that she only knows to iterate using recursion, she doesn't know about for, while and all of that!

I can't wait to see her thoughts evolving around this subject and seeing where this leads her, I was poisoned by loops in the past, so I want to see later on if she's going to come up with reusable functions to loop over data structures and then sharing those as iterators or whatever, the next lessons are going to be really great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment