fork download
  1. #|
  2. Author: [Your Name]
  3. E-mail: [Your PSU Email]@psu.edu
  4. Course: CMPSC 460
  5. Assignment: Lisp Programming Project
  6. Due date: 4/6/2026
  7. File: FoodOrderGenerator.LISP
  8. Purpose: This program uses random-number generation to create food orders
  9. from lists of different categories of food items. It also allows the
  10. user to add food items to or remove food items from the lists
  11. initially provided. The program loops until the user decides that
  12. s/he is done creating food orders.
  13. IDE/Compiler:
  14. LispWorks 8.0.1 Personal Edition
  15. Operating system:
  16. MS Windows 10
  17. References: Web sites listed on our course Programming Language Resources page
  18. Lisp interactive sessions and demo functions posted on our course
  19. Demo Programs page
  20. AI Tool(s): Claude (Anthropic) was used to generate this source code.
  21. AI-generated code specific to this assignment - all functions below.
  22. |#
  23.  
  24. ; -------------------------------------------------------------------
  25. ; Function to display the main menu of options
  26. (defun display-main-menu ()
  27. (format t "~%MENU OPTIONS:~%")
  28. (format t "1) Generate a food order~%")
  29. (format t "2) Add a food item~%")
  30. (format t "3) Remove a food item~%")
  31. (format t "4) Quit~%")
  32. )
  33.  
  34. ; -------------------------------------------------------------------
  35. ; Function to display the submenu of food item categories
  36. (defun display-sub-menu ()
  37. (format t "~%FOOD ITEM TYPES:~%")
  38. (format t "1) Sandwich~%")
  39. (format t "2) Side~%")
  40. (format t "3) Beverage~%")
  41. (format t "4) Dessert~%")
  42. )
  43.  
  44. ; -------------------------------------------------------------------
  45. ; Function to display all four food item lists
  46. (defun display-all-lists (sandwiches sides beverages desserts)
  47. (format t "~%Current food items lists:~%")
  48. (format t "Sandwiches: ~a~%" sandwiches)
  49. (format t "Sides : ~a~%" sides)
  50. (format t "Beverages : ~a~%" beverages)
  51. (format t "Desserts : ~a~%" desserts)
  52. )
  53.  
  54. ; -------------------------------------------------------------------
  55. ; Function to obtain a validated menu choice in range [1, 4]
  56. (defun get-menu-choice ()
  57. (format t "Please enter your choice: ")
  58. (finish-output)
  59. (let ((choice (read)))
  60. (if (and (integerp choice) (>= choice 1) (<= choice 4))
  61. choice
  62. (progn
  63. (format t "Invalid choice! Please re-enter.~%")
  64. (get-menu-choice)
  65. )
  66. )
  67. )
  68. )
  69.  
  70. ; -------------------------------------------------------------------
  71. ; Function to pick a random element from a list
  72. (defun random-element (lst)
  73. (nth (random (length lst)) lst)
  74. )
  75.  
  76. ; -------------------------------------------------------------------
  77. ; Function to generate a random food order from each list
  78. ; Selects one item at random from each list and builds the order
  79. (defun generate-food-order (sandwiches sides beverages desserts)
  80. (let* ((sandwich (random-element sandwiches))
  81. (side (random-element sides))
  82. (beverage (random-element beverages))
  83. (dessert (random-element desserts))
  84. (order (append (list sandwich) (list side) (list beverage) (list dessert))))
  85. (format t "~%Random food order:~%")
  86. (format t " ~a, ~a, ~a, ~a~%" sandwich side beverage dessert)
  87. order
  88. )
  89. )
  90.  
  91. ; -------------------------------------------------------------------
  92. ; Function to add a food item to a list if it is not already present
  93. ; Returns the (possibly updated) list
  94. (defun add-food-item (lst item)
  95. (if (member item lst)
  96. lst
  97. (append lst (list item))
  98. )
  99. )
  100.  
  101. ; -------------------------------------------------------------------
  102. ; Function to remove a food item from a list
  103. ; Does nothing (no error) if the list is empty or the item is not found
  104. ; Returns the (possibly updated) list
  105. (defun remove-food-item (lst item)
  106. (if (or (null lst) (not (member item lst)))
  107. lst
  108. (remove item lst)
  109. )
  110. )
  111.  
  112. ; -------------------------------------------------------------------
  113. ; Function to handle the "add a food item" workflow
  114. ; Displays lists, shows submenu, reads category and new item, returns updated lists
  115. (defun handle-add (sandwiches sides beverages desserts)
  116. (display-all-lists sandwiches sides beverages desserts)
  117. (display-sub-menu)
  118. (let ((cat (get-menu-choice)))
  119. (format t "Please enter your food item: ")
  120. (finish-output)
  121. (let ((new-item (read)))
  122. (cond
  123. ((= cat 1)
  124. (let ((updated (add-food-item sandwiches new-item)))
  125. (format t "Sandwiches: ~a~%" updated)
  126. (list updated sides beverages desserts)
  127. ))
  128. ((= cat 2)
  129. (let ((updated (add-food-item sides new-item)))
  130. (format t "Sides : ~a~%" updated)
  131. (list sandwiches updated beverages desserts)
  132. ))
  133. ((= cat 3)
  134. (let ((updated (add-food-item beverages new-item)))
  135. (format t "Beverages : ~a~%" updated)
  136. (list sandwiches sides updated desserts)
  137. ))
  138. ((= cat 4)
  139. (let ((updated (add-food-item desserts new-item)))
  140. (format t "Desserts : ~a~%" updated)
  141. (list sandwiches sides beverages updated)
  142. ))
  143. )
  144. )
  145. )
  146. )
  147.  
  148. ; -------------------------------------------------------------------
  149. ; Function to handle the "remove a food item" workflow
  150. ; Displays lists, shows submenu, reads category and item, returns updated lists
  151. (defun handle-remove (sandwiches sides beverages desserts)
  152. (display-all-lists sandwiches sides beverages desserts)
  153. (display-sub-menu)
  154. (let ((cat (get-menu-choice)))
  155. (format t "Please enter your food item: ")
  156. (finish-output)
  157. (let ((del-item (read)))
  158. (cond
  159. ((= cat 1)
  160. (let ((updated (remove-food-item sandwiches del-item)))
  161. (format t "Sandwiches: ~a~%" updated)
  162. (list updated sides beverages desserts)
  163. ))
  164. ((= cat 2)
  165. (let ((updated (remove-food-item sides del-item)))
  166. (format t "Sides : ~a~%" updated)
  167. (list sandwiches updated beverages desserts)
  168. ))
  169. ((= cat 3)
  170. (let ((updated (remove-food-item beverages del-item)))
  171. (format t "Beverages : ~a~%" updated)
  172. (list sandwiches sides updated desserts)
  173. ))
  174. ((= cat 4)
  175. (let ((updated (remove-food-item desserts del-item)))
  176. (format t "Desserts : ~a~%" updated)
  177. (list sandwiches sides beverages updated)
  178. ))
  179. )
  180. )
  181. )
  182. )
  183.  
  184. ; -------------------------------------------------------------------
  185. ; Helper function that performs one iteration of the main loop
  186. ; Returns NIL when the user chooses to quit, otherwise recurses with updated lists
  187. (defun main-loop (sandwiches sides beverages desserts)
  188. (display-main-menu)
  189. (let ((choice (get-menu-choice)))
  190. (cond
  191. ; Option 1: Generate a random food order
  192. ((= choice 1)
  193. (generate-food-order sandwiches sides beverages desserts)
  194. (main-loop sandwiches sides beverages desserts)
  195. )
  196. ; Option 2: Add a food item
  197. ((= choice 2)
  198. (let ((updated-lists (handle-add sandwiches sides beverages desserts)))
  199. (main-loop (first updated-lists)
  200. (second updated-lists)
  201. (third updated-lists)
  202. (fourth updated-lists))
  203. )
  204. )
  205. ; Option 3: Remove a food item
  206. ((= choice 3)
  207. (let ((updated-lists (handle-remove sandwiches sides beverages desserts)))
  208. (main-loop (first updated-lists)
  209. (second updated-lists)
  210. (third updated-lists)
  211. (fourth updated-lists))
  212. )
  213. )
  214. ; Option 4: Quit
  215. ((= choice 4)
  216. (format t "~%\"Thank you for using my Food Order Generator!\"~%")
  217. )
  218. )
  219. )
  220. )
  221.  
  222. ; -------------------------------------------------------------------
  223. ; Main "driver" function - initializes the four food lists and starts the loop
  224. (defun loop-program ()
  225. (let ((sandwiches '(blt tuna-salad grilled-cheese hamburger cheesesteak))
  226. (sides '(tossed-salad pasta-salad fries onion-rings chips))
  227. (beverages '(lemonade iced-tea water soda coffee))
  228. (desserts '(ice-cream cake pie brownie cookies)))
  229. (main-loop sandwiches sides beverages desserts)
  230. )
  231. )
Success #stdin #stdout #stderr 0.02s 9532KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Warning: reserving address range 0x80000c0000...0x1fffffffffff that contains memory mappings. clisp might crash later!
Memory dump:
  0x8000000000 - 0x80000bffff
  0x1498b9a00000 - 0x1498b9ce4fff
  0x1498b9e15000 - 0x1498b9e39fff
  0x1498b9e3a000 - 0x1498b9facfff
  0x1498b9fad000 - 0x1498b9ff5fff
  0x1498b9ff6000 - 0x1498b9ff8fff
  0x1498b9ff9000 - 0x1498b9ffbfff
  0x1498b9ffc000 - 0x1498b9ffffff
  0x1498ba000000 - 0x1498ba002fff
  0x1498ba003000 - 0x1498ba201fff
  0x1498ba202000 - 0x1498ba202fff
  0x1498ba203000 - 0x1498ba203fff
  0x1498ba280000 - 0x1498ba28ffff
  0x1498ba290000 - 0x1498ba2c3fff
  0x1498ba2c4000 - 0x1498ba3fafff
  0x1498ba3fb000 - 0x1498ba3fbfff
  0x1498ba3fc000 - 0x1498ba3fefff
  0x1498ba3ff000 - 0x1498ba3fffff
  0x1498ba400000 - 0x1498ba403fff
  0x1498ba404000 - 0x1498ba603fff
  0x1498ba604000 - 0x1498ba604fff
  0x1498ba605000 - 0x1498ba605fff
  0x1498ba654000 - 0x1498ba657fff
  0x1498ba658000 - 0x1498ba658fff
  0x1498ba659000 - 0x1498ba65afff
  0x1498ba65b000 - 0x1498ba65bfff
  0x1498ba65c000 - 0x1498ba65cfff
  0x1498ba65d000 - 0x1498ba65dfff
  0x1498ba65e000 - 0x1498ba66bfff
  0x1498ba66c000 - 0x1498ba679fff
  0x1498ba67a000 - 0x1498ba686fff
  0x1498ba687000 - 0x1498ba68afff
  0x1498ba68b000 - 0x1498ba68bfff
  0x1498ba68c000 - 0x1498ba68cfff
  0x1498ba68d000 - 0x1498ba692fff
  0x1498ba693000 - 0x1498ba694fff
  0x1498ba695000 - 0x1498ba695fff
  0x1498ba696000 - 0x1498ba696fff
  0x1498ba697000 - 0x1498ba697fff
  0x1498ba698000 - 0x1498ba6c5fff
  0x1498ba6c6000 - 0x1498ba6d4fff
  0x1498ba6d5000 - 0x1498ba77afff
  0x1498ba77b000 - 0x1498ba811fff
  0x1498ba812000 - 0x1498ba812fff
  0x1498ba813000 - 0x1498ba813fff
  0x1498ba814000 - 0x1498ba827fff
  0x1498ba828000 - 0x1498ba84ffff
  0x1498ba850000 - 0x1498ba859fff
  0x1498ba85a000 - 0x1498ba85bfff
  0x1498ba85c000 - 0x1498ba861fff
  0x1498ba862000 - 0x1498ba864fff
  0x1498ba867000 - 0x1498ba867fff
  0x1498ba868000 - 0x1498ba868fff
  0x1498ba869000 - 0x1498ba869fff
  0x1498ba86a000 - 0x1498ba86afff
  0x1498ba86b000 - 0x1498ba86bfff
  0x1498ba86c000 - 0x1498ba872fff
  0x1498ba873000 - 0x1498ba875fff
  0x1498ba876000 - 0x1498ba876fff
  0x1498ba877000 - 0x1498ba897fff
  0x1498ba898000 - 0x1498ba89ffff
  0x1498ba8a0000 - 0x1498ba8a0fff
  0x1498ba8a1000 - 0x1498ba8a1fff
  0x1498ba8a2000 - 0x1498ba8a2fff
  0x559ee6b20000 - 0x559ee6c10fff
  0x559ee6c11000 - 0x559ee6d1afff
  0x559ee6d1b000 - 0x559ee6d7afff
  0x559ee6d7c000 - 0x559ee6daafff
  0x559ee6dab000 - 0x559ee6ddbfff
  0x559ee6ddc000 - 0x559ee6ddffff
  0x559ee74f2000 - 0x559ee7512fff
  0x7ffe7a437000 - 0x7ffe7a457fff
  0x7ffe7a494000 - 0x7ffe7a497fff
  0x7ffe7a498000 - 0x7ffe7a499fff