Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Complete newfag here

Name: Anonymous 2011-01-13 4:09

Hai, I'm a newfag to C++ and to this board so excuse my giant amount of fail.
Why won't this figure out the smallest thing in the array?
http://codepad.org/vaHOX8mW

Name: >>35 2011-01-13 18:01

And now I realized that a macro isn't really the recommended way to do this (when you have a function and a macro that are supposed to perform the same job, and the only reason you're also writing a macro is for optimization purposes, then you should use a compiler macro), thus the right definition is this:

(defun range (start-or-count &optional (end (1- start-or-count) end-present-p)
              (by 1) &aux (start (if end-present-p start-or-count 0))) 
  (loop for i from start to end by by collect i))

(define-compiler-macro range (&rest args)
  (if (every #'constantp args) `(list ,@(apply #'seq args)) `(seq ,@args)))

The only disadvantage to the macro version is that if you have a braindead implementation, it can refuse to run compiler macros, however if you have a braindead implementation, it might as well decide to not implement constantp for forms like (+ 1 (- 3 2). Either way, almost all major implementations support both of these just fine, so there's really no reason to worry (if you're running an implementation which doesn't support either of those, you've got other problems to worry about than this).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List