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

C++

Name: Anonymous 2010-04-17 17:20

For an assignment I need to have a program print the inputted number, and every number before it in sequence ex:

1
12
123
1234
12345
123456

I can get it to print a list of the number but for the love of god I cant get it to print the numbers before hand.  I know theres a simple way to do it nesting a while loop in a for loop but I can't fucking figure it out.

Help for a poor retarded aspiring programmer?

Name: Anonymous 2010-04-17 23:33

>>25
How is that different from a for loop, because it's not, besides DOTIMES is useful, and CL tries to include commonly used functions/macros in the language. While the core itself only has 25 special operators (some of which could be implemented through other special operators, but are kept as is for efficiency reasons), everything else can be built through functions and macros. There's no real reason to be minimalistic.

Here's how one could implement DOTIMES:

(defmacro dotimes ((var count-form &optional result-form) &body body)
  (with-gensyms (count)
    `(do ((,var 0 (1+ ,var))
      (,count ,count-form))
     ((>= ,var ,count) ,result-form)
       ,@body)))


DO itself can be implemented as a macro, in form of LOOP (simple version), and LOOP itself can be implemented in form of TAGBODY and GO which are special operators. Common Lisp's goals are the same as most sane language's, that is, to help the programmer, and when they didn't think of something that you might want, give you enough tools so that you can easily build it yourself.

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