A programming exercise in Common Lisp about Algol-style call-by-name. Write the ...
Vassil Nikolov | Васил Николов @vnikolov@ieji.de
A programming exercise in Common Lisp about Algol-style call-by-name.
Write the necessary definitions, so that the following works:
(define-for-calls-by-name sum (i a b v)
(value a b)
"Jensen's device."
(let ((s 0))
(for (i :from a :to b)
(incf s v))
s))
(defvar *m* (make-array '(2 3)
:initial-contents '((0 1 2)
(3 4 5)))
"A number matrix.")
(let (i j)
(assert (eql 3 (sum i 0 2 (aref *m* 0 i))))
(assert (eql 15 (sum i 0 1 (sum j 0 2 (aref *m* i j))))))
(assert (string= "Jensen's device."
(documentation 'sum 'function)))
As usually with exercises, the value of this is in doing it, rather than in the end result.
The interesting part is figuring out an approach and the necessary ingredients; writing the program is more or less straightforward.
#Algol
#CallByName
#CommonLisp
#ComputerProgramming
#Exercise
#Lisp
#ProgrammingPuzzle