Doing a loop in any way other than a recursive cond statement

>doing a loop in any way other than a recursive cond statement
kys

Attached: 20131205232549_original.png (1189x763, 88K)

>statement
*procedure

can you explain to me what a recursive cond statement is?

It doesn't matter anyways, it all gets translated into gotos in machine code.

Well, sometimes recursive if is enough.

good luck doing that on a z80

the compiler turns it into garbage anyway, just write whatever

(loop until (sensible-to-exit)
do (your-shit-here mate))

define a function with a condition to exit, and that calls itself once

Not him, but let me explain with a recursive if:
(define (factorial n)
(define (iter accum k)
(if (= k 0)
accum
(iter (* accum k) (- k 1))))
(loop 1 n))
This is basic tail recursion in Scheme. The local iter function acts as a looping construct, carrying the preliminary result and something like a loop index, counting down from n to 1.

Now, a cond statement is like a mixture of a switch statement and chained if-else. It has the readability of the former while having the flexibility of the latter. This becomes useful for more intricate loops where there are more variables and more conditions depending on those. Hope that helps.

Damn, I used iter as the local function named and then called it as loop. The last line should of course be (iter 1 n))

Imagine having four pathetic, useless penis-shaped limbs only to have a functioning limb coming out of your face.
What the fuck is this mascot?

lol retard

>It has the readability of the former
not in lisp

why the fuck are there so many parenthesis' in functional languages?
Is it like the semi-colon fetish of the C family?

Imagine being this afraid of a few parentheses.

Loop:
Label A
Do thing
Check condition
Go-to A or break

Recursion:
Label A
Do thing
Check condition
Go-to A or break

Am I stupid or are the loops and recursive functions the same thing. What don't I understand here.

>brainlet
It's incredibly simple to write a `(loop` macro using recursion.

functional and imperative is just two ways of conceptualising the exact same thing, look up turing machine machines compared to lambda notation or whatever it's called. sometimes one conceptualisation is more suited to one probem than another one

Common Lisp generally uses the LOOP macro though.

It's Scheme that recommends recursion.

So you used the wrong picture faggot.

>afraid
((((google))))

CL loop is implemented with macro, unsurprisingly

Is Lisp efficient? Its really old so it should be low level like Forth?

It's pretty high level, so it depends on the implementation. It can get acceptably fast though.

Plus you can inline asm IIRC, and it has a very good C FFI.

There are situations where recursion is actually cleaner than loops. Consider something like
// ... state variables
while (!done) {
if (something) {
// change state
continue;
} else if (something_else) {
// change state
continue;
} // ... more clauses
}
(I'm aware I could omit the continue; statements)
Something like this could be simpler with recursion:
int loop_fun(/* state variables */) {
if (something) {
loop_fun(/* changed state variables */);
if (something_else) {
loop_fun(/* changed state variables */);
// ... more clauses
}

On the other hand, if you're trained in functional programming (Scheme in particular), a loop is rarely cleaner than recursion (done right).

Damn, it's too late over here and I should go to bed. Lots of errors of in the code here. Sorry about that.

the lisp alien is for all lisp families. In the land of lisp comic scheme and others are also a part of the lisp king's army

>Am I stupid or are the loops and recursive functions the same thing

They are the same, but in some case recursion is more understandable.
As a simple example, see the difference between iterative and recursive implementation of any kind of tree traversal algorithm

Really? That's awesome.

Because lisp code is represented as data structures, specifically a linked list.
Once you're used to it it's way clearer than any other language.
If you want slightly less parens try Clojure.