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 17:50

>>42
Shouldn't the last case be (1 1.5 ...), unless I misunderstood what the intent of the code was, if given:
1 argument - generate a list from 0 to * given increments/steps of 1, so that you get "first argument" elements.
2 arguments - generate a list from "first argument" to "second argument" given increments/steps of 1
3 arguments - generate a list from "first argument" to "second argument" given increments/steps of "third argument".

Here's my attempt to write this in CL:

(defun seq (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))

(defmacro range (&rest args) 
  (if (every #'constantp args) `(list ,@(apply #'seq args)) `(seq ,@args)))

Difference from your examples is that the third example is ran at compile-time as (+ 9 1) will be detected by my implementation as a constant (most implementations will do this, but they are not required by the standard to do it properly: how well a constant form will be detected depends on your implementation's own optimization code - CL merely gives access to this functionality, but only /recommends/ that compilers perform such optimizations).

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