On 12/04/2011, at 7:45 AM, Matthew Swank wrote:
I am current reading an interesting paper on Racket's macro system (referenced here: http://lambda-the-ultimate.org/node/4196 ), and some of the objects they expose quack like CLTL-2 Environments: http://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node102.html. I have read that having write access to environments makes it hard for the compiler to optimize code. However, even portable read only access would be helpful. Does anyone besides me and Cyrus Harmon (http://cyrusharmon.org/blog/display?id=113) miss Environments?
Alas, I wish I had been exposed to them before. Until Cyrus' post I had no knowledge of them. I thank Cyrus for making that post. Using the function CLTL2 VARIABLE-INFORMATION function, I produced the following higher level functionality as a proof of concept for an idea I have for a mathematical optimisation library.
(type-dispatching-defun matrix-add (y x scalar) (assert (= (array-total-size y) (array-total-size x))) (dotimes (index (array-total-size x)) (declare (type fixnum index)) (setf (row-major-aref y index) (+ (* scalar (row-major-aref x index)) (row-major-aref y index)))) y)
(add-type-specific-function 'matrix-add '((simple-array single-float (*)) (simple-array single-float (*)) single-float))
(defun time-generic () (let ((a (make-array 1000 :initial-element 1)) (b (make-array 1000 :initial-element 2))) (time (dotimes (i 100000) (matrix-add a b 2.0)))))
(defun time-single-float-array () (let ((a (make-array 1000 :initial-element 1.0 :element-type 'single-float)) (b (make-array 1000 :initial-element 2.0 :element-type 'single-float))) (declare (type (simple-array single-float (*)) a b)) (time (dotimes (i 100000) (matrix-add a b 2.0)))))
TESTS> (time-generic) Evaluation took: 8.004 seconds of real time 8.000982 seconds of total run time (7.997856 user, 0.003126 system) 99.96% CPU 15,929,157,645 processor cycles 0 bytes consed
TESTS> (time-single-float-array) Evaluation took: 0.430 seconds of real time 0.429092 seconds of total run time (0.428791 user, 0.000301 system) 99.77% CPU 854,425,193 processor cycles 0 bytes consed
Given the possibilities it offers, I am interested to know why it isn't part of the standard.
Thanks for the Racket links, I will have a read.
Mark
Matt
pro mailing list pro@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/pro