Sarah44 wrote:I have been trying to write a function that will allow me to return the smallest number of a list. It is an exercice to practice "do" iteration.

Use DOLIST to iterate over a simple list.

Could somedy hint me on how to get started with that function?

Basically, you start with the first element of the list, compare it with the next element, compare the smaller of the two values with the third element, and so on. Store the first element in a local variable and iterate down the CDR of the list, always storing the lowest value so far in that variable. If the list is empty, return NIL.

Danb, I think I am starting to understand. However, the only thing is that the textbook says that we can solve the problem using only do. Is it really different from dolist? If yes, could you explain in what it is different?

Sarah44 wrote:However, the only thing is that the textbook says that we can solve the problem using only do. Is it really different from dolist? If yes, could you explain in what it is different?

DO is like C(++ or 99 specifically, I think)'s for loop, except you can have multiple variables being stepped at once, and it returns a value (either nil or a value you specify), like every Lisp form. The basic idea is that you specify some variables, each optionally having an initial value and a form that produces the next value, then you specify a termination condition, then you write the loop body.

EDIT: It's also sort of a recursion emulation. Note the similarity between the arguments to the recursive LIST-LENGTH call and the next value forms in the DO loop.