Thursday, February 25, 2010

A long series of posts

I was arguing recently that it was important for programs to have semantics. Would someone dispute this? Apparently so. Therefore, I started a series of Socratic arguments. I never finished it, but maybe I'll finish it here in my blog.

Let me start with something extremely simple:
(define (factorial x)
 (if (< x 2)
     (* x (factorial (- x 1)))))
and I ask the question to my hypothetical students “What does this mean?”

Student A says “No computer program can ever have a meaning. Someone could redefine *, or shadow if, and make any answer incorrect.”

Student B says “I don't know, but the computer says ”

 (fact 0) => 1
 (fact 1) => 1
 (fact 2) => 2
 (fact 3) => 6
 (fact 4) => 24 ...
Student C says “It defines FACTORIAL as a recursive program that computes the factorial function for positive integer arguments.”

How do you grade these answers, and why?