stylewarning / quickutil

The solution to the Utility Library problem.
87 stars 8 forks source link

Proposed utility: with-tail-call-optimization #34

Closed r-moeritz closed 11 years ago

r-moeritz commented 11 years ago
(defmacro with-tail-call-optimization ((&optional treat-warnings-as-errors) &body body)
  #+sbcl
  `(progn
     (declare (optimize (speed 3)))
     ,@body)
  #+ccl
  `(let ((saved-policy (ccl:current-compiler-policy))
         (new-policy (ccl:new-compiler-policy 
                      :allow-tail-recursion-elimination (lambda () t))))
     (unwind-protect
          (progn
            (ccl:set-current-compiler-policy new-policy)
            ,@body)
       (ccl:set-current-compiler-policy saved-policy)))
  #+lispworks
  `(progn
     (declare (optimize (debug 0)))
     ,@body)
  #+allegro
  `(let ((compiler:tail-call-non-self-merge-switch t)
         (compiler:tail-call-self-merge-switch t))
     ,@body)
  #-(or cmu sbcl ccl lispworks allegro)
  (let ((msg "Proper tail-call optimization is not available."))
    (if treat-warnings-as-errors
        (error msg)
        (progn 
          (warn msg)
          `(progn
             ,@body)))))

Provides: with-tail-call-optimization Requires: Author:Ralph Möritz License: MIT

r-moeritz commented 11 years ago

I've decided making with-tail-call-optimization a utility isn't such a good idea since it is, by it's very nature, in a state of flux as it has to be modified to accommodate more CL implementations or amended to cater for changes to old ones. Also, I think it's a good idea to have a test suite, which quickutil doesn't cater for atm.