hello!
I am new to lisp and I am trying to figure out DO loops. I simply do not understand how to create them, and I must create a Do function which finds the minimum in a list and also use an if function but i am stuck. Can anyone help?
(defun minimum (lst)
"(lst)
return the minimum of a list"
(do (x lst (cdr x))
(result 0 (car x))(defun minimum (lst)
"(lst)
return the minimum of a list"
(do (x lst (cdr x))
(setf 'a (car x))
(setf 'b (car (cdr x))
gayelle wrote:Here is how far along I got in the code. I know that I have to take the first number but I don't know how to compare it to each other value in the list individually...
- Code: Select all
(defun minimum (lst)
"(lst)
return the minimum of a list"
(do (x lst (cdr x))
(result 0 (car x))
(do bindings
stuff-that-determines-when-the-loop-exits-and-what-it-returns
forms-that-get-run-every-iteration )(do ((x lst (cdr x)) (result 0 (car x))) ...)gayelle wrote:
- Code: Select all
(defun minimum (lst)
"(lst)
return the minimum of a list"
(do (x lst (cdr x))
(setf 'a (car x))
(setf 'b (car (cdr x))
smithzv wrote:Okay, it's a start. Let's step back. Describe in plain English what Lisp should do just so we're on the same page.
Users browsing this forum: No registered users and 2 guests