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

Racket

Name: Anonymous 2012-09-25 13:28

there must be a better way to do this right


(define (factorial n)
    (define (iter n result)
        (if (= n 0)
            result
            (iter (- n 1) (* result n))))
    (iter n 1))

Name: Anonymous 2012-09-25 22:37

>>40
I thought so. Come up with a real answer next time instead of just giving some bullshit guess.

Name: Anonymous 2012-09-25 23:38

factorial n = product [1..n]

Name: Anonymous 2012-09-26 3:28

>>2
I like how LISPers love to abuse recursion all the time claiming it makes their code more elegant, but the C version is faster, easier read, and more elegant.

Go fuck yourself LISPers. C is better than your shitty language

Name: Anonymous 2012-09-26 3:38

>>43

many c compilers support tail call optimization. The only thing preventing you from getting just as lispy with c is how some statements are hard to make into expressions. Tail call style is more expressive than loops, and can actually end up compiling to faster code, since the equivalent with loops can be a mess with indicator variables. But nevermind. You'll never understand. Go back to scrubbing your toilet bowlhard to find bug buried within the quadruple nested loop caused by a state variable that was initialized 20 lines down to a value that would have made sense if this condition wasn't triggered during this test case as well.

Name: Anonymous 2012-09-26 3:47

>>44
Except that what you said was the point. LISP fanboys make it seem as though LISP is this ultra powerful language that can use recursion to elegantly provide solutions when in reality, it can be done in C, and often better.

Name: Anonymous 2012-09-26 4:12

>>45

nested functions help, and these are not in the c standard. Tail recursion in c is also not guaranteed to work, so it is not portable. Actual closures that can escape the function body of their declaration are nice too. It is possible to get close to these features in standard C, but you don't have the same convenience or security. If you like these features but don't like scheme (I'm not sure why you have such a dislike of scheme, you seemed to say that it was overrated but the only thing you mentioned was its association with recursion, and by that I can only assume you mean tail recursive style (and by a tail recursive lisp, I can only assume you meant (scheme))), you might want to check out ML.

Name: Anonymous 2012-09-26 4:15

>>45
C
U MENA JAVASCRIPT

Name: Anonymous 2012-09-26 4:15

>>45

and when people talk about lisp being powerful, they are usually referring to its macro system.

Name: Anonymous 2012-09-26 4:51

>>48
Lisp has no macro system. Did you mean CL or Scheme? They are very different to each other.

Name: Anonymous 2012-09-26 5:24

>>49
scheme's macro system is advanced, but it can still all be implemented using lisp's defmacro.

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