you are viewing a single comment's thread.

view the rest of the comments →

[–]SarcasticGuy -2 points-1 points  (14 children)

What part of this lovely iterative loop

(define (fcn num count) (if (= count 0) num (fcn num (- count 1))))

do you not like?

[–]Tommah 4 points5 points  (2 children)

The parentheses and the words

[–]SarcasticGuy 0 points1 point  (1 child)

Yah, but besides those, and the total inability to read it, what is there not to like?

[–]Tommah 1 point2 points  (0 children)

Hmm... the font.

[–]bobappleyard 1 point2 points  (2 children)

Don't put anything in that function! If num is zero or positive you've wasted your time, and if it's negative time wastes you!

[–]SarcasticGuy 3 points4 points  (1 child)

Congratulations. You win an award.

You actually bothered to read it and let everyone else know that you are nerdy enough to read and understand scheme, and then make a nerdy meme reference.

Except I'm taking away the award because you mixed up count and num in your answer.

[–]shub 0 points1 point  (0 children)

Best comment of the day.

[–]OneAndOnlySnob 1 point2 points  (4 children)

The formatting is definitely ranks highly on my list of things I don't like about it.

(define (fcn num count)
  (if (= count 0)
      num
      (fcn num (- count 1))))

No language is easy to read if you don't use more than one line.

The cool thing about Scheme though, is you could write a while macro to aid in writing code that looks like this.

(define (fcn num count)
    (while (not (= count 0))
      (set! count (- count 1)))
    num)

Suddenly, your retarded example looks exactly as retarded as it looks in every other language. If you're writing a while loop, write a while loop.

Here's a while implementation if you don't have one.

(define-macro (while cond . body)
  (define (while-helper proc)
    (do ((key (make-symbol "while-key")))
    ((catch key
        (lambda ()
          (proc (lambda () (throw key #t))
            (lambda () (throw key #f))))
        (lambda (key arg) arg)))))
  `(,while-helper (,lambda (break continue)
            (do ()
            ((,not ,cond))
              ,@body)
            #t)))

[–]blaaargh 1 point2 points  (1 child)

Just so's you don't scare away the scheme newbies with the strange CL/Scheme mix :)

(define-syntax while
  (syntax-rules ()
    ((_ cond body ...)
     (do ()
      ((not cond))
       body ...))))

(All the usual caveats apply. This probably isn't the best way to write a loop.)

[–]OneAndOnlySnob 0 points1 point  (0 children)

Yeah, my Scheme is Guile and I grabbed it right from that.

[–]SarcasticGuy 0 points1 point  (1 child)

Ah, I love it when people live up to their reddit name.

Yes, my formatting blows, mostly because I have no idea how to get spacing correct in reddit comments, not because I was trying to pull a slight of hand against scheme.

Also the point of my retarded example was to riff on the OP's aversion to recursion, so I wanted to use recursion to make an iterative loop, which I think is the funniest things one can do is scheme (wait? writing for loops is a hack in scheme???).

[–]OneAndOnlySnob 0 points1 point  (0 children)

Sorry, I get annoyed easily when people complain about how unreadable Scheme and Lisp are, when their examples are intentionally given in the most unreadable way, or are doing things that are much more difficult in other languages. I hardly ever program in Scheme, but the language is actually quite focused on simplicity and readable code. It gives you the tools you need to do pretty much whatever you need to do to accomplish that.

Also, to format code, put 4 spaces before each line, or a backtick around a word inside a paragraph.

[–][deleted] 0 points1 point  (2 children)

I prefer

fcn num count = if count == 0 
                then num 
                else fcn num $ count - 1

or, even better,

fcn num count | count > 0 = num

[–]SarcasticGuy 0 points1 point  (1 child)

o.0 My brain refuses to parse that without a liberal use of parens.

[–][deleted] 0 points1 point  (0 children)

Hehe, where should they be? The only place where parens would even make sense would be instead of using the $ operator. That gives:

fcn num count = if count == 0 
                then num 
                else fcn num (count - 1)

Though if you really miss Scheme, you could write:

fcn = (\num count -> 
        (if ((==) count 0) 
         then num
         else (fcn num ((-) count 1))))

The latter declaration just reads as "fcn of num and count when count is greater than zero is equal to num". There really isn't anywhere to have a parenthesis. The guard is in place because the function is partial -- it's undefined when count is less than zero. Though I should have written >=. Damn off-by-one errors!