Advertisement

Lisp problem...

Started by January 31, 2006 05:26 AM
3 comments, last by Bruno 18 years, 9 months ago
Hi, I hope someone can help me here, i'm getting really fustrated at this.., Anyways, i'm tryng to help my brother that his as frustrated as me at making a program that should manage a fast food restaurant at making deliveries. The program should take requests of people and place them in a list. So, what we do is we get the orders of people like this :

   (format t "Insert number of Pizzas: ")
   (setf num_pizzas (read T NIL NIL))
         (if (> num_pizzas 0)
          (setf conj-Opedidos (insert(create-Request "P" num_pizzas)conj-Opedidos ))) 

   (format t "~2%~5t ")
   (format t "Insert number of hamburgers: ")
   (setf num_frangos (read T NIL NIL))
      (if (> num_frangos 0)
          (setf conj-Opedidos (insert(create-Request "F" num_frangos)conj-Opedidos ))) 

   (format t "~2%~5t ")
   (format t "Insert number of desearts: ")
   (setf num_sobremesas(read T NIL NIL))
      (if (> num_sobremesas 0)
          (setf conj-Opedidos (insert(create-Request "S" num_sobremesas)conj-Opedidos ))) 

   (format t "~2%~5t ")
   (format t "Insert number of drinks: ")
   (setf num_bebidas (read T NIL NIL))
      (if (> num_drinks 0)
          (setf conj-Opedidos (insert(create-Request "B" num_drinks)conj-Opedidos ))) 

After inserting some values the conj-Opedidos looks like this : (("P" 6) ("F" 6) ("S" 6) ("B" 6)) All good, After this we ask to what area the delivery should be made :

  (format t "~2%~5t ")
   (format t "Code Area? (A, B ou C?) ")
   (setf area (read T NIL NIL))
     (if (or (string-equal area "A") (string-equal area "B") (string-equal area "C")) (return)))
And with this, we feed all the results to another list : (setf conj-encomendas (insert(create-Package conj-Opedidos area) conj-encomendas ))) In the end, conj-encomendas looks like this : (((("P" 8) ("F" 8) ("S" 8) ("B" 8)) B)) Once again, all good, we have the food orders and the area code all in one block. Now the problem is that, when running the code again, instead of adding another block to the list, like this : (((("P" 8) ("F" 8) ("S" 8) ("B" 8)) B))((("P" 4) ("F" 3) ("S" 2) ("B" 1)) A))) He gives this error : 1[4]: (Create-Package (("P" 6) ("F" 6) ("S" 6) ("B" 6)) A) 1[4]: returned ((("P" 6) ("F" 6) ("S" 6) ("B" 6)) A) Error: EXCL::STRING1 argument should be a string [condition type: PROGRAM-ERROR] 0[4]: returned-by-throwing :POP 0 My guess is that this setf is wrong, but i tried so many diferent things and i just can't get this working no matter what i do.., Any ideias on what could be wrong ? thank you very much... Auxiliary structures

The list conj-Opedidos is defined like this :

(defun create-Request (oTipo oQuantidade)
  (list oTipo oQuantidade))

(defun oTipo (opedido)
  (first opedido))

(defun oQuantidade (opedido)
  (second opedido))  
 
(setf conj-Opedidos nil)



The list conj-encomendas..



(defun Create-Package (ped_pratos zona)
      (list ped_pratos zona))

(defun ped_pratos (encomenda)
  (first encomenda))

(defun zona (encomenda)
  (second encomenda))






insert
------

(defun insert(n c)
  (if (null c)
      (list n)
    (if (string-equal (first n)(first (first c)))
        c
      (cons (first c)(insere n (rest c))))))

Set conj-Opedidos to NIL at the beginning of each order process. Then, at the end of the order it will always contain a single order string. Now, have a second variable, say, total-Order. After each order is complete simply insert the new conj-Opedidos into total-Order.
h20, member of WFG 0 A.D.
Advertisement
Thats what i do here :

And with this, we feed all the results to another list :

(setf conj-encomendas (insert(create-Package conj-Opedidos area) conj-encomendas )))

In the end, conj-encomendas looks like this :

(((("P" 8) ("F" 8) ("S" 8) ("B" 8)) B))

I place conj-Opedidos into conj-encomendas

Sorry, I just skimmed your code the first time. You definitely have the right idea, but you'll have to write a second insert function. Take a look at your current insert:

(defun insert(n c)  (if (null c)      (list n)    (if (string-equal (first n)(first (first c)))        c      (cons (first c)(insere n (rest c))))))


From your "string-equal" call, you expect the first element of 'n' to be a string! (And also the (first (first c)).) So, as I'm sure you've done a billion times in your Lisp class, you just need to make a second more generic insert function which perhaps just appends a new element to 'c' without checking for duplicate elements.
h20, member of WFG 0 A.D.
Thanks mate, the problem was exactly in the Insert function., i got it working :)
thanks again

This topic is closed to new replies.

Advertisement