2 ms·
But that problem is present in virtually all homework in CS. Someone already wrote a Celsius to Fahrenheit conversion function, a simple ray-tracer, a quicksor
by kazinator 9y ago
But that problem is present in virtually all homework in CS.
Someone already wrote a Celsius to Fahrenheit conversion function, a simple ray-tracer, a quicksort, a toy Lisp, a text-file-based simple inventory system, etc ...
We could make up a back story about this to give it real-world plausibility: yes, the function is already written, but it's in an expensive, proprietary third-party library which we cannot ship without paying royalty fees and being bogged down with various inconvenient restrictions.
- dingo_bat 9y agoBut you don't call a library bubble sort function inside your own implementation of bubble sort!
- aidenn0 9y agoMy idea for teaching it is to start with just a function that calls the library function: (defun our-member (item list) (cond (t (member item list)))) Now everyone in the class should quickly agree that this function works. Next say "our goal is to write our own implementation of member, so we will handle one special case at a time until we don't need to call member anymore" so step 1: (defun our-member (item list) (cond ((atom list) nil) ;; if it's not a non-empty list, it can't be a list containing item (t (member item (cdr list))))) step 2: (defun our-member (item list) (cond ((atom list) nil) ;; if it's not a non-empty list, it can't be a list containing item ((eql (car list) item) list) ;; if the first element of the list is our item, ;; we have a match and return the whole list (t (member item list)))) step 3: (defun our-member (item list) (cond ((atom list) nil) ;; if it's not a non-empty list, it can't be a list containing item ((eql (car list) item) list) ;; if the first element of the list is our item, ;; we have a match and return the whole list (t (member item (cdr list))))) ;; we already know that the first item is not a match, so we can just run ;; member on the tail of the list And now demonstrate that replacing member with our-member will still be correct. [edit] derp (atom nil) => T