I'm working through the early examples of the "Stratified Design" paper[1] and I've run (almost immediately!) into something that doesn't seem to work.
They describe an average-damp function that given a function, returns a new function that averages the value with the result of the function:
Code: Select all
(define (average)
(div (apply 'add (args)) (length (args))))
(define (average-damp f)
(fn (x)
(average x (f x))))
And expect to get 4 (the average of 3 and the result of adding 2 to 3). However, instead I get this:
Code: Select all
ERR: invalid function : (f x)
called from user defined function average
I have looked through the "Functions as Data" section of the Code Patterns and those examples didn't seem to help. I tried both "expand" and "letex" and they didn't seem to help.
So, is it possible to implement something like average-damp in NewLisp, and how would you do it?
Thanks!
[1] See http://dspace.mit.edu/bitstream/handle/ ... sequence=2