Teaching Scheme: defun
Posted by Peter on March 7, 2006
Hello, and welcome to my blog-thingy.
In this blog I may occasionally wander to other topics, but I will mainly stick to my experiments with scheme and my experiences in teaching it to a new programmer.
To begin teaching a new programmer the first thing I did was to create a standard include file that they could include in their programs that would give them access to functions and macros that would simplify their programming and learning experience. The first function/macro I wrote for this file was
defun, listed straight from common lisp. The motivation behind this was to give the beginning student the ability to create their own functions on the first day of using scheme without any confusion. I rejected the
(define (name params) body) syntax for this purpose because it can create a confusion between the name of the function and its parameters. Likewise I rejected the
(define name (lambda (params) body)) syntax because it adds an extra level of parenthesis to the function declaration, as well as creating confusion about
lambda. Defun however, which for those of you who have never seen it before is used thus:
(defun name (params) body), has neither of these problems. The only downside however is that
lambda is completely new when it is introduced as a way of making functions at runtime.
The defun maco is as follows:
(define-syntax defun (syntax-rules () ((defun a b ...) (define a (lambda b ...)))))
If you have any comments regarding defun, or any suggestions as to how to introduce functions to the new programmer I would be happy to hear them.
p.s. If anyone could give me a tip as to how to write properly indented code in here without jumping though hoops that would be appreciated.